Commit 4c43d626 authored by lichuqiang's avatar lichuqiang

related test update

parent b4a57f68
...@@ -39,8 +39,8 @@ func TestDropAlphaFields(t *testing.T) { ...@@ -39,8 +39,8 @@ func TestDropAlphaFields(t *testing.T) {
} }
// Test that field gets dropped when feature gate is not set // Test that field gets dropped when feature gate is not set
if err := utilfeature.DefaultFeatureGate.Set("VolumeScheduling=false,DynamicProvisioningScheduling=false"); err != nil { if err := utilfeature.DefaultFeatureGate.Set("VolumeScheduling=false"); err != nil {
t.Fatalf("Failed to set feature gate for VolumeScheduling or DynamicProvisioningScheduling: %v", err) t.Fatalf("Failed to set feature gate for VolumeScheduling: %v", err)
} }
class := &storage.StorageClass{ class := &storage.StorageClass{
VolumeBindingMode: &bindingMode, VolumeBindingMode: &bindingMode,
...@@ -59,8 +59,8 @@ func TestDropAlphaFields(t *testing.T) { ...@@ -59,8 +59,8 @@ func TestDropAlphaFields(t *testing.T) {
VolumeBindingMode: &bindingMode, VolumeBindingMode: &bindingMode,
AllowedTopologies: allowedTopologies, AllowedTopologies: allowedTopologies,
} }
if err := utilfeature.DefaultFeatureGate.Set("VolumeScheduling=true,DynamicProvisioningScheduling=true"); err != nil { if err := utilfeature.DefaultFeatureGate.Set("VolumeScheduling=true"); err != nil {
t.Fatalf("Failed to set feature gate for VolumeScheduling or DynamicProvisioningScheduling: %v", err) t.Fatalf("Failed to set feature gate for VolumeScheduling: %v", err)
} }
DropDisabledAlphaFields(class) DropDisabledAlphaFields(class)
if class.VolumeBindingMode != &bindingMode { if class.VolumeBindingMode != &bindingMode {
...@@ -70,7 +70,7 @@ func TestDropAlphaFields(t *testing.T) { ...@@ -70,7 +70,7 @@ func TestDropAlphaFields(t *testing.T) {
t.Errorf("AllowedTopologies field got unexpectantly modified: %+v", class.AllowedTopologies) t.Errorf("AllowedTopologies field got unexpectantly modified: %+v", class.AllowedTopologies)
} }
if err := utilfeature.DefaultFeatureGate.Set("VolumeScheduling=false,DynamicProvisioningScheduling=false"); err != nil { if err := utilfeature.DefaultFeatureGate.Set("VolumeScheduling=false"); err != nil {
t.Fatalf("Failed to disable feature gate for VolumeScheduling or DynamicProvisioningScheduling: %v", err) t.Fatalf("Failed to disable feature gate for VolumeScheduling: %v", err)
} }
} }
...@@ -827,73 +827,67 @@ func TestValidateAllowedTopologies(t *testing.T) { ...@@ -827,73 +827,67 @@ func TestValidateAllowedTopologies(t *testing.T) {
cases := map[string]bindingTest{ cases := map[string]bindingTest{
"no topology": { "no topology": {
class: makeClass(nil, nil), class: makeClass(&waitingMode, nil),
shouldSucceed: true, shouldSucceed: true,
}, },
"valid topology": { "valid topology": {
class: makeClass(nil, validTopology), class: makeClass(&waitingMode, validTopology),
shouldSucceed: true, shouldSucceed: true,
}, },
"topology invalid key": { "topology invalid key": {
class: makeClass(nil, topologyInvalidKey), class: makeClass(&waitingMode, topologyInvalidKey),
shouldSucceed: false, shouldSucceed: false,
}, },
"topology lack of values": { "topology lack of values": {
class: makeClass(nil, topologyLackOfValues), class: makeClass(&waitingMode, topologyLackOfValues),
shouldSucceed: false, shouldSucceed: false,
}, },
"duplicate TopologySelectorRequirement values": { "duplicate TopologySelectorRequirement values": {
class: makeClass(nil, topologyDupValues), class: makeClass(&waitingMode, topologyDupValues),
shouldSucceed: false, shouldSucceed: false,
}, },
"multiple TopologySelectorRequirement values": { "multiple TopologySelectorRequirement values": {
class: makeClass(nil, topologyMultiValues), class: makeClass(&waitingMode, topologyMultiValues),
shouldSucceed: true, shouldSucceed: true,
}, },
"empty MatchLabelExpressions": { "empty MatchLabelExpressions": {
class: makeClass(nil, topologyEmptyMatchLabelExpressions), class: makeClass(&waitingMode, topologyEmptyMatchLabelExpressions),
shouldSucceed: false, shouldSucceed: false,
}, },
"duplicate MatchLabelExpression keys": { "duplicate MatchLabelExpression keys": {
class: makeClass(nil, topologyDupKeys), class: makeClass(&waitingMode, topologyDupKeys),
shouldSucceed: false, shouldSucceed: false,
}, },
"duplicate MatchLabelExpression keys but across separate terms": { "duplicate MatchLabelExpression keys but across separate terms": {
class: makeClass(nil, topologyMultiTerm), class: makeClass(&waitingMode, topologyMultiTerm),
shouldSucceed: true, shouldSucceed: true,
}, },
"duplicate AllowedTopologies terms - identical": { "duplicate AllowedTopologies terms - identical": {
class: makeClass(nil, topologyDupTermsIdentical), class: makeClass(&waitingMode, topologyDupTermsIdentical),
shouldSucceed: false, shouldSucceed: false,
}, },
"two AllowedTopologies terms, with a pair of the same MatchLabelExpressions and a pair of different ones": { "two AllowedTopologies terms, with a pair of the same MatchLabelExpressions and a pair of different ones": {
class: makeClass(nil, topologyExprsOneSameOneDiff), class: makeClass(&waitingMode, topologyExprsOneSameOneDiff),
shouldSucceed: true, shouldSucceed: true,
}, },
"two AllowedTopologies terms, with a pair of the same Values and a pair of different ones": { "two AllowedTopologies terms, with a pair of the same Values and a pair of different ones": {
class: makeClass(nil, topologyValuesOneSameOneDiff), class: makeClass(&waitingMode, topologyValuesOneSameOneDiff),
shouldSucceed: true, shouldSucceed: true,
}, },
"duplicate AllowedTopologies terms - different MatchLabelExpressions order": { "duplicate AllowedTopologies terms - different MatchLabelExpressions order": {
class: makeClass(nil, topologyDupTermsDiffExprOrder), class: makeClass(&waitingMode, topologyDupTermsDiffExprOrder),
shouldSucceed: false, shouldSucceed: false,
}, },
"duplicate AllowedTopologies terms - different TopologySelectorRequirement values order": { "duplicate AllowedTopologies terms - different TopologySelectorRequirement values order": {
class: makeClass(nil, topologyDupTermsDiffValueOrder), class: makeClass(&waitingMode, topologyDupTermsDiffValueOrder),
shouldSucceed: false, shouldSucceed: false,
}, },
} }
// Disable VolumeScheduling so nil VolumeBindingMode doesn't fail to validate.
err := utilfeature.DefaultFeatureGate.Set("VolumeScheduling=false")
if err != nil {
t.Fatalf("Failed to disable feature gate for VolumeScheduling: %v", err)
}
// TODO: remove when feature gate not required // TODO: remove when feature gate not required
err = utilfeature.DefaultFeatureGate.Set("DynamicProvisioningScheduling=true") err := utilfeature.DefaultFeatureGate.Set("VolumeScheduling=true")
if err != nil { if err != nil {
t.Fatalf("Failed to enable feature gate for DynamicProvisioningScheduling: %v", err) t.Fatalf("Failed to enable feature gate for VolumeScheduling: %v", err)
} }
for testName, testCase := range cases { for testName, testCase := range cases {
...@@ -906,9 +900,9 @@ func TestValidateAllowedTopologies(t *testing.T) { ...@@ -906,9 +900,9 @@ func TestValidateAllowedTopologies(t *testing.T) {
} }
} }
err = utilfeature.DefaultFeatureGate.Set("DynamicProvisioningScheduling=false") err = utilfeature.DefaultFeatureGate.Set("VolumeScheduling=false")
if err != nil { if err != nil {
t.Fatalf("Failed to disable feature gate for DynamicProvisioningScheduling: %v", err) t.Fatalf("Failed to disable feature gate for VolumeScheduling: %v", err)
} }
for testName, testCase := range cases { for testName, testCase := range cases {
......
...@@ -237,12 +237,21 @@ func addVolumeAnnotation(volume *v1.PersistentVolume, annName, annValue string) ...@@ -237,12 +237,21 @@ func addVolumeAnnotation(volume *v1.PersistentVolume, annName, annValue string)
return volume return volume
} }
func makePVCClass(scName *string) *v1.PersistentVolumeClaim { func makePVCClass(scName *string, hasSelectNodeAnno bool) *v1.PersistentVolumeClaim {
return &v1.PersistentVolumeClaim{ claim := &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{},
},
Spec: v1.PersistentVolumeClaimSpec{ Spec: v1.PersistentVolumeClaimSpec{
StorageClassName: scName, StorageClassName: scName,
}, },
} }
if hasSelectNodeAnno {
claim.Annotations[annSelectedNode] = "node-name"
}
return claim
} }
func makeStorageClass(scName string, mode *storagev1.VolumeBindingMode) *storagev1.StorageClass { func makeStorageClass(scName string, mode *storagev1.VolumeBindingMode) *storagev1.StorageClass {
...@@ -271,26 +280,30 @@ func TestDelayBinding(t *testing.T) { ...@@ -271,26 +280,30 @@ func TestDelayBinding(t *testing.T) {
shouldFail bool shouldFail bool
}{ }{
"nil-class": { "nil-class": {
pvc: makePVCClass(nil), pvc: makePVCClass(nil, false),
shouldDelay: false, shouldDelay: false,
}, },
"class-not-found": { "class-not-found": {
pvc: makePVCClass(&classNotHere), pvc: makePVCClass(&classNotHere, false),
shouldDelay: false, shouldDelay: false,
}, },
"no-mode-class": { "no-mode-class": {
pvc: makePVCClass(&classNoMode), pvc: makePVCClass(&classNoMode, false),
shouldDelay: false, shouldDelay: false,
shouldFail: true, shouldFail: true,
}, },
"immediate-mode-class": { "immediate-mode-class": {
pvc: makePVCClass(&classImmediateMode), pvc: makePVCClass(&classImmediateMode, false),
shouldDelay: false, shouldDelay: false,
}, },
"wait-mode-class": { "wait-mode-class": {
pvc: makePVCClass(&classWaitMode), pvc: makePVCClass(&classWaitMode, false),
shouldDelay: true, shouldDelay: true,
}, },
"wait-mode-class-with-selectedNode": {
pvc: makePVCClass(&classWaitMode, true),
shouldDelay: false,
},
} }
classes := []*storagev1.StorageClass{ classes := []*storagev1.StorageClass{
...@@ -314,7 +327,7 @@ func TestDelayBinding(t *testing.T) { ...@@ -314,7 +327,7 @@ func TestDelayBinding(t *testing.T) {
// When volumeScheduling feature gate is disabled, should always be delayed // When volumeScheduling feature gate is disabled, should always be delayed
name := "volumeScheduling-feature-disabled" name := "volumeScheduling-feature-disabled"
shouldDelay, err := ctrl.shouldDelayBinding(makePVCClass(&classWaitMode)) shouldDelay, err := ctrl.shouldDelayBinding(makePVCClass(&classWaitMode, false))
if err != nil { if err != nil {
t.Errorf("Test %q returned error: %v", name, err) t.Errorf("Test %q returned error: %v", name, err)
} }
...@@ -338,43 +351,4 @@ func TestDelayBinding(t *testing.T) { ...@@ -338,43 +351,4 @@ func TestDelayBinding(t *testing.T) {
t.Errorf("Test %q returned unexpected %v", name, test.shouldDelay) t.Errorf("Test %q returned unexpected %v", name, test.shouldDelay)
} }
} }
// When dynamicProvisioningScheduling feature gate is disabled, should be delayed,
// even if the pvc has selectedNode annotation.
provisionedClaim := makePVCClass(&classWaitMode)
provisionedClaim.Annotations = map[string]string{annSelectedNode: "node-name"}
name = "dynamicProvisioningScheduling-feature-disabled"
shouldDelay, err = ctrl.shouldDelayBinding(provisionedClaim)
if err != nil {
t.Errorf("Test %q returned error: %v", name, err)
}
if !shouldDelay {
t.Errorf("Test %q returned false, expected true", name)
}
// Enable DynamicProvisioningScheduling feature gate
utilfeature.DefaultFeatureGate.Set("DynamicProvisioningScheduling=true")
defer utilfeature.DefaultFeatureGate.Set("DynamicProvisioningScheduling=false")
// When the pvc does not have selectedNode annotation, should be delayed,
// even if dynamicProvisioningScheduling feature gate is enabled.
name = "dynamicProvisioningScheduling-feature-enabled, selectedNode-annotation-not-set"
shouldDelay, err = ctrl.shouldDelayBinding(makePVCClass(&classWaitMode))
if err != nil {
t.Errorf("Test %q returned error: %v", name, err)
}
if !shouldDelay {
t.Errorf("Test %q returned false, expected true", name)
}
// Should not be delayed when dynamicProvisioningScheduling feature gate is enabled,
// and the pvc has selectedNode annotation.
name = "dynamicProvisioningScheduling-feature-enabled, selectedNode-annotation-set"
shouldDelay, err = ctrl.shouldDelayBinding(provisionedClaim)
if err != nil {
t.Errorf("Test %q returned error: %v", name, err)
}
if shouldDelay {
t.Errorf("Test %q returned true, expected false", name)
}
} }
...@@ -46,10 +46,10 @@ var ( ...@@ -46,10 +46,10 @@ var (
badPVC = makeBadPVC() badPVC = makeBadPVC()
immediateUnboundPVC = makeTestPVC("immediate-unbound-pvc", "1G", pvcUnbound, "", "1", &immediateClass) immediateUnboundPVC = makeTestPVC("immediate-unbound-pvc", "1G", pvcUnbound, "", "1", &immediateClass)
immediateBoundPVC = makeTestPVC("immediate-bound-pvc", "1G", pvcBound, "pv-bound-immediate", "1", &immediateClass) immediateBoundPVC = makeTestPVC("immediate-bound-pvc", "1G", pvcBound, "pv-bound-immediate", "1", &immediateClass)
provisionedPVC = makeTestPVC("provisioned-pvc", "1Gi", pvcUnbound, "", "1", &waitClass) provisionedPVC = makeTestPVC("provisioned-pvc", "1Gi", pvcUnbound, "", "1", &waitClassWithProvisioner)
provisionedPVC2 = makeTestPVC("provisioned-pvc2", "1Gi", pvcUnbound, "", "1", &waitClass) provisionedPVC2 = makeTestPVC("provisioned-pvc2", "1Gi", pvcUnbound, "", "1", &waitClassWithProvisioner)
provisionedPVCHigherVersion = makeTestPVC("provisioned-pvc2", "1Gi", pvcUnbound, "", "2", &waitClass) provisionedPVCHigherVersion = makeTestPVC("provisioned-pvc2", "1Gi", pvcUnbound, "", "2", &waitClassWithProvisioner)
noProvisionerPVC = makeTestPVC("no-provisioner-pvc", "1Gi", pvcUnbound, "", "1", &provisionNotSupportClass) noProvisionerPVC = makeTestPVC("no-provisioner-pvc", "1Gi", pvcUnbound, "", "1", &waitClass)
topoMismatchPVC = makeTestPVC("topo-mismatch-pvc", "1Gi", pvcUnbound, "", "1", &topoMismatchClass) topoMismatchPVC = makeTestPVC("topo-mismatch-pvc", "1Gi", pvcUnbound, "", "1", &topoMismatchClass)
pvNoNode = makeTestPV("pv-no-node", "", "1G", "1", nil, waitClass) pvNoNode = makeTestPV("pv-no-node", "", "1G", "1", nil, waitClass)
...@@ -74,7 +74,7 @@ var ( ...@@ -74,7 +74,7 @@ var (
waitClass = "waitClass" waitClass = "waitClass"
immediateClass = "immediateClass" immediateClass = "immediateClass"
provisionNotSupportClass = "provisionNotSupportedClass" waitClassWithProvisioner = "waitClassWithProvisioner"
topoMismatchClass = "topoMismatchClass" topoMismatchClass = "topoMismatchClass"
nodeLabelKey = "nodeKey" nodeLabelKey = "nodeKey"
...@@ -110,7 +110,7 @@ func newTestBinder(t *testing.T) *testEnv { ...@@ -110,7 +110,7 @@ func newTestBinder(t *testing.T) *testEnv {
classes := []*storagev1.StorageClass{ classes := []*storagev1.StorageClass{
{ {
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: waitClass, Name: waitClassWithProvisioner,
}, },
VolumeBindingMode: &waitMode, VolumeBindingMode: &waitMode,
Provisioner: "test-provisioner", Provisioner: "test-provisioner",
...@@ -133,7 +133,7 @@ func newTestBinder(t *testing.T) *testEnv { ...@@ -133,7 +133,7 @@ func newTestBinder(t *testing.T) *testEnv {
}, },
{ {
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: provisionNotSupportClass, Name: waitClass,
}, },
VolumeBindingMode: &waitMode, VolumeBindingMode: &waitMode,
Provisioner: "kubernetes.io/no-provisioner", Provisioner: "kubernetes.io/no-provisioner",
...@@ -776,9 +776,9 @@ func TestFindPodVolumesWithProvisioning(t *testing.T) { ...@@ -776,9 +776,9 @@ func TestFindPodVolumesWithProvisioning(t *testing.T) {
}, },
} }
// Set VolumeScheduling and DynamicProvisioningScheduling feature gate // Set VolumeScheduling feature gate
utilfeature.DefaultFeatureGate.Set("VolumeScheduling=true,DynamicProvisioningScheduling=true") utilfeature.DefaultFeatureGate.Set("VolumeScheduling=true")
defer utilfeature.DefaultFeatureGate.Set("VolumeScheduling=false,DynamicProvisioningScheduling=false") defer utilfeature.DefaultFeatureGate.Set("VolumeScheduling=false")
testNode := &v1.Node{ testNode := &v1.Node{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
......
...@@ -1116,6 +1116,16 @@ items: ...@@ -1116,6 +1116,16 @@ items:
- get - get
- list - list
- watch - watch
- apiGroups:
- ""
resources:
- persistentvolumeclaims
verbs:
- get
- list
- patch
- update
- watch
- aggregationRule: - aggregationRule:
clusterRoleSelectors: clusterRoleSelectors:
- matchLabels: - matchLabels:
......
...@@ -264,9 +264,8 @@ func TestVolumeBinding(t *testing.T) { ...@@ -264,9 +264,8 @@ func TestVolumeBinding(t *testing.T) {
// TestVolumeBindingRescheduling tests scheduler will retry scheduling when needed. // TestVolumeBindingRescheduling tests scheduler will retry scheduling when needed.
func TestVolumeBindingRescheduling(t *testing.T) { func TestVolumeBindingRescheduling(t *testing.T) {
features := map[string]bool{ features := map[string]bool{
"VolumeScheduling": true, "VolumeScheduling": true,
"PersistentLocalVolumes": true, "PersistentLocalVolumes": true,
"DynamicProvisioningScheduling": true,
} }
config := setupCluster(t, "volume-scheduling", 2, features, 0) config := setupCluster(t, "volume-scheduling", 2, features, 0)
defer config.teardown() defer config.teardown()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment