Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#195 from Madhu-1/process-csi-vol
Browse files Browse the repository at this point in the history
Avoid logging PV name,where PV created by other CSI
  • Loading branch information
k8s-ci-robot authored Dec 12, 2019
2 parents ad7d376 + 6900ef7 commit 2da20f5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,18 @@ func (ctrl *CSIAttachController) vaDeleted(obj interface{}) {
// pvAdded reacts to a PV creation
func (ctrl *CSIAttachController) pvAdded(obj interface{}) {
pv := obj.(*v1.PersistentVolume)
if !ctrl.processFinalizers(pv) {
return
}
ctrl.pvQueue.Add(pv.Name)
}

// pvUpdated reacts to a PV update
func (ctrl *CSIAttachController) pvUpdated(old, new interface{}) {
pv := new.(*v1.PersistentVolume)
if !ctrl.processFinalizers(pv) {
return
}
ctrl.pvQueue.Add(pv.Name)
}

Expand Down Expand Up @@ -193,6 +199,13 @@ func (ctrl *CSIAttachController) syncVA() {
ctrl.handler.SyncNewOrUpdatedVolumeAttachment(va)
}

func (ctrl *CSIAttachController) processFinalizers(pv *v1.PersistentVolume) bool {
if pv.Spec.CSI != nil && pv.Spec.CSI.Driver == ctrl.attacherName {
return true
}
return false
}

// syncPV deals with one key off the queue. It returns false when it's time to quit.
func (ctrl *CSIAttachController) syncPV() {
key, quit := ctrl.pvQueue.Get()
Expand Down
12 changes: 12 additions & 0 deletions pkg/controller/csi_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ func gcePDPVWithFinalizer() *v1.PersistentVolume {
return pv
}

func pvWithDriverName(driver string) *v1.PersistentVolume {
pv := pv()
pv.Spec.CSI.Driver = driver
return pv
}

func pvWithFinalizer() *v1.PersistentVolume {
pv := pv()
pv.Finalizers = []string{fin}
Expand Down Expand Up @@ -1259,6 +1265,12 @@ func TestCSIHandler(t *testing.T) {
deletedVA: va(false, "", nil),
expectedActions: []core.Action{},
},
{
name: "PV created by other CSI drivers or in-tree provisioners -> ignored",
initialObjects: []runtime.Object{},
updatedPV: pvWithDriverName("dummy"),
expectedActions: []core.Action{},
},
}

runTests(t, csiHandlerFactory, tests)
Expand Down

0 comments on commit 2da20f5

Please sign in to comment.