Skip to content

Commit 0f70a09

Browse files
authored
Merge branch 'kubernetes-csi:master' into resizerExtraMetadataFeature
2 parents 07dfe61 + 29a4667 commit 0f70a09

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

pkg/modifycontroller/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ func (ctrl *modifyController) syncPVC(key string) error {
280280
// Only trigger modify volume if the following conditions are met
281281
// 1. Non empty vac name
282282
// 2. PVC is in Bound state
283+
// 3. PV CSI driver name matches local driver
283284
vacName := pvc.Spec.VolumeAttributesClassName
284-
if vacName != nil && *vacName != "" && pvc.Status.Phase == v1.ClaimBound {
285+
if vacName != nil && *vacName != "" && pvc.Status.Phase == v1.ClaimBound && pv.Spec.CSI.Driver == ctrl.name {
285286
_, _, err, _ := ctrl.modify(pvc, pv)
286287
if err != nil {
287288
return err

pkg/modifycontroller/modify_status.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,23 @@ func (ctrl *modifyController) updateConditionBasedOnError(pvc *v1.PersistentVolu
9494
// markControllerModifyVolumeStatus will mark ModifyVolumeStatus as completed in the PVC
9595
// and update CurrentVolumeAttributesClassName, clear the conditions
9696
func (ctrl *modifyController) markControllerModifyVolumeCompleted(pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) (*v1.PersistentVolumeClaim, *v1.PersistentVolume, error) {
97+
modifiedVacName := pvc.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName
98+
9799
// Update PVC
98100
newPVC := pvc.DeepCopy()
101+
99102
// Update ModifyVolumeStatus to completed
100-
var controllerModifyVolumeCompleted v1.PersistentVolumeClaimModifyVolumeStatus
101-
if newPVC.Status.ModifyVolumeStatus == nil {
102-
newPVC.Status.ModifyVolumeStatus = &v1.ModifyVolumeStatus{}
103-
}
104-
newPVC.Status.ModifyVolumeStatus.Status = controllerModifyVolumeCompleted
103+
newPVC.Status.ModifyVolumeStatus = nil
105104

106105
// Update CurrentVolumeAttributesClassName
107-
newPVC.Status.CurrentVolumeAttributesClassName = &newPVC.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName
106+
newPVC.Status.CurrentVolumeAttributesClassName = &modifiedVacName
108107

109-
// Clear all the conditions
108+
// Clear all the conditions related to modify volume
110109
newPVC.Status.Conditions = clearModifyVolumeConditions(newPVC.Status.Conditions)
111110

112111
// Update PV
113112
newPV := pv.DeepCopy()
114-
newPV.Spec.VolumeAttributesClassName = &newPVC.Status.ModifyVolumeStatus.TargetVolumeAttributesClassName
113+
newPV.Spec.VolumeAttributesClassName = &modifiedVacName
115114

116115
// Update PV before PVC to avoid PV not getting updated but PVC did
117116
updatedPV, err := util.PatchPersistentVolume(ctrl.kubeClient, pv, newPV)

pkg/modifycontroller/modify_status_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func TestMarkControllerModifyVolumeCompleted(t *testing.T) {
201201
expectedPV := basePV.DeepCopy()
202202
expectedPV.Spec.VolumeAttributesClassName = &targetVac
203203
expectedPVC := basePVC.WithCurrentVolumeAttributesClassName(targetVac).Get()
204+
expectedPVC.Status.ModifyVolumeStatus = nil
204205

205206
tests := []struct {
206207
name string
@@ -214,7 +215,7 @@ func TestMarkControllerModifyVolumeCompleted(t *testing.T) {
214215
name: "update modify volume status to completed",
215216
pvc: basePVC.Get(),
216217
pv: basePV,
217-
expectedPVC: basePVC.WithCurrentVolumeAttributesClassName(targetVac).Get(),
218+
expectedPVC: expectedPVC,
218219
expectedPV: expectedPV,
219220
},
220221
{

pkg/modifycontroller/modify_volume_test.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,12 @@ func TestModify(t *testing.T) {
7979
expectedPVVolumeAttributesClassName: &testVac,
8080
},
8181
{
82-
name: "modify volume success",
83-
pvc: createTestPVC(pvcName, targetVac /*vacName*/, testVac /*curVacName*/, testVac /*targetVacName*/),
84-
pv: basePV,
85-
vacExists: true,
86-
expectModifyCall: true,
87-
expectedModifyVolumeStatus: &v1.ModifyVolumeStatus{
88-
TargetVolumeAttributesClassName: targetVac,
89-
Status: "",
90-
},
82+
name: "modify volume success",
83+
pvc: createTestPVC(pvcName, targetVac /*vacName*/, testVac /*curVacName*/, testVac /*targetVacName*/),
84+
pv: basePV,
85+
vacExists: true,
86+
expectModifyCall: true,
87+
expectedModifyVolumeStatus: nil,
9188
expectedCurrentVolumeAttributesClassName: &targetVac,
9289
expectedPVVolumeAttributesClassName: &targetVac,
9390
},

0 commit comments

Comments
 (0)