Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#218 from rfranzke/hotfix-v2.1
Browse files Browse the repository at this point in the history
Attacher reacts for deleted PVs if finalizer is present
  • Loading branch information
k8s-ci-robot authored Mar 31, 2020
2 parents 8bb121c + c31dc8d commit 9a20c3f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
9 changes: 3 additions & 6 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import (
"fmt"
"time"

"k8s.io/klog"

v1 "k8s.io/api/core/v1"
storage "k8s.io/api/storage/v1beta1"
"k8s.io/apimachinery/pkg/api/equality"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
coreinformers "k8s.io/client-go/informers/core/v1"
storageinformers "k8s.io/client-go/informers/storage/v1beta1"
Expand All @@ -37,6 +36,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog"
)

// CSIAttachController is a controller that attaches / detaches CSI volumes using provided Handler interface
Expand Down Expand Up @@ -217,10 +217,7 @@ func (ctrl *CSIAttachController) syncVA() {
}

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

// syncPV deals with one key off the queue. It returns false when it's time to quit.
Expand Down
20 changes: 20 additions & 0 deletions pkg/controller/csi_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,26 @@ func TestCSIHandler(t *testing.T) {
pvDeleted(pv()))),
},
},
{
name: "VA deleted -> PV finalizer removed (GCE PD PV)",
initialObjects: []runtime.Object{pvDeleted(gcePDPVWithFinalizer())},
deletedVA: va(false, "", nil),
expectedActions: []core.Action{
core.NewPatchAction(pvGroupResourceVersion, metav1.NamespaceNone, testPVName,
types.MergePatchType, patch(pvDeleted(gcePDPVWithFinalizer()),
pvDeleted(gcePDPV()))),
},
},
{
name: "VA deleted -> PV finalizer not removed",
initialObjects: []runtime.Object{pvDeleted(pv())},
deletedVA: va(false, "", nil),
},
{
name: "VA deleted -> PV finalizer not removed (GCE PD PV)",
initialObjects: []runtime.Object{pvDeleted(gcePDPV())},
deletedVA: va(false, "", nil),
},
{
name: "PV updated -> PV finalizer removed",
initialObjects: []runtime.Object{},
Expand Down

0 comments on commit 9a20c3f

Please sign in to comment.