admit upgrading storage class of pvc from beta annotation to spec field
This commit is contained in:
@@ -736,6 +736,29 @@ func testVolumeClaimAnnotation(name string, namespace string, ann string, annval
|
||||
}
|
||||
}
|
||||
|
||||
func testVolumeClaimStorageClassInSpec(name, namespace, scName string, spec core.PersistentVolumeClaimSpec) *core.PersistentVolumeClaim {
|
||||
spec.StorageClassName = &scName
|
||||
return &core.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
},
|
||||
Spec: spec,
|
||||
}
|
||||
}
|
||||
|
||||
func testVolumeClaimStorageClassInAnnotationAndSpec(name, namespace, scNameInAnn, scName string, spec core.PersistentVolumeClaimSpec) *core.PersistentVolumeClaim {
|
||||
spec.StorageClassName = &scName
|
||||
return &core.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
Annotations: map[string]string{v1.BetaStorageClassAnnotation: scNameInAnn},
|
||||
},
|
||||
Spec: spec,
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatePersistentVolumeClaim(t *testing.T) {
|
||||
invalidClassName := "-invalid-"
|
||||
validClassName := "valid"
|
||||
@@ -1251,6 +1274,52 @@ func TestValidatePersistentVolumeClaimUpdate(t *testing.T) {
|
||||
Phase: core.ClaimPending,
|
||||
})
|
||||
|
||||
validClaimStorageClassInSpec := testVolumeClaimStorageClassInSpec("foo", "ns", "fast", core.PersistentVolumeClaimSpec{
|
||||
AccessModes: []core.PersistentVolumeAccessMode{
|
||||
core.ReadOnlyMany,
|
||||
},
|
||||
Resources: core.ResourceRequirements{
|
||||
Requests: core.ResourceList{
|
||||
core.ResourceName(core.ResourceStorage): resource.MustParse("10G"),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
invalidClaimStorageClassInSpec := testVolumeClaimStorageClassInSpec("foo", "ns", "fast2", core.PersistentVolumeClaimSpec{
|
||||
AccessModes: []core.PersistentVolumeAccessMode{
|
||||
core.ReadOnlyMany,
|
||||
},
|
||||
Resources: core.ResourceRequirements{
|
||||
Requests: core.ResourceList{
|
||||
core.ResourceName(core.ResourceStorage): resource.MustParse("10G"),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
validClaimStorageClassInAnnotationAndSpec := testVolumeClaimStorageClassInAnnotationAndSpec(
|
||||
"foo", "ns", "fast", "fast", core.PersistentVolumeClaimSpec{
|
||||
AccessModes: []core.PersistentVolumeAccessMode{
|
||||
core.ReadOnlyMany,
|
||||
},
|
||||
Resources: core.ResourceRequirements{
|
||||
Requests: core.ResourceList{
|
||||
core.ResourceName(core.ResourceStorage): resource.MustParse("10G"),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
invalidClaimStorageClassInAnnotationAndSpec := testVolumeClaimStorageClassInAnnotationAndSpec(
|
||||
"foo", "ns", "fast2", "fast", core.PersistentVolumeClaimSpec{
|
||||
AccessModes: []core.PersistentVolumeAccessMode{
|
||||
core.ReadOnlyMany,
|
||||
},
|
||||
Resources: core.ResourceRequirements{
|
||||
Requests: core.ResourceList{
|
||||
core.ResourceName(core.ResourceStorage): resource.MustParse("10G"),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
scenarios := map[string]struct {
|
||||
isExpectedFailure bool
|
||||
oldClaim *core.PersistentVolumeClaim
|
||||
@@ -1412,6 +1481,48 @@ func TestValidatePersistentVolumeClaimUpdate(t *testing.T) {
|
||||
enableResize: true,
|
||||
enableBlock: false,
|
||||
},
|
||||
"valid-upgrade-storage-class-annotation-to-spec": {
|
||||
isExpectedFailure: false,
|
||||
oldClaim: validClaimStorageClass,
|
||||
newClaim: validClaimStorageClassInSpec,
|
||||
enableResize: false,
|
||||
enableBlock: false,
|
||||
},
|
||||
"invalid-upgrade-storage-class-annotation-to-spec": {
|
||||
isExpectedFailure: true,
|
||||
oldClaim: validClaimStorageClass,
|
||||
newClaim: invalidClaimStorageClassInSpec,
|
||||
enableResize: false,
|
||||
enableBlock: false,
|
||||
},
|
||||
"valid-upgrade-storage-class-annotation-to-annotation-and-spec": {
|
||||
isExpectedFailure: false,
|
||||
oldClaim: validClaimStorageClass,
|
||||
newClaim: validClaimStorageClassInAnnotationAndSpec,
|
||||
enableResize: false,
|
||||
enableBlock: false,
|
||||
},
|
||||
"invalid-upgrade-storage-class-annotation-to-annotation-and-spec": {
|
||||
isExpectedFailure: true,
|
||||
oldClaim: validClaimStorageClass,
|
||||
newClaim: invalidClaimStorageClassInAnnotationAndSpec,
|
||||
enableResize: false,
|
||||
enableBlock: false,
|
||||
},
|
||||
"invalid-upgrade-storage-class-in-spec": {
|
||||
isExpectedFailure: true,
|
||||
oldClaim: validClaimStorageClassInSpec,
|
||||
newClaim: invalidClaimStorageClassInSpec,
|
||||
enableResize: false,
|
||||
enableBlock: false,
|
||||
},
|
||||
"invalid-downgrade-storage-class-spec-to-annotation": {
|
||||
isExpectedFailure: true,
|
||||
oldClaim: validClaimStorageClassInSpec,
|
||||
newClaim: validClaimStorageClass,
|
||||
enableResize: false,
|
||||
enableBlock: false,
|
||||
},
|
||||
}
|
||||
|
||||
for name, scenario := range scenarios {
|
||||
|
Reference in New Issue
Block a user