diff --git a/pkg/modifycontroller/modify_status.go b/pkg/modifycontroller/modify_status.go index 6bc023e09..d9365373d 100644 --- a/pkg/modifycontroller/modify_status.go +++ b/pkg/modifycontroller/modify_status.go @@ -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) diff --git a/pkg/modifycontroller/modify_status_test.go b/pkg/modifycontroller/modify_status_test.go index e0850a9bc..b62e58c09 100644 --- a/pkg/modifycontroller/modify_status_test.go +++ b/pkg/modifycontroller/modify_status_test.go @@ -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 @@ -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, }, { diff --git a/pkg/modifycontroller/modify_volume_test.go b/pkg/modifycontroller/modify_volume_test.go index 5d90be5e1..5fd999223 100644 --- a/pkg/modifycontroller/modify_volume_test.go +++ b/pkg/modifycontroller/modify_volume_test.go @@ -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, },