set mode and permissions from PVC annotation (nfs.io/createMode,nfs.io/createUID,nfs.io/createGID)
This commit is contained in:
parent
e289a21201
commit
cb203b4a46
|
|
@ -165,6 +165,9 @@ metadata:
|
||||||
name: test-claim
|
name: test-claim
|
||||||
annotations:
|
annotations:
|
||||||
nfs.io/storage-path: "test-path" # not required, depending on whether this annotation was shown in the storage class description
|
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:
|
spec:
|
||||||
storageClassName: managed-nfs-storage
|
storageClassName: managed-nfs-storage
|
||||||
accessModes:
|
accessModes:
|
||||||
|
|
|
||||||
|
|
@ -110,11 +110,33 @@ func (p *nfsProvisioner) Provision(ctx context.Context, options controller.Provi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(4).Infof("creating path %s", fullPath)
|
createMode := os.FileMode(0777)
|
||||||
if err := os.MkdirAll(fullPath, 0777); err != nil {
|
annotationCreateMode, exists := metadata.annotations["nfs.io/createMode"]
|
||||||
|
if exists {
|
||||||
|
annotationCreateModeUInt, _ := strconv.ParseUint(annotationCreateMode, 8, 32)
|
||||||
|
createMode = os.FileMode(annotationCreateModeUInt)
|
||||||
|
}
|
||||||
|
|
||||||
|
createUID := "0"
|
||||||
|
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())
|
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{
|
pv := &v1.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue