diff --git a/cmd/csi-attacher/main.go b/cmd/csi-attacher/main.go index 1a5c69c3e6..44c22e6f6b 100644 --- a/cmd/csi-attacher/main.go +++ b/cmd/csi-attacher/main.go @@ -154,12 +154,11 @@ func main() { } if supportsAttach { pvLister := factory.Core().V1().PersistentVolumes().Lister() - nodeLister := factory.Core().V1().Nodes().Lister() vaLister := factory.Storage().V1beta1().VolumeAttachments().Lister() csiNodeLister := factory.Storage().V1beta1().CSINodes().Lister() volAttacher := attacher.NewAttacher(csiConn) CSIVolumeLister := attacher.NewVolumeLister(csiConn) - handler = controller.NewCSIHandler(clientset, csiAttacher, volAttacher, CSIVolumeLister, pvLister, nodeLister, csiNodeLister, vaLister, timeout, supportsReadOnly, csitrans.New()) + handler = controller.NewCSIHandler(clientset, csiAttacher, volAttacher, CSIVolumeLister, pvLister, csiNodeLister, vaLister, timeout, supportsReadOnly, csitrans.New()) klog.V(2).Infof("CSI driver supports ControllerPublishUnpublish, using real CSI handler") } else { handler = controller.NewTrivialHandler(clientset) diff --git a/deploy/kubernetes/rbac.yaml b/deploy/kubernetes/rbac.yaml index f5d97a1173..93ce319629 100644 --- a/deploy/kubernetes/rbac.yaml +++ b/deploy/kubernetes/rbac.yaml @@ -16,7 +16,7 @@ metadata: namespace: default --- -# Attacher must be able to work with PVs, nodes and VolumeAttachments +# Attacher must be able to work with PVs, CSINodes and VolumeAttachments kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: @@ -25,9 +25,6 @@ rules: - apiGroups: [""] resources: ["persistentvolumes"] verbs: ["get", "list", "watch", "update", "patch"] - - apiGroups: [""] - resources: ["nodes"] - verbs: ["get", "list", "watch"] - apiGroups: ["storage.k8s.io"] resources: ["csinodes"] verbs: ["get", "list", "watch"] diff --git a/pkg/controller/csi_handler.go b/pkg/controller/csi_handler.go index 08ba1c2615..c6c3a259f2 100644 --- a/pkg/controller/csi_handler.go +++ b/pkg/controller/csi_handler.go @@ -62,7 +62,6 @@ type csiHandler struct { attacher attacher.Attacher CSIVolumeLister VolumeLister pvLister corelisters.PersistentVolumeLister - nodeLister corelisters.NodeLister csiNodeLister storagelisters.CSINodeLister vaLister storagelisters.VolumeAttachmentLister vaQueue, pvQueue workqueue.RateLimitingInterface @@ -82,7 +81,6 @@ func NewCSIHandler( attacher attacher.Attacher, CSIVolumeLister VolumeLister, pvLister corelisters.PersistentVolumeLister, - nodeLister corelisters.NodeLister, csiNodeLister storagelisters.CSINodeLister, vaLister storagelisters.VolumeAttachmentLister, timeout *time.Duration, @@ -95,7 +93,6 @@ func NewCSIHandler( attacher: attacher, CSIVolumeLister: CSIVolumeLister, pvLister: pvLister, - nodeLister: nodeLister, csiNodeLister: csiNodeLister, vaLister: vaLister, timeout: *timeout, @@ -682,7 +679,7 @@ func (h *csiHandler) getCredentialsFromPV(csiSource *v1.CSIPersistentVolumeSourc return credentials, nil } -// getNodeID finds node ID from Node API object. If caller wants, it can find +// getNodeID finds node ID from CSINode API object. If caller wants, it can find // node ID stored in VolumeAttachment annotation. func (h *csiHandler) getNodeID(driver string, nodeName string, va *storage.VolumeAttachment) (string, error) { // Try to find CSINode first. @@ -709,7 +706,7 @@ func (h *csiHandler) getNodeID(driver string, nodeName string, va *storage.Volum return nodeID, nil } - // return nodeLister.Get error + // return csiNodeLister.Get error return "", err } diff --git a/pkg/controller/csi_handler_test.go b/pkg/controller/csi_handler_test.go index 3e2c44cec1..d60f9262e8 100644 --- a/pkg/controller/csi_handler_test.go +++ b/pkg/controller/csi_handler_test.go @@ -57,7 +57,6 @@ func csiHandlerFactory(client kubernetes.Interface, informerFactory informers.Sh csi, lister, informerFactory.Core().V1().PersistentVolumes().Lister(), - informerFactory.Core().V1().Nodes().Lister(), informerFactory.Storage().V1beta1().CSINodes().Lister(), informerFactory.Storage().V1beta1().VolumeAttachments().Lister(), &timeout, @@ -73,7 +72,6 @@ func csiHandlerFactoryNoReadOnly(client kubernetes.Interface, informerFactory in csi, lister, informerFactory.Core().V1().PersistentVolumes().Lister(), - informerFactory.Core().V1().Nodes().Lister(), informerFactory.Storage().V1beta1().CSINodes().Lister(), informerFactory.Storage().V1beta1().VolumeAttachments().Lister(), &timeout, @@ -198,6 +196,14 @@ func node() *v1.Node { } } +func nodeWithAnnotations() *v1.Node { + node := node() + node.Annotations = map[string]string{ + "csi.volume.kubernetes.io/nodeid": fmt.Sprintf("{ %q: %q }", testAttacherName, testNodeID), + } + return node +} + func csiNode() *storage.CSINode { return &storage.CSINode{ ObjectMeta: metav1.ObjectMeta{ @@ -286,7 +292,7 @@ func TestCSIHandler(t *testing.T) { // { name: "VolumeAttachment added -> successful attachment", - initialObjects: []runtime.Object{pvWithFinalizer(), node(), csiNode()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: va(false /*attached*/, "" /*finalizer*/, nil /* annotations */), expectedActions: []core.Action{ // Finalizer is saved first @@ -303,7 +309,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with InlineVolumeSpec -> successful attachment", - initialObjects: []runtime.Object{node(), csiNode()}, + initialObjects: []runtime.Object{csiNode()}, addedVA: vaWithInlineSpec(va(false /*attached*/, "" /*finalizer*/, nil /* annotations */)), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -319,7 +325,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "readOnly VolumeAttachment added -> successful attachment", - initialObjects: []runtime.Object{pvReadOnly(pvWithFinalizer()), node(), csiNode()}, + initialObjects: []runtime.Object{pvReadOnly(pvWithFinalizer()), csiNode()}, addedVA: va(false /*attached*/, "" /*finalizer*/, nil /* annotations */), expectedActions: []core.Action{ // Finalizer is saved first @@ -336,7 +342,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "readOnly VolumeAttachment with InlineVolumeSpec -> successful attachment", - initialObjects: []runtime.Object{node(), csiNode()}, + initialObjects: []runtime.Object{csiNode()}, addedVA: vaInlineSpecReadOnly(vaWithInlineSpec(va(false /*attached*/, "" /*finalizer*/, nil /* annotations */))), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -352,7 +358,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment updated -> successful attachment", - initialObjects: []runtime.Object{pvWithFinalizer(), node(), csiNode()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, updatedVA: va(false, "", nil), expectedActions: []core.Action{ // Finalizer is saved first @@ -369,7 +375,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with InlineVolumeSpec updated -> successful attachment", - initialObjects: []runtime.Object{node(), csiNode()}, + initialObjects: []runtime.Object{csiNode()}, updatedVA: vaWithInlineSpec(va(false /*attached*/, "" /*finalizer*/, nil /* annotations */)), expectedActions: []core.Action{ // Finalizer is saved first @@ -386,7 +392,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with attributes -> successful attachment", - initialObjects: []runtime.Object{pvWithAttributes(pvWithFinalizer(), map[string]string{"foo": "bar"}), node(), csiNode()}, + initialObjects: []runtime.Object{pvWithAttributes(pvWithFinalizer(), map[string]string{"foo": "bar"}), csiNode()}, updatedVA: va(false, "", nil), expectedActions: []core.Action{ // Finalizer is saved first @@ -403,7 +409,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with InlineVolumeSpec and attributes -> successful attachment", - initialObjects: []runtime.Object{node(), csiNode()}, + initialObjects: []runtime.Object{csiNode()}, updatedVA: vaInlineSpecWithAttributes(vaWithInlineSpec(va(false, "", nil)) /*va*/, map[string]string{"foo": "bar"} /*attributes*/), expectedActions: []core.Action{ // Finalizer is saved first @@ -420,7 +426,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with secrets -> successful attachment", - initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "secret"), node(), secret(), csiNode()}, + initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "secret"), secret(), csiNode()}, updatedVA: va(false, "", nil), expectedActions: []core.Action{ core.NewGetAction(secretGroupResourceVersion, "default", "secret"), @@ -438,7 +444,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with InlineVolumeSpec and secrets -> successful attachment", - initialObjects: []runtime.Object{node(), secret(), csiNode()}, + initialObjects: []runtime.Object{secret(), csiNode()}, updatedVA: vaInlineSpecWithSecret(vaWithInlineSpec(va(false, "", nil)) /*va*/, "secret" /*secret*/), expectedActions: []core.Action{ core.NewGetAction(secretGroupResourceVersion, "default", "secret"), @@ -456,7 +462,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with empty secrets -> successful attachment", - initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "emptySecret"), node(), emptySecret(), csiNode()}, + initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "emptySecret"), emptySecret(), csiNode()}, updatedVA: va(false, "", nil), expectedActions: []core.Action{ core.NewGetAction(secretGroupResourceVersion, "default", "emptySecret"), @@ -474,7 +480,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with InlineVolumeSpec and empty secrets -> successful attachment", - initialObjects: []runtime.Object{node(), emptySecret(), csiNode()}, + initialObjects: []runtime.Object{emptySecret(), csiNode()}, updatedVA: vaInlineSpecWithSecret(vaWithInlineSpec(va(false, "", nil)) /*va*/, "emptySecret" /*secret*/), expectedActions: []core.Action{ core.NewGetAction(secretGroupResourceVersion, "default", "emptySecret"), @@ -492,7 +498,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with missing secrets -> error", - initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "unknownSecret"), node()}, + initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "unknownSecret"), csiNode()}, updatedVA: va(false, "", nil), expectedActions: []core.Action{ core.NewGetAction(secretGroupResourceVersion, "default", "unknownSecret"), @@ -504,7 +510,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment updated -> PV finalizer is added", - initialObjects: []runtime.Object{pv(), node(), csiNode()}, + initialObjects: []runtime.Object{pv(), csiNode()}, updatedVA: va(false, "", nil), expectedActions: []core.Action{ // PV Finalizer after VA @@ -525,7 +531,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "error saving PV finalizer -> controller retries", - initialObjects: []runtime.Object{pv(), node(), csiNode()}, + initialObjects: []runtime.Object{pv(), csiNode()}, updatedVA: va(false, "", nil), reactors: []reaction{ { @@ -577,14 +583,14 @@ func TestCSIHandler(t *testing.T) { }, { name: "already attached volume -> ignored", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, updatedVA: va(true, fin, ann), expectedActions: []core.Action{}, expectedCSICalls: []csiCall{}, }, { name: "PV with deletion timestamp -> ignored with error", - initialObjects: []runtime.Object{pvDeleted(pv()), node()}, + initialObjects: []runtime.Object{pvDeleted(pv()), csiNode()}, updatedVA: va(false, fin, ann), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -595,7 +601,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment added -> successful attachment incl. metadata", - initialObjects: []runtime.Object{pvWithFinalizer(), node(), csiNode()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: va(false, "", nil), expectedActions: []core.Action{ // Finalizer is saved first @@ -611,13 +617,13 @@ func TestCSIHandler(t *testing.T) { }, { name: "unknown driver -> ignored", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: vaWithInvalidDriver(va(false, fin, ann)), expectedActions: []core.Action{}, }, { name: "unknown PV -> error", - initialObjects: []runtime.Object{node()}, + initialObjects: []runtime.Object{csiNode()}, addedVA: va(false, fin, ann), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -627,7 +633,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "unknown PV -> error + error saving the error", - initialObjects: []runtime.Object{node()}, + initialObjects: []runtime.Object{csiNode()}, addedVA: va(false, fin, ann), reactors: []reaction{ { @@ -661,7 +667,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "neither PV nor InlineVolumeSpec reference-> error", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: vaWithNoPVReferenceNorInlineVolumeSpec(va(false, fin, ann)), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -671,7 +677,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "both PV and InlineVolumeSpec reference-> error", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: vaAddInlineSpec(va(false, fin, ann)), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -691,7 +697,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "failed write with VA finializers -> controller retries", - initialObjects: []runtime.Object{pvWithFinalizer(), node(), csiNode()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: va(false, "", nil), reactors: []reaction{ { @@ -735,7 +741,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "failed write with attached=true -> controller retries", - initialObjects: []runtime.Object{pvWithFinalizer(), node(), csiNode()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: va(false, "", nil), reactors: []reaction{ { @@ -779,7 +785,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "CSI attach fails -> controller retries", - initialObjects: []runtime.Object{pvWithFinalizer(), node(), csiNode()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: va(false, "", nil), expectedActions: []core.Action{ // Finalizer is saved first @@ -806,7 +812,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "CSI attach times out -> controller retries", - initialObjects: []runtime.Object{pvWithFinalizer(), node(), csiNode()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: va(false, "", nil), expectedActions: []core.Action{ // Finalizer is saved first @@ -832,9 +838,19 @@ func TestCSIHandler(t *testing.T) { vaWithAttachError(va(false, fin, ann), "csinode.storage.k8s.io \"node1\" not found"))), }, }, + { + name: "Node with annotations, CSINode is absent -> error", + initialObjects: []runtime.Object{pvWithFinalizer(), nodeWithAnnotations()}, + addedVA: va(false, fin, ann), + expectedActions: []core.Action{ + core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, + types.MergePatchType, patch(va(false /*attached*/, fin, ann), + vaWithAttachError(va(false, fin, ann), "csinode.storage.k8s.io \"node1\" not found"))), + }, + }, { name: "CSINode exists without the driver -> error", - initialObjects: []runtime.Object{pvWithFinalizer(), node(), csiNodeEmpty()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNodeEmpty()}, addedVA: va(false, fin, ann), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -844,7 +860,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "CSINode exists with the driver, Node without annotations -> success", - initialObjects: []runtime.Object{pvWithFinalizer(), node(), csiNode()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: va(false /*attached*/, "" /*finalizer*/, nil), expectedActions: []core.Action{ // Finalizer is saved first @@ -861,7 +877,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with GCEPersistentDiskVolumeSource -> successful attachment", - initialObjects: []runtime.Object{gcePDPVWithFinalizer(), node(), csiNode()}, + initialObjects: []runtime.Object{gcePDPVWithFinalizer(), csiNode()}, addedVA: va(false /*attached*/, "" /*finalizer*/, nil), expectedActions: []core.Action{ // Finalizer is saved first @@ -882,7 +898,7 @@ func TestCSIHandler(t *testing.T) { { name: "VolumeAttachment marked for deletion -> successful detach", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: deleted(va(true, fin, ann)), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -895,7 +911,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with InlineVolumeSpec marked for deletion -> successful detach", - initialObjects: []runtime.Object{node()}, + initialObjects: []runtime.Object{csiNode()}, addedVA: deleted(vaWithInlineSpec(va(true, fin, ann))), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -908,7 +924,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "volume with secrets -> successful detach", - initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "secret"), node(), secret()}, + initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "secret"), secret()}, addedVA: deleted(va(true, fin, ann)), expectedActions: []core.Action{ core.NewGetAction(secretGroupResourceVersion, "default", "secret"), @@ -922,7 +938,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "volume attachment with InlineVolumeSpec and secrets -> successful detach", - initialObjects: []runtime.Object{node(), secret()}, + initialObjects: []runtime.Object{secret()}, addedVA: deleted(vaInlineSpecWithSecret(vaWithInlineSpec(va(true, fin, ann)), "secret")), expectedActions: []core.Action{ core.NewGetAction(secretGroupResourceVersion, "default", "secret"), @@ -936,7 +952,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "volume with empty secrets -> successful detach", - initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "emptySecret"), node(), emptySecret()}, + initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "emptySecret"), emptySecret()}, addedVA: deleted(va(true, fin, ann)), expectedActions: []core.Action{ core.NewGetAction(secretGroupResourceVersion, "default", "emptySecret"), @@ -950,7 +966,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "volume attachment with InlineVolumeSpec and empty secrets -> successful detach", - initialObjects: []runtime.Object{node(), emptySecret()}, + initialObjects: []runtime.Object{emptySecret()}, addedVA: deleted(vaInlineSpecWithSecret(vaWithInlineSpec(va(true, fin, ann)), "emptySecret")), expectedActions: []core.Action{ core.NewGetAction(secretGroupResourceVersion, "default", "emptySecret"), @@ -964,7 +980,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "volume with missing secrets -> error", - initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "unknownSecret"), node()}, + initialObjects: []runtime.Object{pvWithSecret(pvWithFinalizer(), "unknownSecret"), csiNode()}, addedVA: deleted(va(true, fin, ann)), expectedActions: []core.Action{ core.NewGetAction(secretGroupResourceVersion, "default", "unknownSecret"), @@ -977,7 +993,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "CSI detach fails with an error -> controller retries", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: deleted(va(true, fin, ann)), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -994,7 +1010,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "CSI detach times out -> controller retries", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: deleted(va(true, fin, ann)), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -1008,14 +1024,14 @@ func TestCSIHandler(t *testing.T) { }, { name: "already detached volume -> ignored", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, updatedVA: deleted(va(false, "", nil)), expectedActions: []core.Action{}, expectedCSICalls: []csiCall{}, }, { name: "detach unknown PV -> error", - initialObjects: []runtime.Object{node()}, + initialObjects: []runtime.Object{csiNode()}, addedVA: deleted(va(true, fin, ann)), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -1025,7 +1041,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "detach unknown PV -> error + error saving the error", - initialObjects: []runtime.Object{node()}, + initialObjects: []runtime.Object{csiNode()}, addedVA: deleted(va(true, fin, ann)), reactors: []reaction{ { @@ -1059,7 +1075,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "detach VA with neither PV nor InlineCSIVolumeSource reference-> error", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: deleted(vaWithNoPVReferenceNorInlineVolumeSpec(va(true, fin, ann))), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -1070,7 +1086,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "detach VA with both PV and InlineCSIVolumeSource reference-> error", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: deleted(vaAddInlineSpec(va(true, fin, ann))), expectedActions: []core.Action{ core.NewPatchAction(vaGroupResourceVersion, metav1.NamespaceNone, testPVName+"-"+testNodeName, @@ -1105,7 +1121,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "failed write with attached=false -> controller retries", - initialObjects: []runtime.Object{pvWithFinalizer(), node()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: deleted(va(false, fin, ann)), reactors: []reaction{ { @@ -1148,7 +1164,7 @@ func TestCSIHandler(t *testing.T) { }, { name: "VolumeAttachment with GCEPersistentDiskVolumeSource marked for deletion -> successful detach", - initialObjects: []runtime.Object{gcePDPVWithFinalizer(), node()}, + initialObjects: []runtime.Object{gcePDPVWithFinalizer(), csiNode()}, addedVA: deleted(va(true /*attached*/, fin /*finalizer*/, ann)), expectedActions: []core.Action{ // Finalizer is saved first @@ -1332,7 +1348,7 @@ func TestCSIHandlerReadOnly(t *testing.T) { // { name: "read-write PV -> attached as read-write", - initialObjects: []runtime.Object{pvWithFinalizer(), node(), csiNode()}, + initialObjects: []runtime.Object{pvWithFinalizer(), csiNode()}, addedVA: va(false /*attached*/, "" /*finalizer*/, nil /* annotations */), expectedActions: []core.Action{ // Finalizer is saved first @@ -1349,7 +1365,7 @@ func TestCSIHandlerReadOnly(t *testing.T) { }, { name: "read-only PV -> attached as read-write", - initialObjects: []runtime.Object{pvReadOnly(pvWithFinalizer()), node(), csiNode()}, + initialObjects: []runtime.Object{pvReadOnly(pvWithFinalizer()), csiNode()}, addedVA: va(false /*attached*/, "" /*finalizer*/, nil /* annotations */), expectedActions: []core.Action{ // Finalizer is saved first