awslabs / mountpoint-s3-csi-driver

Built on Mountpoint for Amazon S3, the Mountpoint CSI driver presents an Amazon S3 bucket as a storage volume accessible by containers in your Kubernetes cluster.
Apache License 2.0
153 stars 18 forks source link

Add capability to specify the S3 bucket prefix in 'volumeAttributes' #132

Closed vishwa-trulioo closed 5 months ago

vishwa-trulioo commented 5 months ago

/feature

Problem statement I was attempting to specify an S3 prefix as a 'spec.csi.volumeAttributes'. Either it is not supported or not documented. I used bucketprefix as the parameter. It didn't work

Expected outcome I checked all the examples and documentation. There is no way for us to use S3 prefix as the mount point for the 'PersistentVolume'. But, the original tool mountpoint-s3 clearly has the capability to do it.

Here is the YAML manifest I attempted,

apiVersion: v1
kind: PersistentVolume
metadata:
  name: s3-pv
spec:
  capacity:
    storage: 1Gi # ignored, required
  accessModes:
    - ReadWriteMany # supported options: ReadWriteMany / ReadOnlyMany
  mountOptions:
    - allow-delete
    - region us-east-1
  csi:
    driver: s3.csi.aws.com # required
    volumeHandle: s3-csi-driver-volume
    volumeAttributes:
      bucketName: s3-csi-driver
      bucketprefix: data/
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: s3-claim
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: "s3"
  resources:
    requests:
      storage: 1Gi
  volumeName: s3-pv
---
apiVersion: v1
kind: Pod
metadata:
  name: s3-app
spec:
  containers:
    - name: app
      image: centos
      command: ["/bin/sh"]
      args: ["-c", "echo 'Hello from the container!' >> /data/$(date -u).txt; tail -f /dev/null"]
      volumeMounts:
        - name: persistent-storage
          mountPath: /data
  volumes:
    - name: persistent-storage
      persistentVolumeClaim:
        claimName: s3-claim

Alternatives considered I tried different parameter names 'volumeAttributes'. But didn't work. for I had no other alternative.

Additional context If this is already possible, are you able to provide an example on how to do this?

EdKingscote commented 5 months ago

From the analysis I did last week, my understanding is that the mount options for the PersistentVolume should map to CLI options - have you tried

  mountOptions:
    - prefix myprefix/
dlakhaws commented 5 months ago

That is correct, the Mountpoint configurations are defined in mountOptions (documentation for this is here)

To add to the example mentioned above:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: s3-pv
spec:
  capacity:
    storage: 1200Gi # ignored, required
  accessModes:
    - ReadWriteMany # supported options: ReadWriteMany / ReadOnlyMany
  mountOptions:
    - prefix myprefix/
  csi:
    driver: s3.csi.aws.com # required
    volumeHandle: s3-csi-driver-volume
    volumeAttributes:
      bucketName: s3-csi-driver
vishwa-trulioo commented 5 months ago

Thanks for the support. This worked. Here is the final YAML manifest I used.

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: s3-pv
spec:
  capacity:
    storage: 1200Gi # ignored, required
  accessModes:
    - ReadWriteMany # supported options: ReadWriteMany / ReadOnlyMany
  mountOptions:
    - prefix myfolder/
    - region us-east-1
  csi:
    driver: s3.csi.aws.com # required
    volumeHandle: s3-csi-driver-volume
    volumeAttributes:
      bucketName: app-resources
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: s3-pvc
spec:
  storageClassName: ""
  volumeName: s3-pv
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1200Gi # Adjust the size as needed
---
apiVersion: v1
kind: Pod
metadata:
  name: app
spec:
  containers:
    - name: busybox
      image: busybox
      command: ["sleep", "3600"]
      volumeMounts:
        - name: persistent-storage
          mountPath: /data
  volumes:
    - name: persistent-storage
      persistentVolumeClaim:
        claimName: s3-pvc

The link you provided for mount options. I can't seem to find the mount options in there.

Lastly, here is my final feedback to get it working.

Thank you again for the support. we can close this issue.

dlakhaws commented 5 months ago

Thank you for the feedback. We're working to update the docs currently and will update the GitHub page once we do.

dlakhaws commented 5 months ago

The documentation on the EKS page has been updated.