Modify VolumeZonePredicate to handle multi-zone PV
Modifies the VolumeZonePredicate to handle a PV that belongs to more then one zone or region. This is indicated by the zone or region label value containing a comma separated list.
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
// util.go uses api.Codecs.LegacyCodec so import this package to do some
|
||||
// resource initialization.
|
||||
_ "k8s.io/kubernetes/pkg/api/install"
|
||||
@@ -229,3 +230,36 @@ spec:
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestZonesToSet(t *testing.T) {
|
||||
functionUnderTest := "ZonesToSet"
|
||||
// First part: want an error
|
||||
sliceOfZones := []string{"", ",", "us-east-1a, , us-east-1d", ", us-west-1b", "us-west-2b,"}
|
||||
for _, zones := range sliceOfZones {
|
||||
if got, err := ZonesToSet(zones); err == nil {
|
||||
t.Errorf("%v(%v) returned (%v), want (%v)", functionUnderTest, zones, got, "an error")
|
||||
}
|
||||
}
|
||||
|
||||
// Second part: want no error
|
||||
tests := []struct {
|
||||
zones string
|
||||
want sets.String
|
||||
}{
|
||||
{
|
||||
zones: "us-east-1a",
|
||||
want: sets.String{"us-east-1a": sets.Empty{}},
|
||||
},
|
||||
{
|
||||
zones: "us-east-1a, us-west-2a",
|
||||
want: sets.String{
|
||||
"us-east-1a": sets.Empty{},
|
||||
"us-west-2a": sets.Empty{},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got, err := ZonesToSet(tt.zones); err != nil || !got.Equal(tt.want) {
|
||||
t.Errorf("%v(%v) returned (%v), want (%v)", functionUnderTest, tt.zones, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user