Skip to content

Commit

Permalink
Extract volume mount options for ThinRuntime fuse container (fluid-cl…
Browse files Browse the repository at this point in the history
…oudnative#2456)

* BUGFIX: fix remaining runtime set configmap after deletion

Signed-off-by: dongyun.xzh <[email protected]>

* Extract mount options from pv

Signed-off-by: dongyun.xzh <[email protected]>

Signed-off-by: dongyun.xzh <[email protected]>
  • Loading branch information
TrafalgarZZZ authored Dec 20, 2022
1 parent cd76897 commit f6ed38c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
3 changes: 0 additions & 3 deletions charts/thin/templates/config/runtime.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
"helm.sh/hook": "pre-install"
"helm.sh/hook-delete-policy": before-hook-creation
name: {{ template "thin.fullname" . }}-runtimeset
labels:
app: {{ template "thin.name" . }}
Expand Down
31 changes: 26 additions & 5 deletions pkg/ddc/thin/transform_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ func (t *ThinEngine) transformConfig(runtime *datav1alpha1.ThinRuntime,
mounts := []datav1alpha1.Mount{}
// todo: support passing flexVolume info
pvAttributes := map[string]*corev1.CSIPersistentVolumeSource{}
pvMountOptions := map[string][]string{}
for _, m := range dataset.Spec.Mounts {
if strings.HasPrefix(m.MountPoint, common.VolumeScheme.String()) {
pvcName := strings.TrimPrefix(m.MountPoint, common.VolumeScheme.String())
csiInfo, err := t.extractCSIVolumeSourceInfo(pvcName)
csiInfo, mountOptions, err := t.extractVolumeInfo(pvcName)
if err != nil {
return config, err
}

pvAttributes[pvcName] = csiInfo
pvMountOptions[pvcName] = mountOptions
}

m.Options, err = t.genUFSMountOptions(m)
Expand All @@ -56,10 +58,11 @@ func (t *ThinEngine) transformConfig(runtime *datav1alpha1.ThinRuntime,
config.RuntimeOptions = runtime.Spec.Fuse.Options
config.TargetPath = targetPath
config.PersistentVolumeAttrs = pvAttributes
config.PersistentVolumeMountOptions = pvMountOptions
return
}

func (t *ThinEngine) extractCSIVolumeSourceInfo(pvcName string) (csiInfo *corev1.CSIPersistentVolumeSource, err error) {
func (t *ThinEngine) extractVolumeInfo(pvcName string) (csiInfo *corev1.CSIPersistentVolumeSource, mountOptions []string, err error) {
pvc, err := kubeclient.GetPersistentVolumeClaim(t.Client, pvcName, t.namespace)
if err != nil {
return
Expand All @@ -75,12 +78,30 @@ func (t *ThinEngine) extractCSIVolumeSourceInfo(pvcName string) (csiInfo *corev1
return
}

if pv.Spec.CSI == nil {
err = fmt.Errorf("persistent volume %s has unsupported volume source. only CSI is supported", pv.Name)
if pv.Spec.CSI != nil {
csiInfo = pv.Spec.CSI
}

mountOptions, err = t.extractVolumeMountOptions(pv)
if err != nil {
return
}

return pv.Spec.CSI, nil
return
}

func (t *ThinEngine) extractVolumeMountOptions(pv *corev1.PersistentVolume) (mountOptions []string, err error) {
if len(pv.Spec.MountOptions) != 0 {
return pv.Spec.MountOptions, nil
}

// fallback to check "volume.beta.kubernetes.io/mount-options", see https://kubernetes.io/docs/concepts/storage/persistent-volumes/#mount-options
// e.g. volume.beta.kubernetes.io/mount-options: rw,nfsvers=4,noexec
if opts, exists := pv.Annotations[corev1.MountOptionAnnotation]; exists {
return strings.Split(opts, ","), nil
}

return
}

func (t *ThinEngine) toRuntimeSetConfig(workers []string, fuses []string) (result string, err error) {
Expand Down
9 changes: 5 additions & 4 deletions pkg/ddc/thin/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ type Fuse struct {
}

type Config struct {
Mounts []datav1alpha1.Mount `json:"mounts,omitempty"`
TargetPath string `json:"targetPath,omitempty"`
RuntimeOptions map[string]string `json:"runtimeOptions,omitempty"`
PersistentVolumeAttrs map[string]*corev1.CSIPersistentVolumeSource `json:"persistentVolumeAttrs,omitempty"`
Mounts []datav1alpha1.Mount `json:"mounts,omitempty"`
TargetPath string `json:"targetPath,omitempty"`
RuntimeOptions map[string]string `json:"runtimeOptions,omitempty"`
PersistentVolumeAttrs map[string]*corev1.CSIPersistentVolumeSource `json:"persistentVolumeAttrs,omitempty"`
PersistentVolumeMountOptions map[string][]string `json:"persistentVolumeMountOptions,omitempty"`
}

// RuntimeSetConfig is with the info of the workers and fuses
Expand Down

0 comments on commit f6ed38c

Please sign in to comment.