CSIDriver: allow "StorageCapacity" to be modified
When originally introduced, the field was made immutable to be consistent with the other fields. But in practice allowing it to be toggled makes more sense, in particular when considering the rollout of a CSI driver (let it run without using the published CSIStorageCapacity object, then flip the field, or upgrading from a driver without support to one which supports it). The only consumer of this field, the kube-scheduler, can handle mutation without problems because it always consults the informer cache to get the current value.
This commit is contained in:
@@ -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
|
||||
|
@@ -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) {
|
||||
@@ -2061,18 +2067,18 @@ func TestCSIDriverValidationUpdate(t *testing.T) {
|
||||
new.Spec.FSGroupPolicy = &fileFSGroupPolicy
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "StorageCapacity changed",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.StorageCapacity = ¬StorageCapacity
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "TokenRequests invalidated",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.TokenRequests = []storage.TokenRequest{{Audience: gcp}, {Audience: gcp}}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid nil StorageCapacity",
|
||||
modify: func(new *storage.CSIDriver) {
|
||||
new.Spec.StorageCapacity = nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range errorCases {
|
||||
|
Reference in New Issue
Block a user