Skip to content

Commit

Permalink
Assert NodePublishVolume behavior for single node single writer volumes
Browse files Browse the repository at this point in the history
Ensure that a single node single writer volume cannot be mounted at two
different target paths on the same node.

See the second table in the NodePublishVolume section of the CSI spec
for more details:
https://github.com/container-storage-interface/spec/blob/v1.7.0/spec.md#nodepublishvolume
  • Loading branch information
chrishenzie committed Jan 30, 2023
1 parent 45cd08b commit 9af9538
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ build-sanity:
$(MAKE) -C cmd/csi-sanity all


TEST_HOSTPATH_VERSION=v1.7.3
TEST_HOSTPATH_VERSION=v1.11.0
TEST_HOSTPATH_SOURCE=bin/hostpath-source
TEST_HOSTPATH_REPO=https://github.com/kubernetes-csi/csi-driver-host-path.git
bin/hostpathplugin:
Expand Down
8 changes: 4 additions & 4 deletions hack/_apitest2/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func TestMyDriverWithCustomTargetPaths(t *testing.T) {
var createTargetDirCalls, createStagingDirCalls,
removeTargetDirCalls, removeStagingDirCalls int

wantCreateTargetCalls := 3
wantCreateStagingCalls := 3
wantRemoveTargetCalls := 3
wantRemoveStagingCalls := 3
wantCreateTargetCalls := 4
wantCreateStagingCalls := 4
wantRemoveTargetCalls := 4
wantRemoveStagingCalls := 4

// tmpPath could be a CO specific directory under which all the target dirs
// are created. For k8s, it could be /var/lib/kubelet/pods under which the
Expand Down
66 changes: 60 additions & 6 deletions pkg/sanity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,13 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
var (
r *Resources

providesControllerService bool
controllerPublishSupported bool
nodeStageSupported bool
nodeVolumeStatsSupported bool
nodeExpansionSupported bool
controllerExpansionSupported bool
providesControllerService bool
controllerPublishSupported bool
nodeStageSupported bool
nodeVolumeStatsSupported bool
nodeExpansionSupported bool
controllerExpansionSupported bool
singleNodeMultiWriterSupported bool
)

createVolumeWithCapability := func(volumeName string, cap *csi.VolumeCapability) *csi.CreateVolumeResponse {
Expand Down Expand Up @@ -319,6 +320,8 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
nodeVolumeStatsSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_GET_VOLUME_STATS)
nodeExpansionSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_EXPAND_VOLUME)
controllerExpansionSupported = isControllerCapabilitySupported(cl, csi.ControllerServiceCapability_RPC_EXPAND_VOLUME)
singleNodeMultiWriterSupported = isNodeCapabilitySupported(n, csi.NodeServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER)

r = &Resources{
Context: sc,
ControllerClient: cl,
Expand Down Expand Up @@ -431,6 +434,57 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.InvalidArgument), "unexpected error: %s", serverError.Message())
})

Describe("with single node multi writer capability", func() {
BeforeEach(func() {
if !singleNodeMultiWriterSupported {
Skip("Service does not have single node multi writer capability")
}
})

It("should fail when volume with single node single writer access mode is already mounted at a different target path", func() {
By("creating a single node single writer volume")
name := UniqueString("sanity-node-publish-single-node-single-writer")
cap := TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_SINGLE_WRITER)
vol := createVolumeWithCapability(name, cap)

By("Getting a node id")
nid, err := r.NodeGetInfo(
context.Background(),
&csi.NodeGetInfoRequest{})
Expect(err).NotTo(HaveOccurred())
Expect(nid).NotTo(BeNil())
Expect(nid.GetNodeId()).NotTo(BeEmpty())

By("Staging and publishing a volume")
conpubvol := controllerPublishVolumeWithCapability(name, vol, nid, cap)
_ = nodeStageVolumeWithCapability(name, vol, conpubvol, cap)
_ = nodePublishVolumeWithCapability(name, vol, conpubvol, cap)

nodePublishRequest := &csi.NodePublishVolumeRequest{
VolumeId: vol.GetVolume().GetVolumeId(),
TargetPath: sc.TargetPath + "/other_target",
VolumeCapability: cap,
VolumeContext: vol.GetVolume().GetVolumeContext(),
Secrets: sc.Secrets.NodePublishVolumeSecret,
}
if conpubvol != nil {
nodePublishRequest.PublishContext = conpubvol.GetPublishContext()
}
if nodeStageSupported {
nodePublishRequest.StagingTargetPath = sc.StagingPath
}

_, err = r.NodePublishVolume(
context.Background(),
nodePublishRequest)
Expect(err).To(HaveOccurred())

serverError, ok := status.FromError(err)
Expect(ok).To(BeTrue())
Expect(serverError.Code()).To(Equal(codes.FailedPrecondition), "unexpected error: %s", serverError.Message())
})
})
})

Describe("NodeUnpublishVolume", func() {
Expand Down
2 changes: 1 addition & 1 deletion release-tools/prow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ configvar CSI_PROW_BUILD_PLATFORMS "linux amd64 amd64; linux ppc64le ppc64le -pp
# which is disabled with GOFLAGS=-mod=vendor).
configvar GOFLAGS_VENDOR "$( [ -d vendor ] && echo '-mod=vendor' )" "Go flags for using the vendor directory"

configvar CSI_PROW_GO_VERSION_BUILD "1.18" "Go version for building the component" # depends on component's source code
configvar CSI_PROW_GO_VERSION_BUILD "1.19" "Go version for building the component" # depends on component's source code
configvar CSI_PROW_GO_VERSION_E2E "" "override Go version for building the Kubernetes E2E test suite" # normally doesn't need to be set, see install_e2e
configvar CSI_PROW_GO_VERSION_SANITY "${CSI_PROW_GO_VERSION_BUILD}" "Go version for building the csi-sanity test suite" # depends on CSI_PROW_SANITY settings below
configvar CSI_PROW_GO_VERSION_KIND "${CSI_PROW_GO_VERSION_BUILD}" "Go version for building 'kind'" # depends on CSI_PROW_KIND_VERSION below
Expand Down

0 comments on commit 9af9538

Please sign in to comment.