From 88e5cd64386f88c2cf86186dde33bc8e0912f6e7 Mon Sep 17 00:00:00 2001 From: torredil Date: Tue, 16 Apr 2024 17:05:35 +0000 Subject: [PATCH] Address feedback Signed-off-by: torredil --- Makefile | 2 +- cmd/hooks/prestop_test.go | 72 ++--- cmd/main.go | 23 +- hack/update-mockgen.sh | 12 +- pkg/driver/{mocks => }/mock_k8s_client.go | 0 pkg/driver/{mocks => }/mock_k8s_corev1.go | 0 pkg/driver/{mocks => }/mock_k8s_storagev1.go | 0 .../{mocks => }/mock_k8s_storagev1_csinode.go | 0 pkg/driver/node_test.go | 275 +++++++++--------- pkg/mounter/{mocks => }/mock_mount.go | 0 pkg/mounter/{mocks => }/mock_mount_windows.go | 0 pkg/mounter/mount.go | 1 + pkg/mounter/mount_linux.go | 18 +- 13 files changed, 215 insertions(+), 188 deletions(-) rename pkg/driver/{mocks => }/mock_k8s_client.go (100%) rename pkg/driver/{mocks => }/mock_k8s_corev1.go (100%) rename pkg/driver/{mocks => }/mock_k8s_storagev1.go (100%) rename pkg/driver/{mocks => }/mock_k8s_storagev1_csinode.go (100%) rename pkg/mounter/{mocks => }/mock_mount.go (100%) rename pkg/mounter/{mocks => }/mock_mount_windows.go (100%) diff --git a/Makefile b/Makefile index 0a442aa3a4..2d45031232 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,7 @@ clean: .PHONY: test test: - go test -race ./cmd/... ./pkg/... + go test -v -race ./cmd/... ./pkg/... .PHONY: test/coverage test/coverage: diff --git a/cmd/hooks/prestop_test.go b/cmd/hooks/prestop_test.go index 86e99d116e..740609857d 100644 --- a/cmd/hooks/prestop_test.go +++ b/cmd/hooks/prestop_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/golang/mock/gomock" - mockclient "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver/mocks" + "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" @@ -19,13 +19,13 @@ func TestPreStopHook(t *testing.T) { name string nodeName string expErr error - mockFunc func(string, *mockclient.MockKubernetesClient, *mockclient.MockCoreV1Interface, *mockclient.MockNodeInterface, *mockclient.MockVolumeAttachmentInterface, *mockclient.MockStorageV1Interface) error + mockFunc func(string, *driver.MockKubernetesClient, *driver.MockCoreV1Interface, *driver.MockNodeInterface, *driver.MockVolumeAttachmentInterface, *driver.MockStorageV1Interface) error }{ { name: "TestPreStopHook: CSI_NODE_NAME not set", nodeName: "", expErr: fmt.Errorf("PreStop: CSI_NODE_NAME missing"), - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockStorageV1 *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockStorageV1 *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { return nil }, }, @@ -33,8 +33,8 @@ func TestPreStopHook(t *testing.T) { name: "TestPreStopHook: failed to retrieve node information", nodeName: "test-node", expErr: fmt.Errorf("fetchNode: failed to retrieve node information: non-existent node"), - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockStorageV1 *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { - mockClient.EXPECT().CoreV1().Return(mockCoreV1).Times(1) + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockStorageV1 *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { + driver.EXPECT().CoreV1().Return(mockCoreV1).Times(1) mockCoreV1.EXPECT().Nodes().Return(mockNode).Times(1) mockNode.EXPECT().Get(gomock.Any(), gomock.Eq(nodeName), gomock.Any()).Return(nil, fmt.Errorf("non-existent node")).Times(1) @@ -45,14 +45,14 @@ func TestPreStopHook(t *testing.T) { name: "TestPreStopHook: node is not being drained, skipping VolumeAttachments check - missing TaintNodeUnschedulable", nodeName: "test-node", expErr: nil, - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockStorageV1 *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockStorageV1 *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { mockNodeObj := &v1.Node{ Spec: v1.NodeSpec{ Taints: []v1.Taint{}, }, } - mockClient.EXPECT().CoreV1().Return(mockCoreV1).Times(1) + driver.EXPECT().CoreV1().Return(mockCoreV1).Times(1) mockCoreV1.EXPECT().Nodes().Return(mockNode).Times(1) mockNode.EXPECT().Get(gomock.Any(), gomock.Eq(nodeName), gomock.Any()).Return(mockNodeObj, nil).Times(1) @@ -63,7 +63,7 @@ func TestPreStopHook(t *testing.T) { name: "TestPreStopHook: node is not being drained, skipping VolumeAttachments check - missing TaintEffectNoSchedule", nodeName: "test-node", expErr: nil, - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockStorageV1 *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockStorageV1 *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { mockNodeObj := &v1.Node{ Spec: v1.NodeSpec{ Taints: []v1.Taint{ @@ -75,7 +75,7 @@ func TestPreStopHook(t *testing.T) { }, } - mockClient.EXPECT().CoreV1().Return(mockCoreV1).Times(1) + driver.EXPECT().CoreV1().Return(mockCoreV1).Times(1) mockCoreV1.EXPECT().Nodes().Return(mockNode).Times(1) mockNode.EXPECT().Get(gomock.Any(), gomock.Eq(nodeName), gomock.Any()).Return(mockNodeObj, nil).Times(1) @@ -86,7 +86,7 @@ func TestPreStopHook(t *testing.T) { name: "TestPreStopHook: node is being drained, no volume attachments remain", nodeName: "test-node", expErr: nil, - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockVolumeAttachments *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockVolumeAttachments *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { fakeNode := &v1.Node{ Spec: v1.NodeSpec{ @@ -101,8 +101,8 @@ func TestPreStopHook(t *testing.T) { emptyVolumeAttachments := &storagev1.VolumeAttachmentList{Items: []storagev1.VolumeAttachment{}} - mockClient.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() - mockClient.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() + driver.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() + driver.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() mockCoreV1.EXPECT().Nodes().Return(mockNode).AnyTimes() mockNode.EXPECT().Get(gomock.Any(), gomock.Eq(nodeName), gomock.Any()).Return(fakeNode, nil).AnyTimes() @@ -118,7 +118,7 @@ func TestPreStopHook(t *testing.T) { name: "TestPreStopHook: node is being drained, no volume attachments associated with node", nodeName: "test-node", expErr: nil, - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockVolumeAttachments *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockVolumeAttachments *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { fakeNode := &v1.Node{ Spec: v1.NodeSpec{ @@ -141,8 +141,8 @@ func TestPreStopHook(t *testing.T) { }, } - mockClient.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() - mockClient.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() + driver.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() + driver.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() mockCoreV1.EXPECT().Nodes().Return(mockNode).AnyTimes() mockNode.EXPECT().Get(gomock.Any(), gomock.Eq(nodeName), gomock.Any()).Return(fakeNode, nil).AnyTimes() @@ -158,7 +158,7 @@ func TestPreStopHook(t *testing.T) { name: "TestPreStopHook: Node is drained before timeout", nodeName: "test-node", expErr: nil, - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockVolumeAttachments *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockVolumeAttachments *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { fakeNode := &v1.Node{ Spec: v1.NodeSpec{ @@ -184,8 +184,8 @@ func TestPreStopHook(t *testing.T) { fakeWatcher := watch.NewFake() deleteSignal := make(chan bool, 1) - mockClient.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() - mockClient.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() + driver.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() + driver.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() mockCoreV1.EXPECT().Nodes().Return(mockNode).AnyTimes() mockNode.EXPECT().Get(gomock.Any(), gomock.Eq(nodeName), gomock.Any()).Return(fakeNode, nil).AnyTimes() @@ -215,7 +215,7 @@ func TestPreStopHook(t *testing.T) { name: "TestPreStopHook: Karpenter node is not being drained, skipping VolumeAttachments check - missing TaintEffectNoSchedule", nodeName: "test-karpenter-node", expErr: nil, - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockStorageV1 *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockStorageV1 *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { mockNodeObj := &v1.Node{ Spec: v1.NodeSpec{ Taints: []v1.Taint{ @@ -227,7 +227,7 @@ func TestPreStopHook(t *testing.T) { }, } - mockClient.EXPECT().CoreV1().Return(mockCoreV1).Times(1) + driver.EXPECT().CoreV1().Return(mockCoreV1).Times(1) mockCoreV1.EXPECT().Nodes().Return(mockNode).Times(1) mockNode.EXPECT().Get(gomock.Any(), gomock.Eq(nodeName), gomock.Any()).Return(mockNodeObj, nil).Times(1) @@ -238,7 +238,7 @@ func TestPreStopHook(t *testing.T) { name: "TestPreStopHook: Karpenter node is being drained, no volume attachments remain", nodeName: "test-karpenter-node", expErr: nil, - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockVolumeAttachments *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockVolumeAttachments *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { fakeNode := &v1.Node{ Spec: v1.NodeSpec{ @@ -253,8 +253,8 @@ func TestPreStopHook(t *testing.T) { emptyVolumeAttachments := &storagev1.VolumeAttachmentList{Items: []storagev1.VolumeAttachment{}} - mockClient.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() - mockClient.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() + driver.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() + driver.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() mockCoreV1.EXPECT().Nodes().Return(mockNode).AnyTimes() mockNode.EXPECT().Get(gomock.Any(), gomock.Eq(nodeName), gomock.Any()).Return(fakeNode, nil).AnyTimes() @@ -270,7 +270,7 @@ func TestPreStopHook(t *testing.T) { name: "TestPreStopHook: Karpenter node is being drained, no volume attachments associated with node", nodeName: "test-karpenter-node", expErr: nil, - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockVolumeAttachments *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockVolumeAttachments *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { fakeNode := &v1.Node{ Spec: v1.NodeSpec{ @@ -293,8 +293,8 @@ func TestPreStopHook(t *testing.T) { }, } - mockClient.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() - mockClient.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() + driver.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() + driver.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() mockCoreV1.EXPECT().Nodes().Return(mockNode).AnyTimes() mockNode.EXPECT().Get(gomock.Any(), gomock.Eq(nodeName), gomock.Any()).Return(fakeNode, nil).AnyTimes() @@ -310,7 +310,7 @@ func TestPreStopHook(t *testing.T) { name: "TestPreStopHook: Karpenter Node is drained before timeout", nodeName: "test-karpenter-node", expErr: nil, - mockFunc: func(nodeName string, mockClient *mockclient.MockKubernetesClient, mockCoreV1 *mockclient.MockCoreV1Interface, mockNode *mockclient.MockNodeInterface, mockVolumeAttachments *mockclient.MockVolumeAttachmentInterface, mockStorageV1Interface *mockclient.MockStorageV1Interface) error { + mockFunc: func(nodeName string, driver *driver.MockKubernetesClient, mockCoreV1 *driver.MockCoreV1Interface, mockNode *driver.MockNodeInterface, mockVolumeAttachments *driver.MockVolumeAttachmentInterface, mockStorageV1Interface *driver.MockStorageV1Interface) error { fakeNode := &v1.Node{ Spec: v1.NodeSpec{ @@ -336,8 +336,8 @@ func TestPreStopHook(t *testing.T) { fakeWatcher := watch.NewFake() deleteSignal := make(chan bool, 1) - mockClient.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() - mockClient.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() + driver.EXPECT().CoreV1().Return(mockCoreV1).AnyTimes() + driver.EXPECT().StorageV1().Return(mockStorageV1Interface).AnyTimes() mockCoreV1.EXPECT().Nodes().Return(mockNode).AnyTimes() mockNode.EXPECT().Get(gomock.Any(), gomock.Eq(nodeName), gomock.Any()).Return(fakeNode, nil).AnyTimes() @@ -370,14 +370,14 @@ func TestPreStopHook(t *testing.T) { mockCtl := gomock.NewController(t) defer mockCtl.Finish() - mockClient := mockclient.NewMockKubernetesClient(mockCtl) - mockCoreV1 := mockclient.NewMockCoreV1Interface(mockCtl) - mockStorageV1 := mockclient.NewMockStorageV1Interface(mockCtl) - mockNode := mockclient.NewMockNodeInterface(mockCtl) - mockVolumeAttachments := mockclient.NewMockVolumeAttachmentInterface(mockCtl) + d := driver.NewMockKubernetesClient(mockCtl) + mockCoreV1 := driver.NewMockCoreV1Interface(mockCtl) + mockStorageV1 := driver.NewMockStorageV1Interface(mockCtl) + mockNode := driver.NewMockNodeInterface(mockCtl) + mockVolumeAttachments := driver.NewMockVolumeAttachmentInterface(mockCtl) if tc.mockFunc != nil { - err := tc.mockFunc(tc.nodeName, mockClient, mockCoreV1, mockNode, mockVolumeAttachments, mockStorageV1) + err := tc.mockFunc(tc.nodeName, d, mockCoreV1, mockNode, mockVolumeAttachments, mockStorageV1) if err != nil { t.Fatalf("TestPreStopHook: mockFunc returned error: %v", err) } @@ -387,7 +387,7 @@ func TestPreStopHook(t *testing.T) { t.Setenv("CSI_NODE_NAME", tc.nodeName) } - err := PreStop(mockClient) + err := PreStop(d) if tc.expErr != nil { require.Error(t, err) diff --git a/cmd/main.go b/cmd/main.go index 4beb76ec85..6b8cea4195 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -139,18 +139,29 @@ func main() { } region := os.Getenv("AWS_REGION") - - md, metadataErr := metadata.NewMetadataService(cfg, region) - if metadataErr != nil { - klog.ErrorS(err, "Could not determine region from any metadata service. The region can be manually supplied via the AWS_REGION environment variable.") - panic(err) - } + var md metadata.MetadataService + var metadataErr error if region == "" { klog.V(5).InfoS("[Debug] Retrieving region from metadata service") + md, metadataErr = metadata.NewMetadataService(cfg, region) + if metadataErr != nil { + klog.ErrorS(metadataErr, "Could not determine region from any metadata service. The region can be manually supplied via the AWS_REGION environment variable.") + panic(metadataErr) + } region = md.GetRegion() } + if md == nil { + if options.Mode == driver.NodeMode || options.Mode == driver.AllMode { + md, metadataErr = metadata.NewMetadataService(cfg, region) + if metadataErr != nil { + klog.ErrorS(metadataErr, "failed to initialize metadata service") + klog.FlushAndExit(klog.ExitFlushTimeout, 1) + } + } + } + cloud, err := cloud.NewCloud(region, options.AwsSdkDebugLog, options.UserAgentExtra, options.Batching) if err != nil { klog.ErrorS(err, "failed to create cloud service") diff --git a/hack/update-mockgen.sh b/hack/update-mockgen.sh index c157381952..10cd3ed6ba 100755 --- a/hack/update-mockgen.sh +++ b/hack/update-mockgen.sh @@ -21,12 +21,12 @@ BIN="$(dirname "$(realpath "${BASH_SOURCE[0]}")")/../bin" # Source-based mocking for internal interfaces "${BIN}/mockgen" -package cloud -destination=./pkg/cloud/mock_cloud.go -source pkg/cloud/interface.go "${BIN}/mockgen" -package metadata -destination=./pkg/cloud/metadata/mock_metadata.go -source pkg/cloud/metadata/interface.go -"${BIN}/mockgen" -package mounter -destination=./pkg/mounter/mocks/mock_mount.go -source pkg/mounter/mount.go -"${BIN}/mockgen" -package mounter -destination=./pkg/mounter/mocks/mock_mount_windows.go -source pkg/mounter/safe_mounter_windows.go +"${BIN}/mockgen" -package mounter -destination=./pkg/mounter/mock_mount.go -source pkg/mounter/mount.go +"${BIN}/mockgen" -package mounter -destination=./pkg/mounter/mock_mount_windows.go -source pkg/mounter/safe_mounter_windows.go "${BIN}/mockgen" -package cloud -destination=./pkg/cloud/mock_ec2.go -source pkg/cloud/ec2_interface.go EC2API # Reflection-based mocking for external dependencies -"${BIN}/mockgen" -package driver -destination=./pkg/driver/mocks/mock_k8s_client.go -mock_names='Interface=MockKubernetesClient' k8s.io/client-go/kubernetes Interface -"${BIN}/mockgen" -package driver -destination=./pkg/driver/mocks/mock_k8s_corev1.go k8s.io/client-go/kubernetes/typed/core/v1 CoreV1Interface,NodeInterface -"${BIN}/mockgen" -package driver -destination=./pkg/driver/mocks/mock_k8s_storagev1.go k8s.io/client-go/kubernetes/typed/storage/v1 VolumeAttachmentInterface,StorageV1Interface -"${BIN}/mockgen" -package driver -destination=./pkg/driver/mocks/mock_k8s_storagev1_csinode.go k8s.io/client-go/kubernetes/typed/storage/v1 CSINodeInterface +"${BIN}/mockgen" -package driver -destination=./pkg/driver/mock_k8s_client.go -mock_names='Interface=MockKubernetesClient' k8s.io/client-go/kubernetes Interface +"${BIN}/mockgen" -package driver -destination=./pkg/driver/mock_k8s_corev1.go k8s.io/client-go/kubernetes/typed/core/v1 CoreV1Interface,NodeInterface +"${BIN}/mockgen" -package driver -destination=./pkg/driver/mock_k8s_storagev1.go k8s.io/client-go/kubernetes/typed/storage/v1 VolumeAttachmentInterface,StorageV1Interface +"${BIN}/mockgen" -package driver -destination=./pkg/driver/mock_k8s_storagev1_csinode.go k8s.io/client-go/kubernetes/typed/storage/v1 CSINodeInterface diff --git a/pkg/driver/mocks/mock_k8s_client.go b/pkg/driver/mock_k8s_client.go similarity index 100% rename from pkg/driver/mocks/mock_k8s_client.go rename to pkg/driver/mock_k8s_client.go diff --git a/pkg/driver/mocks/mock_k8s_corev1.go b/pkg/driver/mock_k8s_corev1.go similarity index 100% rename from pkg/driver/mocks/mock_k8s_corev1.go rename to pkg/driver/mock_k8s_corev1.go diff --git a/pkg/driver/mocks/mock_k8s_storagev1.go b/pkg/driver/mock_k8s_storagev1.go similarity index 100% rename from pkg/driver/mocks/mock_k8s_storagev1.go rename to pkg/driver/mock_k8s_storagev1.go diff --git a/pkg/driver/mocks/mock_k8s_storagev1_csinode.go b/pkg/driver/mock_k8s_storagev1_csinode.go similarity index 100% rename from pkg/driver/mocks/mock_k8s_storagev1_csinode.go rename to pkg/driver/mock_k8s_storagev1_csinode.go diff --git a/pkg/driver/node_test.go b/pkg/driver/node_test.go index 84c952c093..1b4856e9f9 100644 --- a/pkg/driver/node_test.go +++ b/pkg/driver/node_test.go @@ -31,8 +31,7 @@ import ( "github.com/golang/mock/gomock" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud/metadata" "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver/internal" - mockclient "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver/mocks" - mockmounter "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/mounter/mocks" + "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/mounter" "github.com/stretchr/testify/assert" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -48,8 +47,8 @@ func TestNewNodeService(t *testing.T) { defer ctrl.Finish() mockMetadataService := metadata.NewMockMetadataService(ctrl) - mockMounter := mockmounter.NewMockMounter(ctrl) - mockKubernetesClient := mockclient.NewMockKubernetesClient(ctrl) + mockMounter := mounter.NewMockMounter(ctrl) + mockKubernetesClient := NewMockKubernetesClient(ctrl) os.Setenv("AWS_REGION", "us-west-2") defer os.Unsetenv("AWS_REGION") @@ -83,7 +82,7 @@ func TestNodeStageVolume(t *testing.T) { testCases := []struct { name string req *csi.NodeStageVolumeRequest - mounterMock func(ctrl *gomock.Controller) *mockmounter.MockMounter + mounterMock func(ctrl *gomock.Controller) *mounter.MockMounter metadataMock func(ctrl *gomock.Controller) *metadata.MockMetadataService expectedErr error inflight bool @@ -105,8 +104,8 @@ func TestNodeStageVolume(t *testing.T) { }, PublishContext: map[string]string{DevicePathKey: "/dev/xvdba"}, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Any()).Return(true, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Any()).Return("", 1, nil) @@ -261,8 +260,8 @@ func TestNodeStageVolume(t *testing.T) { }, PublishContext: map[string]string{DevicePathKey: "/dev/xvdba"}, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Any()).Return(false, nil) m.EXPECT().MakeDir(gomock.Any()).Return(nil) @@ -320,8 +319,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) return m }, metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService { @@ -351,8 +350,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) return m }, metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService { @@ -382,8 +381,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) return m }, metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService { @@ -413,8 +412,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) return m }, metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService { @@ -444,8 +443,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) return m }, metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService { @@ -475,8 +474,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) return m }, metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService { @@ -504,8 +503,8 @@ func TestNodeStageVolume(t *testing.T) { }, PublishContext: map[string]string{}, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) return m }, metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService { @@ -532,8 +531,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) return m }, metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService { @@ -564,8 +563,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), "1", gomock.Any()).Return("/dev/xvdba1", nil) m.EXPECT().PathExists(gomock.Any()).Return(true, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Any()).Return("", 1, nil) @@ -602,8 +601,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), "", gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Any()).Return(true, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Any()).Return("", 1, nil) @@ -637,8 +636,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Eq("/dev/xvdba"), gomock.Eq("vol-test"), gomock.Eq(""), gomock.Eq("us-west-2")).Return("", errors.New("find device path error")) return m }, @@ -668,8 +667,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Eq("/staging/path")).Return(false, errors.New("path exists error")) return m @@ -700,8 +699,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Eq("/staging/path")).Return(false, nil) m.EXPECT().MakeDir(gomock.Eq("/staging/path")).Return(errors.New("make dir error")) @@ -733,8 +732,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Eq("/staging/path")).Return(true, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/staging/path")).Return("", 0, errors.New("get device name error")) @@ -766,8 +765,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Eq("/staging/path")).Return(true, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/staging/path")).Return("/dev/xvdba", 1, nil) @@ -799,8 +798,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Eq("/staging/path")).Return(true, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/staging/path")).Return("", 1, nil) @@ -833,8 +832,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Any()).Return(true, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Any()).Return("", 1, nil) @@ -868,8 +867,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Any()).Return(true, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Any()).Return("", 1, nil) @@ -912,8 +911,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Eq("/staging/path")).Return(true, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/staging/path")).Return("", 1, nil) @@ -951,8 +950,8 @@ func TestNodeStageVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Eq("/staging/path")).Return(true, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/staging/path")).Return("", 1, nil) @@ -974,7 +973,7 @@ func TestNodeStageVolume(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - var mounter *mockmounter.MockMounter + var mounter *mounter.MockMounter if tc.mounterMock != nil { mounter = tc.mounterMock(ctrl) } @@ -1191,7 +1190,7 @@ func TestGetVolumesLimit(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - var mounter *mockmounter.MockMounter + var mounter *mounter.MockMounter var metadata *metadata.MockMetadataService if tc.metadataMock != nil { @@ -1217,7 +1216,7 @@ func TestNodePublishVolume(t *testing.T) { testCases := []struct { name string req *csi.NodePublishVolumeRequest - mounterMock func(ctrl *gomock.Controller) *mockmounter.MockMounter + mounterMock func(ctrl *gomock.Controller) *mounter.MockMounter metadataMock func(ctrl *gomock.Controller) *metadata.MockMetadataService expectedErr error inflight bool @@ -1240,8 +1239,8 @@ func TestNodePublishVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Any()).Return(true, nil) @@ -1274,8 +1273,8 @@ func TestNodePublishVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().PreparePublishTarget(gomock.Any()).Return(nil) m.EXPECT().IsLikelyNotMountPoint(gomock.Any()).Return(true, nil) m.EXPECT().Mount(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) @@ -1411,8 +1410,8 @@ func TestNodePublishVolume(t *testing.T) { }, Readonly: true, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Any()).Return(true, nil) @@ -1488,8 +1487,8 @@ func TestNodePublishVolume(t *testing.T) { VolumeAttributePartition: "0", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Any()).Return(true, nil) @@ -1525,8 +1524,8 @@ func TestNodePublishVolume(t *testing.T) { VolumeAttributePartition: "1", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("/dev/xvdba", nil) m.EXPECT().PathExists(gomock.Any()).Return(true, nil) @@ -1559,8 +1558,8 @@ func TestNodePublishVolume(t *testing.T) { DevicePathKey: "/dev/xvdba", }, }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().FindDevicePath(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("", errors.New("device path error")) return m @@ -1578,7 +1577,7 @@ func TestNodePublishVolume(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - var mounter *mockmounter.MockMounter + var mounter *mounter.MockMounter if tc.mounterMock != nil { mounter = tc.mounterMock(ctrl) } @@ -1610,7 +1609,7 @@ func TestNodeUnstageVolume(t *testing.T) { testCases := []struct { name string req *csi.NodeUnstageVolumeRequest - mounterMock func(ctrl *gomock.Controller) *mockmounter.MockMounter + mounterMock func(ctrl *gomock.Controller) *mounter.MockMounter expectedErr error inflight bool }{ @@ -1620,8 +1619,8 @@ func TestNodeUnstageVolume(t *testing.T) { VolumeId: "vol-test", StagingTargetPath: "/staging/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().GetDeviceNameFromMount(gomock.Any()).Return("dev-test", 1, nil) m.EXPECT().Unstage(gomock.Any()).Return(nil) return m @@ -1647,8 +1646,8 @@ func TestNodeUnstageVolume(t *testing.T) { VolumeId: "vol-test", StagingTargetPath: "/staging/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().GetDeviceNameFromMount(gomock.Any()).Return("", 1, nil) m.EXPECT().Unstage(gomock.Any()).Return(errors.New("unstage failed")) return m @@ -1661,8 +1660,8 @@ func TestNodeUnstageVolume(t *testing.T) { VolumeId: "vol-test", StagingTargetPath: "/staging/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().GetDeviceNameFromMount(gomock.Any()).Return("", 0, nil) return m }, @@ -1673,8 +1672,8 @@ func TestNodeUnstageVolume(t *testing.T) { VolumeId: "vol-test", StagingTargetPath: "/staging/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().GetDeviceNameFromMount(gomock.Any()).Return("", 0, errors.New("failed to get device name")) return m }, @@ -1686,8 +1685,8 @@ func TestNodeUnstageVolume(t *testing.T) { VolumeId: "vol-test", StagingTargetPath: "/staging/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().GetDeviceNameFromMount(gomock.Any()).Return("dev-test", 2, nil) m.EXPECT().Unstage(gomock.Any()).Return(nil) return m @@ -1709,7 +1708,7 @@ func TestNodeUnstageVolume(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - var mounter *mockmounter.MockMounter + var mounter *mounter.MockMounter if tc.mounterMock != nil { mounter = tc.mounterMock(ctrl) } @@ -1839,7 +1838,7 @@ func TestNodeGetInfo(t *testing.T) { defer ctrl.Finish() metadataService := tc.metadataMock(ctrl) - mounter := mockmounter.NewMockMounter(ctrl) + mounter := mounter.NewMockMounter(ctrl) driver := &NodeService{ metadata: metadataService, @@ -1864,7 +1863,7 @@ func TestNodeUnpublishVolume(t *testing.T) { testCases := []struct { name string req *csi.NodeUnpublishVolumeRequest - mounterMock func(ctrl *gomock.Controller) *mockmounter.MockMounter + mounterMock func(ctrl *gomock.Controller) *mounter.MockMounter expectedErr error inflight bool }{ @@ -1874,8 +1873,8 @@ func TestNodeUnpublishVolume(t *testing.T) { VolumeId: "vol-test", TargetPath: "/target/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().Unpublish(gomock.Eq("/target/path")).Return(nil) return m }, @@ -1900,8 +1899,8 @@ func TestNodeUnpublishVolume(t *testing.T) { VolumeId: "vol-test", TargetPath: "/target/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().Unpublish(gomock.Eq("/target/path")).Return(errors.New("unpublish failed")) return m }, @@ -1923,7 +1922,7 @@ func TestNodeUnpublishVolume(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - var mounter *mockmounter.MockMounter + var mounter *mounter.MockMounter if tc.mounterMock != nil { mounter = tc.mounterMock(ctrl) } @@ -1949,7 +1948,7 @@ func TestNodeExpandVolume(t *testing.T) { testCases := []struct { name string req *csi.NodeExpandVolumeRequest - mounterMock func(ctrl *gomock.Controller) *mockmounter.MockMounter + mounterMock func(ctrl *gomock.Controller) *mounter.MockMounter metadataMock func(ctrl *gomock.Controller) *metadata.MockMetadataService expectedResp *csi.NodeExpandVolumeResponse expectedErr error @@ -1960,8 +1959,8 @@ func TestNodeExpandVolume(t *testing.T) { VolumeId: "vol-test", VolumePath: "/volume/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/volume/path")).Return("device-name", 1, nil) m.EXPECT().FindDevicePath(gomock.Eq("device-name"), gomock.Eq("vol-test"), gomock.Eq(""), gomock.Eq("us-west-2")).Return("/dev/xvdba", nil) @@ -2028,8 +2027,8 @@ func TestNodeExpandVolume(t *testing.T) { VolumeId: "vol-test", VolumePath: "/volume/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, errors.New("failed to determine if block device")) return m }, @@ -2041,8 +2040,8 @@ func TestNodeExpandVolume(t *testing.T) { VolumeId: "vol-test", VolumePath: "/volume/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(true, nil) m.EXPECT().GetBlockSizeBytes(gomock.Eq("/volume/path")).Return(int64(0), errors.New("failed to get block size")) return m @@ -2055,8 +2054,8 @@ func TestNodeExpandVolume(t *testing.T) { VolumeId: "vol-test", VolumePath: "/volume/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(true, nil) m.EXPECT().GetBlockSizeBytes(gomock.Eq("/volume/path")).Return(int64(1000), nil) return m @@ -2069,8 +2068,8 @@ func TestNodeExpandVolume(t *testing.T) { VolumeId: "vol-test", VolumePath: "/volume/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/volume/path")).Return("", 0, errors.New("failed to get device name")) return m @@ -2085,8 +2084,8 @@ func TestNodeExpandVolume(t *testing.T) { VolumeId: "vol-test", VolumePath: "/volume/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/volume/path")).Return("device-name", 1, nil) m.EXPECT().FindDevicePath(gomock.Eq("device-name"), gomock.Eq("vol-test"), gomock.Eq(""), gomock.Eq("us-west-2")).Return("", errors.New("failed to find device path")) @@ -2106,8 +2105,8 @@ func TestNodeExpandVolume(t *testing.T) { VolumeId: "vol-test", VolumePath: "/volume/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/volume/path")).Return("device-name", 1, nil) m.EXPECT().FindDevicePath(gomock.Eq("device-name"), gomock.Eq("vol-test"), gomock.Eq(""), gomock.Eq("us-west-2")).Return("/dev/xvdba", nil) @@ -2128,8 +2127,8 @@ func TestNodeExpandVolume(t *testing.T) { VolumeId: "vol-test", VolumePath: "/volume/path", }, - mounterMock: func(ctrl *gomock.Controller) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().IsBlockDevice(gomock.Eq("/volume/path")).Return(false, nil) m.EXPECT().GetDeviceNameFromMount(gomock.Eq("/volume/path")).Return("device-name", 1, nil) m.EXPECT().FindDevicePath(gomock.Eq("device-name"), gomock.Eq("vol-test"), gomock.Eq(""), gomock.Eq("us-west-2")).Return("/dev/xvdba", nil) @@ -2152,7 +2151,7 @@ func TestNodeExpandVolume(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - var mounter *mockmounter.MockMounter + var mounter *mounter.MockMounter if tc.mounterMock != nil { mounter = tc.mounterMock(ctrl) } @@ -2185,15 +2184,15 @@ func TestNodeGetVolumeStats(t *testing.T) { validVolId bool validPath bool metricsStatErr bool - mounterMock func(mockCtl *gomock.Controller, dir string) *mockmounter.MockMounter + mounterMock func(mockCtl *gomock.Controller, dir string) *mounter.MockMounter expectedErr func(dir string) error }{ { name: "success normal", validVolId: true, validPath: true, - mounterMock: func(ctrl *gomock.Controller, dir string) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller, dir string) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().PathExists(dir).Return(true, nil) m.EXPECT().IsBlockDevice(gomock.Eq(dir)).Return(false, nil) return m @@ -2221,8 +2220,8 @@ func TestNodeGetVolumeStats(t *testing.T) { name: "path_exists_error", validVolId: true, validPath: true, - mounterMock: func(ctrl *gomock.Controller, dir string) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller, dir string) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().PathExists(dir).Return(false, errors.New("path exists error")) return m }, @@ -2234,8 +2233,8 @@ func TestNodeGetVolumeStats(t *testing.T) { name: "path_does_not_exist", validVolId: true, validPath: true, - mounterMock: func(ctrl *gomock.Controller, dir string) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller, dir string) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().PathExists(dir).Return(false, nil) return m }, @@ -2247,8 +2246,8 @@ func TestNodeGetVolumeStats(t *testing.T) { name: "is_block_device_error", validVolId: true, validPath: true, - mounterMock: func(ctrl *gomock.Controller, dir string) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller, dir string) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().PathExists(dir).Return(true, nil) m.EXPECT().IsBlockDevice(gomock.Eq(dir)).Return(false, errors.New("is block device error")) return m @@ -2261,8 +2260,8 @@ func TestNodeGetVolumeStats(t *testing.T) { name: "get_block_size_bytes_error", validVolId: true, validPath: true, - mounterMock: func(ctrl *gomock.Controller, dir string) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller, dir string) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().PathExists(dir).Return(true, nil) m.EXPECT().IsBlockDevice(gomock.Eq(dir)).Return(true, nil) m.EXPECT().GetBlockSizeBytes(dir).Return(int64(0), errors.New("get block size bytes error")) @@ -2276,8 +2275,8 @@ func TestNodeGetVolumeStats(t *testing.T) { name: "success block device", validVolId: true, validPath: true, - mounterMock: func(ctrl *gomock.Controller, dir string) *mockmounter.MockMounter { - m := mockmounter.NewMockMounter(ctrl) + mounterMock: func(ctrl *gomock.Controller, dir string) *mounter.MockMounter { + m := mounter.NewMockMounter(ctrl) m.EXPECT().PathExists(dir).Return(true, nil) m.EXPECT().IsBlockDevice(gomock.Eq(dir)).Return(true, nil) m.EXPECT().GetBlockSizeBytes(dir).Return(int64(1024), nil) @@ -2296,7 +2295,7 @@ func TestNodeGetVolumeStats(t *testing.T) { dir := t.TempDir() - var mounter *mockmounter.MockMounter + var mounter *mounter.MockMounter if tc.mounterMock != nil { mounter = tc.mounterMock(ctrl, dir) } @@ -2352,10 +2351,10 @@ func TestRemoveNotReadyTaint(t *testing.T) { t.Setenv("CSI_NODE_NAME", nodeName) getNodeMock, _ := getNodeMock(mockCtl, nodeName, &corev1.Node{}, nil) - storageV1Mock := mockclient.NewMockStorageV1Interface(mockCtl) - getNodeMock.(*mockclient.MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() + storageV1Mock := NewMockStorageV1Interface(mockCtl) + getNodeMock.(*MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() - csiNodesMock := mockclient.NewMockCSINodeInterface(mockCtl) + csiNodesMock := NewMockCSINodeInterface(mockCtl) storageV1Mock.EXPECT().CSINodes().Return(csiNodesMock).Times(1) count := int32(1) @@ -2405,10 +2404,10 @@ func TestRemoveNotReadyTaint(t *testing.T) { }, }, nil) - storageV1Mock := mockclient.NewMockStorageV1Interface(mockCtl) - getNodeMock.(*mockclient.MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() + storageV1Mock := NewMockStorageV1Interface(mockCtl) + getNodeMock.(*MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() - csiNodesMock := mockclient.NewMockCSINodeInterface(mockCtl) + csiNodesMock := NewMockCSINodeInterface(mockCtl) storageV1Mock.EXPECT().CSINodes().Return(csiNodesMock).Times(1) count := int32(1) @@ -2463,10 +2462,10 @@ func TestRemoveNotReadyTaint(t *testing.T) { }, }, nil) - storageV1Mock := mockclient.NewMockStorageV1Interface(mockCtl) - getNodeMock.(*mockclient.MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() + storageV1Mock := NewMockStorageV1Interface(mockCtl) + getNodeMock.(*MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() - csiNodesMock := mockclient.NewMockCSINodeInterface(mockCtl) + csiNodesMock := NewMockCSINodeInterface(mockCtl) storageV1Mock.EXPECT().CSINodes().Return(csiNodesMock).Times(1) count := int32(1) @@ -2521,10 +2520,10 @@ func TestRemoveNotReadyTaint(t *testing.T) { }, }, nil) - storageV1Mock := mockclient.NewMockStorageV1Interface(mockCtl) - getNodeMock.(*mockclient.MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() + storageV1Mock := NewMockStorageV1Interface(mockCtl) + getNodeMock.(*MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() - csiNodesMock := mockclient.NewMockCSINodeInterface(mockCtl) + csiNodesMock := NewMockCSINodeInterface(mockCtl) storageV1Mock.EXPECT().CSINodes().Return(csiNodesMock).Times(1) csiNodesMock.EXPECT(). @@ -2556,10 +2555,10 @@ func TestRemoveNotReadyTaint(t *testing.T) { }, }, nil) - storageV1Mock := mockclient.NewMockStorageV1Interface(mockCtl) - getNodeMock.(*mockclient.MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() + storageV1Mock := NewMockStorageV1Interface(mockCtl) + getNodeMock.(*MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() - csiNodesMock := mockclient.NewMockCSINodeInterface(mockCtl) + csiNodesMock := NewMockCSINodeInterface(mockCtl) storageV1Mock.EXPECT().CSINodes().Return(csiNodesMock).Times(1) mockCSINode := &v1.CSINode{ @@ -2605,10 +2604,10 @@ func TestRemoveNotReadyTaint(t *testing.T) { }, }, nil) - storageV1Mock := mockclient.NewMockStorageV1Interface(mockCtl) - getNodeMock.(*mockclient.MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() + storageV1Mock := NewMockStorageV1Interface(mockCtl) + getNodeMock.(*MockKubernetesClient).EXPECT().StorageV1().Return(storageV1Mock).AnyTimes() - csiNodesMock := mockclient.NewMockCSINodeInterface(mockCtl) + csiNodesMock := NewMockCSINodeInterface(mockCtl) storageV1Mock.EXPECT().CSINodes().Return(csiNodesMock).Times(1) mockCSINode := &v1.CSINode{ @@ -2683,10 +2682,10 @@ func TestRemoveTaintInBackground(t *testing.T) { }) } -func getNodeMock(mockCtl *gomock.Controller, nodeName string, returnNode *corev1.Node, returnError error) (kubernetes.Interface, *mockclient.MockNodeInterface) { - mockClient := mockclient.NewMockKubernetesClient(mockCtl) - mockCoreV1 := mockclient.NewMockCoreV1Interface(mockCtl) - mockNode := mockclient.NewMockNodeInterface(mockCtl) +func getNodeMock(mockCtl *gomock.Controller, nodeName string, returnNode *corev1.Node, returnError error) (kubernetes.Interface, *MockNodeInterface) { + mockClient := NewMockKubernetesClient(mockCtl) + mockCoreV1 := NewMockCoreV1Interface(mockCtl) + mockNode := NewMockNodeInterface(mockCtl) mockClient.EXPECT().CoreV1().Return(mockCoreV1).MinTimes(1) mockCoreV1.EXPECT().Nodes().Return(mockNode).MinTimes(1) diff --git a/pkg/mounter/mocks/mock_mount.go b/pkg/mounter/mock_mount.go similarity index 100% rename from pkg/mounter/mocks/mock_mount.go rename to pkg/mounter/mock_mount.go diff --git a/pkg/mounter/mocks/mock_mount_windows.go b/pkg/mounter/mock_mount_windows.go similarity index 100% rename from pkg/mounter/mocks/mock_mount_windows.go rename to pkg/mounter/mock_mount_windows.go diff --git a/pkg/mounter/mount.go b/pkg/mounter/mount.go index 371d9ccef0..d530e6bd30 100644 --- a/pkg/mounter/mount.go +++ b/pkg/mounter/mount.go @@ -50,6 +50,7 @@ type NodeMounter struct { *mountutils.SafeFormatAndMount } +// NewNodeMounter returns a new intsance of NodeMounter. func NewNodeMounter() (Mounter, error) { // mounter.NewSafeMounter returns a SafeFormatAndMount safeMounter, err := NewSafeMounter() diff --git a/pkg/mounter/mount_linux.go b/pkg/mounter/mount_linux.go index a248f66543..822518d1f7 100644 --- a/pkg/mounter/mount_linux.go +++ b/pkg/mounter/mount_linux.go @@ -39,6 +39,9 @@ const ( diskPartitionSuffix = "" ) +// FindDevicePath finds path of device and verifies its existence +// if the device is not nvme, return the path directly +// if the device is nvme, finds and returns the nvme device path eg. /dev/nvme1n1 func (m *NodeMounter) FindDevicePath(devicePath, volumeID, partition, region string) (string, error) { strippedVolumeName := strings.Replace(volumeID, "-", "", -1) canonicalDevicePath := "" @@ -88,6 +91,10 @@ func (m *NodeMounter) FindDevicePath(devicePath, volumeID, partition, region str if util.IsSBE(region) { klog.V(5).InfoS("[Debug] Falling back to snow volume lookup", "devicePath", devicePath) + // Snow completely ignores the requested device path and mounts volumes starting at /dev/vda .. /dev/vdb .. etc + // Morph the device path to the snow form by chopping off the last letter and prefixing with /dev/vd + // VMs on snow devices are currently limited to 10 block devices each - if that ever exceeds 26 this will need + // to be adapted canonicalDevicePath = "/dev/vd" + devicePath[len(devicePath)-1:] } @@ -130,12 +137,13 @@ func findNvmeVolume(findName string) (device string, err error) { return resolved, nil } -// Helper to inject exec.Comamnd().CombinedOutput() for verifyVolumeSerialMatch +// execRunner is a helper to inject exec.Comamnd().CombinedOutput() for verifyVolumeSerialMatch // Tests use a mocked version that does not actually execute any binaries func execRunner(name string, arg ...string) ([]byte, error) { return exec.Command(name, arg...).CombinedOutput() } +// verifyVolumeSerialMatch checks the volume serial of the device against the expected volume func verifyVolumeSerialMatch(canonicalDevicePath string, strippedVolumeName string, execRunner func(string, ...string) ([]byte, error)) error { // In some rare cases, a race condition can lead to the /dev/disk/by-id/ symlink becoming out of date // See https://github.com/kubernetes-sigs/aws-ebs-csi-driver/issues/1224 for more info @@ -161,6 +169,7 @@ func verifyVolumeSerialMatch(canonicalDevicePath string, strippedVolumeName stri return nil } +// PreparePublishTarget creates the target directory for the volume to be mounted func (m *NodeMounter) PreparePublishTarget(target string) error { klog.V(4).InfoS("NodePublishVolume: creating dir", "target", target) if err := m.MakeDir(target); err != nil { @@ -169,6 +178,7 @@ func (m *NodeMounter) PreparePublishTarget(target string) error { return nil } +// IsBlockDevice checks if the given path is a block device func (m *NodeMounter) IsBlockDevice(fullPath string) (bool, error) { var st unix.Stat_t err := unix.Stat(fullPath, &st) @@ -179,6 +189,7 @@ func (m *NodeMounter) IsBlockDevice(fullPath string) (bool, error) { return (st.Mode & unix.S_IFMT) == unix.S_IFBLK, nil } +// GetBlockSizeBytes gets the size of the disk in bytes func (m *NodeMounter) GetBlockSizeBytes(devicePath string) (int64, error) { output, err := m.Exec.Command("blockdev", "--getsize64", devicePath).Output() if err != nil { @@ -192,6 +203,7 @@ func (m *NodeMounter) GetBlockSizeBytes(devicePath string) (int64, error) { return gotSizeBytes, nil } +// appendPartition appends the partition to the device path func (m *NodeMounter) appendPartition(devicePath, partition string) string { if partition == "" { return devicePath @@ -247,19 +259,23 @@ func (m *NodeMounter) PathExists(path string) (bool, error) { return mountutils.PathExists(path) } +// Resize resizes the filesystem of the given devicePath func (m *NodeMounter) Resize(devicePath, deviceMountPath string) (bool, error) { return mountutils.NewResizeFs(m.Exec).Resize(devicePath, deviceMountPath) } +// NeedResize checks if the filesystem of the given devicePath needs to be resized func (m *NodeMounter) NeedResize(devicePath string, deviceMountPath string) (bool, error) { return mountutils.NewResizeFs(m.Exec).NeedResize(devicePath, deviceMountPath) } +// Unpublish unmounts the given path func (m *NodeMounter) Unpublish(path string) error { // On linux, unpublish and unstage both perform an unmount return m.Unstage(path) } +// Unstage unmounts the given path func (m *NodeMounter) Unstage(path string) error { err := mountutils.CleanupMountPoint(path, m, false) // Ignore the error when it contains "not mounted", because that indicates the