Skip to content

Commit

Permalink
Merge pull request #423 from k8s-infra-cherrypick-robot/cherry-pick-4…
Browse files Browse the repository at this point in the history
…21-to-release-1.11

[release-1.11] clear modify status when the operation is completed
  • Loading branch information
k8s-ci-robot authored Jul 26, 2024
2 parents aa9ba24 + b05e578 commit e81db4a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
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

0 comments on commit e81db4a

Please sign in to comment.