Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Fixed the issue that the pod could not start mounting pvc when the prefix parameter contained a slash "/" #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gsmini
Copy link

@gsmini gsmini commented Feb 17, 2025

when use

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: s3-sc-custom-dir
provisioner: ch.ctrox.csi.s3-driver
parameters:
  mounter: s3fs
  bucket: my-bucket
  usePrefix: "true"
  prefix:  userid/1/order
  csi.storage.k8s.io/provisioner-secret-name: csi-s3-secret
  csi.storage.k8s.io/provisioner-secret-namespace: kube-system
  csi.storage.k8s.io/controller-publish-secret-name: csi-s3-secret
  csi.storage.k8s.io/controller-publish-secret-namespace: kube-system
  csi.storage.k8s.io/node-stage-secret-name: csi-s3-secret
  csi.storage.k8s.io/node-stage-secret-namespace: kube-system
  csi.storage.k8s.io/node-publish-secret-name: csi-s3-secret
  csi.storage.k8s.io/node-publish-secret-namespace: kube-system

the prefix contains slash "/", so pod run err with:

 Warning  FailedMount      10s (x7 over 42s)  kubelet         MountVolume.MountDevice failed for volume "pvc-6b77ca3b-a2ca-4053-9f95-ae2ca593285a" : rpc error: code = Unknown desc = The specified key does not exist.

this issue has the same question : #56

i debug and found the reason:

func volumeIDToBucketPrefix(volumeID string) (string, string) {
	// if the volumeID has a slash in it, this volume is
	// stored under a certain prefix within the bucket.
	splitVolumeID := strings.Split(volumeID, "/")
	if len(splitVolumeID) > 1 {
		return splitVolumeID[0], splitVolumeID[1]
	}

	return volumeID, ""
}

https://github.com/ctrox/csi-s3/blob/master/pkg/driver/controllerserver.go#L265

this code split the prefix and splitVolumeID[0] is bucket name, splitVolumeID[1] is not the subpath when prefix contains slash “/” :

splitVolumeID := strings.Split(volumeID, "/")

so i fix it ,just like this:

func volumeIDToBucketPrefix(volumeID string) (string, string) {
	// if the volumeID has a slash in it, this volume is
	// stored under a certain prefix within the bucket.
	splitVolumeID := strings.SplitN(volumeID, "/", 2)
	if len(splitVolumeID) > 1 {
		return splitVolumeID[0], splitVolumeID[1]
	}

	return volumeID, ""
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants