Skip to content

always overwrite TargetVolumeAttributesClassName when setting Status #510

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

Merged
merged 1 commit into from
Jul 29, 2025
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
9 changes: 5 additions & 4 deletions pkg/modifycontroller/modify_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package modifycontroller

import (
"fmt"

"github.com/kubernetes-csi/external-resizer/pkg/util"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/utils/ptr"
)

// markControllerModifyVolumeStatus will mark ModifyVolumeStatus other than completed in the PVC
Expand All @@ -31,10 +33,10 @@ func (ctrl *modifyController) markControllerModifyVolumeStatus(
err error) (*v1.PersistentVolumeClaim, error) {

newPVC := pvc.DeepCopy()
if newPVC.Status.ModifyVolumeStatus == nil {
newPVC.Status.ModifyVolumeStatus = &v1.ModifyVolumeStatus{}
newPVC.Status.ModifyVolumeStatus = &v1.ModifyVolumeStatus{
Status: modifyVolumeStatus,
TargetVolumeAttributesClassName: ptr.Deref(pvc.Spec.VolumeAttributesClassName, ""),
}
newPVC.Status.ModifyVolumeStatus.Status = modifyVolumeStatus
// Update PVC's Condition to indicate modification
pvcCondition := v1.PersistentVolumeClaimCondition{
Type: v1.PersistentVolumeClaimVolumeModifyingVolume,
Expand All @@ -45,7 +47,6 @@ func (ctrl *modifyController) markControllerModifyVolumeStatus(
switch modifyVolumeStatus {
case v1.PersistentVolumeClaimModifyVolumeInProgress:
conditionMessage = "ModifyVolume operation in progress."
newPVC.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName = *pvc.Spec.VolumeAttributesClassName
case v1.PersistentVolumeClaimModifyVolumeInfeasible:
conditionMessage = "ModifyVolume failed with error" + err.Error() + ". Waiting for retry."
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/modifycontroller/modify_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ func TestModify(t *testing.T) {
},
{
name: "vac does not exist, no modification and set ModifyVolumeStatus to pending",
pvc: createTestPVC(pvcName, targetVac /*vacName*/, testVac /*curVacName*/, testVac /*targetVacName*/),
pvc: createTestPVC(pvcName, targetVac /*vacName*/, testVac /*curVacName*/, "" /*targetVacName*/),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the base pvc needs to change targetVacName to empty string?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that is to just check if code is working as expected. If base PVC already had target set, then we won't be able to tell the difference.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then we should have a separate unit test case?

pv: basePV,
expectModifyCall: false,
expectedModifyVolumeStatus: &v1.ModifyVolumeStatus{
TargetVolumeAttributesClassName: testVac,
TargetVolumeAttributesClassName: targetVac,
Status: v1.PersistentVolumeClaimModifyVolumePending,
},
expectedCurrentVolumeAttributesClassName: &testVac,
Expand Down