Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set mode and permissions from PVC annotation (nfs.io/createMode,nfs/createUID,nfs/createGID) #121

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ metadata:
name: test-claim
annotations:
nfs.io/storage-path: "test-path" # not required, depending on whether this annotation was shown in the storage class description
nfs.io/createUID: "1000" # set folder uid as createUID on creation, not required, default 0 (root)
nfs.io/createGID: "1000" # set folder gid as createGID on creation, not required, default 0 (root)
nfs.io/createMode: "0755" # set folder mode as createMode on creation, not required, default 0777 (a+rwx)
spec:
storageClassName: managed-nfs-storage
accessModes:
Expand Down
28 changes: 25 additions & 3 deletions cmd/nfs-subdir-external-provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,33 @@ func (p *nfsProvisioner) Provision(ctx context.Context, options controller.Provi
}
}

glog.V(4).Infof("creating path %s", fullPath)
if err := os.MkdirAll(fullPath, 0777); err != nil {
createMode := os.FileMode(0777)
annotationCreateMode, exists := metadata.annotations["nfs.io/createMode"]
if exists {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please format this file with gofmt

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

annotationCreateModeUInt, _ := strconv.ParseUint(annotationCreateMode, 8, 32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the error here ignored?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

createMode = os.FileMode(annotationCreateModeUInt)
}

createUID := "0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root:root is really the default everywhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like the previous pull request behavior

annotationCreateUID, exists := metadata.annotations["nfs.io/createUID"]
if exists {
createUID = annotationCreateUID
}
createGID := "0"
annotationCreateGID, exists := metadata.annotations["nfs.io/createGID"]
if exists {
createGID = annotationCreateGID
}

uid, _ := strconv.Atoi(createUID)
gid, _ := strconv.Atoi(createGID)

glog.V(4).Infof("creating path %s with %#o mode, %d UID, %d GID", fullPath, createMode, uid, gid)
if err := os.MkdirAll(fullPath, createMode); err != nil {
return nil, controller.ProvisioningFinished, errors.New("unable to create directory to provision new pv: " + err.Error())
}
os.Chmod(fullPath, 0777)
os.Chmod(fullPath, createMode)
os.Chown(fullPath, uid, gid)

pv := &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Expand Down