Skip to content

Commit

Permalink
support mountOptions in configmap (#1103)
Browse files Browse the repository at this point in the history
support mountOptions in configmap
  • Loading branch information
zxh326 authored Sep 3, 2024
1 parent 620ef9f commit 1b9d295
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/scripts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def wait_dir_not_empty(check_path):
output = subprocess.run(["sudo", "ls", check_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if output.stderr.decode("utf-8") != "":
LOG.info("output stderr {}".format(output.stderr.decode("utf-8")))
time.sleep(5)
continue
if output.stdout.decode("utf-8") != "":
return True
Expand Down
10 changes: 9 additions & 1 deletion juicefs-csi-driver-config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,12 @@ data:
# volumes:
# - name: block-devices
# persistentVolumeClaim:
# claimName: block-pv
# claimName: block-pv
# add some mountOptions to the mount pod
# - pvcSelector:
# matchLabels:
# need-mount-options: "true"
# mountOptions:
# - writeback
# - xxx
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ type MountPodPatch struct {
VolumeDevices []corev1.VolumeDevice `json:"volumeDevices,omitempty"`
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
Env []corev1.EnvVar `json:"env,omitempty"`
MountOptions []string `json:"mountOptions,omitempty"`
}

func (mpp *MountPodPatch) isMatch(pvc *corev1.PersistentVolumeClaim) bool {
Expand Down Expand Up @@ -332,6 +333,9 @@ func (mpp *MountPodPatch) merge(mp MountPodPatch) {
if mp.Env != nil {
mpp.Env = mp.Env
}
if mp.MountOptions != nil {
mpp.MountOptions = mp.MountOptions
}
}

// TODO: migrate more config for here
Expand Down
15 changes: 15 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,21 @@ func TestGenMountPodPatch(t *testing.T) {
},
},
},
{
name: "test mount options",
baseConfig: &Config{
MountPodPatch: []MountPodPatch{
{
MountOptions: []string{"rw", "nolock"},
},
},
},
expectedPatch: MountPodPatch{
Labels: map[string]string{},
Annotations: map[string]string{},
MountOptions: []string{"rw", "nolock"},
},
},
}

for _, tc := range testCases {
Expand Down
25 changes: 21 additions & 4 deletions pkg/config/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,10 @@ func GenPodAttrWithCfg(setting *JfsSetting, volCtx map[string]string) error {
}
}
}

setting.Attr = attr
// apply config patch
applyAttrPatch(attr, setting)
applyConfigPatch(setting)

return nil
}

Expand Down Expand Up @@ -527,12 +528,14 @@ func GenPodAttrWithMountPod(ctx context.Context, client *k8sclient.K8sClient, mo
Name: mountPod.Annotations[JuiceFSUUID],
VolumeId: mountPod.Annotations[UniqueId],
MountPath: filepath.Join(PodMountBase, pvName) + mountPod.Name[len(mountPod.Name)-7:],
Options: pv.Spec.MountOptions,
}
if v, ok := pv.Spec.CSI.VolumeAttributes["subPath"]; ok && v != "" {
setting.SubPath = v
}
setting.Attr = attr
// apply config patch
applyAttrPatch(attr, setting)
applyConfigPatch(setting)
return attr, nil
}

Expand Down Expand Up @@ -698,7 +701,8 @@ func getDefaultResource() corev1.ResourceRequirements {
}
}

func applyAttrPatch(attr *PodAttr, setting *JfsSetting) {
func applyConfigPatch(setting *JfsSetting) {
attr := setting.Attr
// overwrite by mountpod patch
patch := GlobalConfig.GenMountPodPatch(*setting)
if patch.Image != "" {
Expand Down Expand Up @@ -728,6 +732,19 @@ func applyAttrPatch(attr *PodAttr, setting *JfsSetting) {
attr.VolumeMounts = patch.VolumeMounts
attr.Volumes = patch.Volumes
attr.Env = patch.Env

// merge or overwrite setting options
if setting.Options == nil {
setting.Options = make([]string, 0)
}
for _, option := range patch.MountOptions {
for i, o := range setting.Options {
if strings.Split(o, "=")[0] == option {
setting.Options = append(setting.Options[:i], setting.Options[i+1:]...)
}
}
setting.Options = append(setting.Options, option)
}
}

// IsCEMountPod check if the pod is a mount pod of CE
Expand Down

0 comments on commit 1b9d295

Please sign in to comment.