EvenPodsSpread: api changes

This commit is contained in:
Wei Huang
2019-04-26 10:08:52 -07:00
parent 8d4c49faae
commit 49da505a9a
6 changed files with 333 additions and 1 deletions

View File

@@ -13663,7 +13663,6 @@ func testDataSourceInSpec(name string, kind string, apiGroup string) *core.Persi
}
func TestAlphaVolumePVCDataSource(t *testing.T) {
testCases := []struct {
testName string
claimSpec core.PersistentVolumeClaimSpec
@@ -13704,7 +13703,104 @@ func TestAlphaVolumePVCDataSource(t *testing.T) {
if errs := ValidatePersistentVolumeClaimSpec(&tc.claimSpec, field.NewPath("spec")); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
}
}
}
func TestValidateTopologySpreadConstraints(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.EvenPodsSpread, true)()
testCases := []struct {
name string
constraints []core.TopologySpreadConstraint
errtype field.ErrorType
errfield string
}{
{
name: "all required fields ok",
constraints: []core.TopologySpreadConstraint{
{MaxSkew: 1, TopologyKey: "k8s.io/zone", WhenUnsatisfiable: core.DoNotSchedule},
},
},
{
name: "missing MaxSkew",
constraints: []core.TopologySpreadConstraint{
{TopologyKey: "k8s.io/zone", WhenUnsatisfiable: core.DoNotSchedule},
},
errtype: field.ErrorTypeInvalid,
errfield: "maxSkew",
},
{
name: "invalid MaxSkew",
constraints: []core.TopologySpreadConstraint{
{MaxSkew: 0, TopologyKey: "k8s.io/zone", WhenUnsatisfiable: core.DoNotSchedule},
},
errtype: field.ErrorTypeInvalid,
errfield: "maxSkew",
},
{
name: "missing TopologyKey",
constraints: []core.TopologySpreadConstraint{
{MaxSkew: 1, WhenUnsatisfiable: core.DoNotSchedule},
},
errtype: field.ErrorTypeRequired,
errfield: "topologyKey",
},
{
name: "missing scheduling mode",
constraints: []core.TopologySpreadConstraint{
{MaxSkew: 1, TopologyKey: "k8s.io/zone"},
},
errtype: field.ErrorTypeNotSupported,
errfield: "whenUnsatisfiable",
},
{
name: "unsupported scheduling mode",
constraints: []core.TopologySpreadConstraint{
{MaxSkew: 1, TopologyKey: "k8s.io/zone", WhenUnsatisfiable: core.UnsatisfiableConstraintAction("N/A")},
},
errtype: field.ErrorTypeNotSupported,
errfield: "whenUnsatisfiable",
},
{
name: "multiple constraints ok with all required fields",
constraints: []core.TopologySpreadConstraint{
{MaxSkew: 1, TopologyKey: "k8s.io/zone", WhenUnsatisfiable: core.DoNotSchedule},
{MaxSkew: 2, TopologyKey: "k8s.io/node", WhenUnsatisfiable: core.ScheduleAnyway},
},
},
{
name: "multiple constraints missing TopologyKey on partial ones",
constraints: []core.TopologySpreadConstraint{
{MaxSkew: 1, TopologyKey: "k8s.io/zone", WhenUnsatisfiable: core.DoNotSchedule},
{MaxSkew: 2, WhenUnsatisfiable: core.ScheduleAnyway},
},
errtype: field.ErrorTypeRequired,
errfield: "topologyKey",
},
{
name: "duplicate constraints",
constraints: []core.TopologySpreadConstraint{
{MaxSkew: 1, TopologyKey: "k8s.io/zone", WhenUnsatisfiable: core.DoNotSchedule},
{MaxSkew: 2, TopologyKey: "k8s.io/zone", WhenUnsatisfiable: core.DoNotSchedule},
},
errtype: field.ErrorTypeDuplicate,
errfield: "{topologyKey, whenUnsatisfiable}",
},
}
for i, tc := range testCases {
errs := validateTopologySpreadConstraints(tc.constraints, field.NewPath("field"))
if len(errs) > 0 && tc.errtype == "" {
t.Errorf("[%d: %q] unexpected error(s): %v", i, tc.name, errs)
} else if len(errs) == 0 && tc.errtype != "" {
t.Errorf("[%d: %q] expected error type %v", i, tc.name, tc.errtype)
} else if len(errs) >= 1 {
if errs[0].Type != tc.errtype {
t.Errorf("[%d: %q] expected error type %v, got %v", i, tc.name, tc.errtype, errs[0].Type)
} else if !strings.HasSuffix(errs[0].Field, "."+tc.errfield) {
t.Errorf("[%d: %q] expected error on field %q, got %q", i, tc.name, tc.errfield, errs[0].Field)
}
}
}
}