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

clear modify status when the operation is completed #421

Merged
merged 1 commit into from
Jul 26, 2024
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
15 changes: 7 additions & 8 deletions pkg/modifycontroller/modify_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,23 @@ func (ctrl *modifyController) updateConditionBasedOnError(pvc *v1.PersistentVolu
// markControllerModifyVolumeStatus will mark ModifyVolumeStatus as completed in the PVC
// and update CurrentVolumeAttributesClassName, clear the conditions
func (ctrl *modifyController) markControllerModifyVolumeCompleted(pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) (*v1.PersistentVolumeClaim, *v1.PersistentVolume, error) {
modifiedVacName := pvc.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName

// Update PVC
newPVC := pvc.DeepCopy()

// Update ModifyVolumeStatus to completed
var controllerModifyVolumeCompleted v1.PersistentVolumeClaimModifyVolumeStatus
if newPVC.Status.ModifyVolumeStatus == nil {
newPVC.Status.ModifyVolumeStatus = &v1.ModifyVolumeStatus{}
}
newPVC.Status.ModifyVolumeStatus.Status = controllerModifyVolumeCompleted
newPVC.Status.ModifyVolumeStatus = nil

// Update CurrentVolumeAttributesClassName
newPVC.Status.CurrentVolumeAttributesClassName = &newPVC.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName
newPVC.Status.CurrentVolumeAttributesClassName = &modifiedVacName

// Clear all the conditions
// Clear all the conditions related to modify volume
newPVC.Status.Conditions = clearModifyVolumeConditions(newPVC.Status.Conditions)

// Update PV
newPV := pv.DeepCopy()
newPV.Spec.VolumeAttributesClassName = &newPVC.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName
newPV.Spec.VolumeAttributesClassName = &modifiedVacName

// Update PV before PVC to avoid PV not getting updated but PVC did
updatedPV, err := util.PatchPersistentVolume(ctrl.kubeClient, pv, newPV)
Expand Down
3 changes: 2 additions & 1 deletion pkg/modifycontroller/modify_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func TestMarkControllerModifyVolumeCompleted(t *testing.T) {
expectedPV := basePV.DeepCopy()
expectedPV.Spec.VolumeAttributesClassName = &targetVac
expectedPVC := basePVC.WithCurrentVolumeAttributesClassName(targetVac).Get()
expectedPVC.Status.ModifyVolumeStatus = nil

tests := []struct {
name string
Expand All @@ -214,7 +215,7 @@ func TestMarkControllerModifyVolumeCompleted(t *testing.T) {
name: "update modify volume status to completed",
pvc: basePVC.Get(),
pv: basePV,
expectedPVC: basePVC.WithCurrentVolumeAttributesClassName(targetVac).Get(),
expectedPVC: expectedPVC,
expectedPV: expectedPV,
},
{
Expand Down
15 changes: 6 additions & 9 deletions pkg/modifycontroller/modify_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,12 @@ func TestModify(t *testing.T) {
expectedPVVolumeAttributesClassName: &testVac,
},
{
name: "modify volume success",
pvc: createTestPVC(pvcName, targetVac /*vacName*/, testVac /*curVacName*/, testVac /*targetVacName*/),
pv: basePV,
vacExists: true,
expectModifyCall: true,
expectedModifyVolumeStatus: &v1.ModifyVolumeStatus{
TargetVolumeAttributesClassName: targetVac,
Status: "",
},
name: "modify volume success",
pvc: createTestPVC(pvcName, targetVac /*vacName*/, testVac /*curVacName*/, testVac /*targetVacName*/),
pv: basePV,
vacExists: true,
expectModifyCall: true,
expectedModifyVolumeStatus: nil,
expectedCurrentVolumeAttributesClassName: &targetVac,
expectedPVVolumeAttributesClassName: &targetVac,
},
Expand Down