Merge pull request #116089 from cvvz/fix-116028

fix: should not set default storageclass if annotation "volume.beta.kubernetes.io/storage-class" is set
This commit is contained in:
Kubernetes Prow Robot 2023-03-01 16:55:23 -08:00 committed by GitHub
commit 5157158d3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -937,7 +937,7 @@ func (ctrl *PersistentVolumeController) updateVolumePhaseWithEvent(volume *v1.Pe
// Ignores claims that already have a storage class. // Ignores claims that already have a storage class.
// TODO: if resync is ever changed to a larger period, we might need to change how we set the default class on existing unbound claims // TODO: if resync is ever changed to a larger period, we might need to change how we set the default class on existing unbound claims
func (ctrl *PersistentVolumeController) assignDefaultStorageClass(claim *v1.PersistentVolumeClaim) (bool, error) { func (ctrl *PersistentVolumeController) assignDefaultStorageClass(claim *v1.PersistentVolumeClaim) (bool, error) {
if claim.Spec.StorageClassName != nil { if storagehelpers.GetPersistentVolumeClaimClass(claim) != "" {
return false, nil return false, nil
} }

View File

@ -862,6 +862,24 @@ func TestRetroactiveStorageClassAssignment(t *testing.T) {
}, },
}, },
}, },
{
storageClasses: []*storagev1.StorageClass{
makeDefaultStorageClass(classGold, &modeImmediate),
makeStorageClass(classCopper, &modeImmediate),
},
tests: []controllerTest{
{
name: "15-7 - pvc storage class is not changed if claim is not bound but already set annotation \"volume.beta.kubernetes.io/storage-class\"",
initialVolumes: novolumes,
expectedVolumes: novolumes,
initialClaims: newClaimArray("claim15-7", "uid15-7", "1Gi", "", v1.ClaimPending, nil, v1.BetaStorageClassAnnotation),
expectedClaims: newClaimArray("claim15-7", "uid15-7", "1Gi", "", v1.ClaimPending, nil, v1.BetaStorageClassAnnotation),
expectedEvents: noevents,
errors: noerrors,
test: testSyncClaim,
},
},
},
} }
for _, test := range tests { for _, test := range tests {
runSyncTests(t, test.tests, test.storageClasses, nil) runSyncTests(t, test.tests, test.storageClasses, nil)