From a8ae3631f662020d0fabd8e6df762d3e13218edc Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Wed, 6 Oct 2021 12:41:01 -0700 Subject: [PATCH] Fix windows NodePublish failing because mount target doesn't exist --- examples/kubernetes/windows/README.md | 2 +- pkg/driver/node.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/kubernetes/windows/README.md b/examples/kubernetes/windows/README.md index 1144eca2e6..19a466fd75 100644 --- a/examples/kubernetes/windows/README.md +++ b/examples/kubernetes/windows/README.md @@ -7,7 +7,7 @@ This example shows how to create a EBS volume and consume it from a Windows cont 1. A 1.18+ Windows node. Windows support has only been tested on 1.18 EKS Windows nodes. https://docs.aws.amazon.com/eks/latest/userguide/windows-support.html 2. [csi-proxy](https://github.com/kubernetes-csi/csi-proxy) v1.0.0+ installed on the Windows node. -3. Driver v1.3.0 from GCR k8s.gcr.io/provider-aws/aws-ebs-csi-driver:v1.3.0. It can be built and pushed to another image registry with the command `TAG=$MY_TAG REGISTRY=$MY_REGISTRY make all-push` where `MY_TAG` refers to the image tag to push and `MY_REGISTRY` to the destination image registry like "XXXXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com" +3. Driver v1.3.2 from GCR k8s.gcr.io/provider-aws/aws-ebs-csi-driver:v1.3.2. It can be built and pushed to another image registry with the command `TAG=$MY_TAG REGISTRY=$MY_REGISTRY make all-push` where `MY_TAG` refers to the image tag to push and `MY_REGISTRY` to the destination image registry like "XXXXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com" 4. The driver installed with the Node plugin on the Windows node and the Controller plugin on a Linux node: `helm upgrade --install aws-ebs-csi-driver --namespace kube-system ./charts/aws-ebs-csi-driver --set node.enableWindows=true --set image.repository=$MY_REGISTRY/aws-ebs-csi-driver --set image.tag=$MY_TAG` ## Usage diff --git a/pkg/driver/node.go b/pkg/driver/node.go index 95ad9ddc8e..068bfdd1e9 100644 --- a/pkg/driver/node.go +++ b/pkg/driver/node.go @@ -589,7 +589,7 @@ func (d *nodeService) nodePublishVolumeForBlock(req *csi.NodePublishVolumeReques //Checking if the target file is already mounted with a device. mounted, err := d.isMounted(source, target) if err != nil { - return status.Errorf(codes.Internal, "Could not mount %q at %q: %v", source, target, err) + return status.Errorf(codes.Internal, "Could not check if %q is mounted: %v", target, err) } if !mounted { @@ -626,7 +626,7 @@ func (d *nodeService) isMounted(source string, target string) (bool, error) { //After successful unmount, the device is ready to be mounted. return !notMnt, nil } - return !notMnt, status.Errorf(codes.Internal, "Could not mount %q at %q: %v", source, target, err) + return !notMnt, status.Errorf(codes.Internal, "Could not check if %q is a mount point: %v, %v", target, err, pathErr) } if !notMnt { @@ -634,7 +634,12 @@ func (d *nodeService) isMounted(source string, target string) (bool, error) { return !notMnt, nil } - return !notMnt, err + // Do not return os.IsNotExist error. Other errors were handled above. It is + // the responsibility of the caller to check whether the given target path + // exists (in Linux, the target mount directory must exist before mount is + // called on it) or not (in Windows, the target must NOT exist before a + // symlink is created at it) + return !notMnt, nil } func (d *nodeService) nodePublishVolumeForFileSystem(req *csi.NodePublishVolumeRequest, mountOptions []string, mode *csi.VolumeCapability_Mount) error { @@ -665,7 +670,7 @@ func (d *nodeService) nodePublishVolumeForFileSystem(req *csi.NodePublishVolumeR mounted, err := d.isMounted(source, target) if err != nil { - return status.Errorf(codes.Internal, "Could not mount %q at %q: %v", source, target, err) + return status.Errorf(codes.Internal, "Could not check if %q is mounted: %v", target, err) } if !mounted {