Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should not set default storageclass if annotation "volume.beta.kubernetes.io/storage-class" is set #116089

Merged
merged 2 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/controller/volume/persistentvolume/pv_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ func (ctrl *PersistentVolumeController) updateVolumePhaseWithEvent(volume *v1.Pe
// 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
func (ctrl *PersistentVolumeController) assignDefaultStorageClass(claim *v1.PersistentVolumeClaim) (bool, error) {
if claim.Spec.StorageClassName != nil {
if storagehelpers.GetPersistentVolumeClaimClass(claim) != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test for the fix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, added.

return false, nil
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/controller/volume/persistentvolume/pv_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
runSyncTests(t, test.tests, test.storageClasses, nil)
Expand Down