diff --git a/pkg/apis/storage/types.go b/pkg/apis/storage/types.go index 045df66c85b7d..db88831902d89 100644 --- a/pkg/apis/storage/types.go +++ b/pkg/apis/storage/types.go @@ -357,7 +357,7 @@ type CSIDriverSpec struct { // unset or false and it can be flipped later when storage // capacity information has been published. // - // This field is immutable. + // This field was immutable in Kubernetes <= 1.22 and now is mutable. // // This is a beta field and only available when the CSIStorageCapacity // feature is enabled. The default is false. diff --git a/pkg/apis/storage/validation/validation.go b/pkg/apis/storage/validation/validation.go index 7c6ec5daac68a..9cd48cd71764a 100644 --- a/pkg/apis/storage/validation/validation.go +++ b/pkg/apis/storage/validation/validation.go @@ -420,13 +420,13 @@ func ValidateCSIDriver(csiDriver *storage.CSIDriver) field.ErrorList { // ValidateCSIDriverUpdate validates a CSIDriver. func ValidateCSIDriverUpdate(new, old *storage.CSIDriver) field.ErrorList { allErrs := apivalidation.ValidateObjectMetaUpdate(&new.ObjectMeta, &old.ObjectMeta, field.NewPath("metadata")) + allErrs = append(allErrs, validateCSIDriverSpec(&new.Spec, field.NewPath("spec"))...) // immutable fields should not be mutated. allErrs = append(allErrs, apimachineryvalidation.ValidateImmutableField(new.Spec.AttachRequired, old.Spec.AttachRequired, field.NewPath("spec", "attachedRequired"))...) allErrs = append(allErrs, apimachineryvalidation.ValidateImmutableField(new.Spec.FSGroupPolicy, old.Spec.FSGroupPolicy, field.NewPath("spec", "fsGroupPolicy"))...) allErrs = append(allErrs, apimachineryvalidation.ValidateImmutableField(new.Spec.PodInfoOnMount, old.Spec.PodInfoOnMount, field.NewPath("spec", "podInfoOnMount"))...) allErrs = append(allErrs, apimachineryvalidation.ValidateImmutableField(new.Spec.VolumeLifecycleModes, old.Spec.VolumeLifecycleModes, field.NewPath("spec", "volumeLifecycleModes"))...) - allErrs = append(allErrs, apimachineryvalidation.ValidateImmutableField(new.Spec.StorageCapacity, old.Spec.StorageCapacity, field.NewPath("spec", "storageCapacity"))...) allErrs = append(allErrs, validateTokenRequests(new.Spec.TokenRequests, field.NewPath("spec", "tokenRequests"))...) return allErrs diff --git a/pkg/apis/storage/validation/validation_test.go b/pkg/apis/storage/validation/validation_test.go index ccc7fe7665105..7b483d48cae1a 100644 --- a/pkg/apis/storage/validation/validation_test.go +++ b/pkg/apis/storage/validation/validation_test.go @@ -1965,6 +1965,12 @@ func TestCSIDriverValidationUpdate(t *testing.T) { new.Spec.RequiresRepublish = &requiresRepublish }, }, + { + name: "StorageCapacity changed", + modify: func(new *storage.CSIDriver) { + new.Spec.StorageCapacity = ¬StorageCapacity + }, + }, } for _, test := range successCases { t.Run(test.name, func(t *testing.T) { @@ -2062,15 +2068,15 @@ func TestCSIDriverValidationUpdate(t *testing.T) { }, }, { - name: "StorageCapacity changed", + name: "TokenRequests invalidated", modify: func(new *storage.CSIDriver) { - new.Spec.StorageCapacity = ¬StorageCapacity + new.Spec.TokenRequests = []storage.TokenRequest{{Audience: gcp}, {Audience: gcp}} }, }, { - name: "TokenRequests invalidated", + name: "invalid nil StorageCapacity", modify: func(new *storage.CSIDriver) { - new.Spec.TokenRequests = []storage.TokenRequest{{Audience: gcp}, {Audience: gcp}} + new.Spec.StorageCapacity = nil }, }, } diff --git a/staging/src/k8s.io/api/storage/v1/types.go b/staging/src/k8s.io/api/storage/v1/types.go index d805e1539b041..f69b40b9ffe02 100644 --- a/staging/src/k8s.io/api/storage/v1/types.go +++ b/staging/src/k8s.io/api/storage/v1/types.go @@ -341,7 +341,7 @@ type CSIDriverSpec struct { // unset or false and it can be flipped later when storage // capacity information has been published. // - // This field is immutable. + // This field was immutable in Kubernetes <= 1.22 and now is mutable. // // This is a beta field and only available when the CSIStorageCapacity // feature is enabled. The default is false. diff --git a/staging/src/k8s.io/api/storage/v1beta1/types.go b/staging/src/k8s.io/api/storage/v1beta1/types.go index 9fe5646adc31e..3b74ce5eeac4a 100644 --- a/staging/src/k8s.io/api/storage/v1beta1/types.go +++ b/staging/src/k8s.io/api/storage/v1beta1/types.go @@ -362,7 +362,7 @@ type CSIDriverSpec struct { // unset or false and it can be flipped later when storage // capacity information has been published. // - // This field is immutable. + // This field was immutable in Kubernetes <= 1.22 and now is mutable. // // This is a beta field and only available when the CSIStorageCapacity // feature is enabled. The default is false.