From ab6a2530fb158146f53703146fc347ceceb2b202 Mon Sep 17 00:00:00 2001 From: Michelle Au Date: Wed, 27 Mar 2019 17:28:21 -0700 Subject: [PATCH] return empty devicepath for csi attach --- pkg/volume/csi/csi_attacher.go | 6 +++--- pkg/volume/csi/csi_attacher_test.go | 21 +++++++++------------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index d4b84b4e659..8590fb5074b 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -29,7 +29,7 @@ import ( "k8s.io/klog" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" storage "k8s.io/api/storage/v1" apierrs "k8s.io/apimachinery/pkg/api/errors" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -108,8 +108,8 @@ func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string klog.V(4).Info(log("attacher.Attach finished OK with VolumeAttachment object [%s]", attachID)) - // TODO(71164): In 1.15, return empty devicePath - return attachID, nil + // Don't return attachID as a devicePath. We can reconstruct the attachID using getAttachmentName() + return "", nil } func (c *csiAttacher) WaitForAttach(spec *volume.Spec, _ string, pod *v1.Pod, timeout time.Duration) (string, error) { diff --git a/pkg/volume/csi/csi_attacher_test.go b/pkg/volume/csi/csi_attacher_test.go index 04ab902c4ab..b5d86c85974 100644 --- a/pkg/volume/csi/csi_attacher_test.go +++ b/pkg/volume/csi/csi_attacher_test.go @@ -198,7 +198,7 @@ func TestAttacherAttach(t *testing.T) { csiAttacher := attacher.(*csiAttacher) - go func(spec *volume.Spec, id, nodename string, fail bool) { + go func(spec *volume.Spec, nodename string, fail bool) { attachID, err := csiAttacher.Attach(spec, types.NodeName(nodename)) if !fail && err != nil { t.Errorf("expecting no failure, but got err: %v", err) @@ -206,10 +206,10 @@ func TestAttacherAttach(t *testing.T) { if fail && err == nil { t.Errorf("expecting failure, but got no err") } - if attachID != id && !fail { - t.Errorf("expecting attachID %v, got %v", id, attachID) + if attachID != "" { + t.Errorf("expecting empty attachID, got %v", attachID) } - }(tc.spec, tc.attachID, tc.nodeName, tc.shouldFail) + }(tc.spec, tc.nodeName, tc.shouldFail) var status storage.VolumeAttachmentStatus if tc.injectAttacherError { @@ -277,15 +277,15 @@ func TestAttacherAttachWithInline(t *testing.T) { } csiAttacher := attacher.(*csiAttacher) - go func(spec *volume.Spec, id, nodename string, fail bool) { + go func(spec *volume.Spec, nodename string, fail bool) { attachID, err := csiAttacher.Attach(spec, types.NodeName(nodename)) if fail != (err != nil) { t.Errorf("expecting no failure, but got err: %v", err) } - if attachID != id && !fail { - t.Errorf("expecting attachID %v, got %v", id, attachID) + if attachID != "" { + t.Errorf("expecting empty attachID, got %v", attachID) } - }(tc.spec, tc.attachID, tc.nodeName, tc.shouldFail) + }(tc.spec, tc.nodeName, tc.shouldFail) var status storage.VolumeAttachmentStatus if tc.injectAttacherError { @@ -362,10 +362,7 @@ func TestAttacherWithCSIDriver(t *testing.T) { if err != nil { t.Errorf("Attach() failed: %s", err) } - if expectAttach && attachID == "" { - t.Errorf("Expected attachID, got nothing") - } - if !expectAttach && attachID != "" { + if attachID != "" { t.Errorf("Expected empty attachID, got %q", attachID) } }(spec, test.expectVolumeAttachment)