Skip to content

Commit

Permalink
support juicefs in serverless (fluid-cloudnative#1427)
Browse files Browse the repository at this point in the history
Signed-off-by: zwwhdls <[email protected]>
  • Loading branch information
zwwhdls committed Mar 18, 2022
1 parent 3810f2c commit fffba9f
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 111 deletions.
6 changes: 3 additions & 3 deletions api/v1alpha1/juicefsruntime_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ type JuiceFSFuseSpec struct {
Image string `json:"image,omitempty"`

// Image for JuiceFS fuse
ImageTag string `json:"image_tag,omitempty"`
ImageTag string `json:"imageTag,omitempty"`

// One of the three policies: `Always`, `IfNotPresent`, `Never`
ImagePullPolicy string `json:"image_pull_policy,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`

// Environment variables that will be used by JuiceFS Fuse
Env []corev1.EnvVar `json:"env,omitempty"`
Expand All @@ -115,7 +115,7 @@ type JuiceFSFuseSpec struct {
// NodeSelector is a selector which must be true for the fuse client to fit on a node,
// this option only effect when global is enabled
// +optional
NodeSelector map[string]string `json:"node_selector,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// CleanPolicy decides when to clean Juicefs Fuse pods.
// Currently Fluid supports two policies: OnDemand and OnRuntimeDeleted
Expand Down
11 changes: 8 additions & 3 deletions charts/fluid/fluid/crds/data.fluid.io_juicefsruntimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ spec:
image:
description: Image for JuiceFS fuse
type: string
image_pull_policy:
imagePullPolicy:
description: 'One of the three policies: `Always`, `IfNotPresent`,
`Never`'
type: string
image_tag:
imageTag:
description: Image for JuiceFS fuse
type: string
node_selector:
nodeSelector:
additionalProperties:
type: string
description: NodeSelector is a selector which must be true for
Expand Down Expand Up @@ -1082,6 +1082,11 @@ spec:
masterReason:
description: Reason for Master's condition transition
type: string
mountTime:
description: MountTime represents time last mount happened if Mounttime
is early than master starting time, remount will be required
format: date-time
type: string
selector:
description: Selector is used for auto-scaling
type: string
Expand Down
97 changes: 34 additions & 63 deletions charts/juicefs/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,6 @@ spec:
tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
{{- end }}
initContainers:
- name: prepare
image: {{ .Values.fuse.image }}:{{ .Values.fuse.imageTag }}
imagePullPolicy: {{ .Values.fuse.imagePullPolicy }}
command:
- sh
- -c
- "sh /root/prepare/prepare-subpath.sh"
securityContext:
privileged: true
env:
{{- if .Values.fuse.envs }}
{{ toYaml .Values.fuse.envs | trim | indent 10 }}
{{- end }}
{{- if .Values.fuse.prepare.metaurlSecret }}
- name: METAURL
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.prepare.metaurlSecret }}
key: metaurl
{{- end }}
{{- if .Values.fuse.prepare.accesskeySecret }}
- name: ACCESS_KEY
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.prepare.accesskeySecret }}
key: access-key
{{- end }}
{{- if .Values.fuse.prepare.secretkeySecret }}
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.prepare.secretkeySecret }}
key: secret-key
{{- end }}
volumeMounts:
- mountPath: /root/.juicefs
mountPropagation: Bidirectional
name: jfs-root-dir
- mountPath: /root/prepare
name: prepare
containers:
- name: juicefs-fuse
image: {{ .Values.fuse.image }}:{{ .Values.fuse.imageTag }}
Expand All @@ -98,15 +57,34 @@ spec:
memory: {{ .Values.fuse.resources.requests.memory }}
{{- end }}
{{- end }}
{{- if .Values.fuse.command }}
command: ["sh", "-c", "{{ .Values.fuse.command }}"]
{{- end }}
command: ["sh", "/root/script/script.sh"]
env:
- name: JFS_FOREGROUND
value: "1"
{{- if .Values.fuse.envs }}
{{ toYaml .Values.fuse.envs | trim | indent 10 }}
{{- end }}
{{- if .Values.fuse.metaurlSecret }}
- name: METAURL
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.metaurlSecret }}
key: metaurl
{{- end }}
{{- if .Values.fuse.accesskeySecret }}
- name: ACCESS_KEY
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.accesskeySecret }}
key: access-key
{{- end }}
{{- if .Values.fuse.secretkeySecret }}
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.secretkeySecret }}
key: secret-key
{{- end }}
readinessProbe:
exec:
command:
Expand All @@ -129,19 +107,18 @@ spec:
exec:
command: ["sh", "-c", "umount {{ .Values.fuse.mountPath }}"]
volumeMounts:
- name: jfs-dir
- name: juicefs-fuse-mount
mountPath: {{ .Values.fuse.hostMountPath }}
mountPropagation: Bidirectional
- mountPath: /root/.juicefs
mountPropagation: Bidirectional
name: jfs-root-dir
- mountPath: /root/script
name: script
{{- if .Values.fuse.cacheDir }}
- name: cache-dir
mountPath: {{ .Values.fuse.cacheDir }}
{{- end }}
restartPolicy: Always
volumes:
- name: jfs-dir
- name: juicefs-fuse-mount
hostPath:
path: {{ .Values.fuse.hostMountPath }}
type: DirectoryOrCreate
Expand All @@ -151,36 +128,30 @@ spec:
path: {{ .Values.fuse.cacheDir }}
type: DirectoryOrCreate
{{- end }}
- name: jfs-root-dir
emptyDir: {}
- name: prepare
- name: script
configMap:
name: {{ template "juicefs.fullname" . }}-prepare
name: {{ template "juicefs.fullname" . }}-script
defaultMode: 0777
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "juicefs.fullname" . }}-prepare
name: {{ template "juicefs.fullname" . }}-script
labels:
app: {{ template "juicefs.name" . }}
chart: {{ template "juicefs.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
prepare-subpath.sh: |
script.sh: |
#!/bin/bash
{{- if and .Values.fuse.prepare.storage .Values.fuse.prepare.bucket .Values.fuse.prepare.accesskeySecret .Values.fuse.prepare.secretkeySecret }}
/usr/local/bin/juicefs format --storage={{ .Values.fuse.prepare.storage }} --bucket={{ .Values.fuse.prepare.bucket }} --access-key=${ACCESS_KEY} --secret-key=${SECRET_KEY} ${METAURL} {{ .Values.fuse.prepare.name }}
{{- if and .Values.fuse.storage .Values.fuse.bucket .Values.fuse.accesskeySecret .Values.fuse.secretkeySecret }}
/usr/local/bin/juicefs format --storage={{ .Values.fuse.storage }} --bucket={{ .Values.fuse.bucket }} --access-key=${ACCESS_KEY} --secret-key=${SECRET_KEY} ${METAURL} {{ .Values.fuse.name }}
{{- else }}
/usr/local/bin/juicefs format ${METAURL} {{ .Values.fuse.prepare.name }} --no-update
/usr/local/bin/juicefs format ${METAURL} {{ .Values.fuse.name }} --no-update
{{- end }}
/usr/local/bin/juicefs mount -d ${METAURL} /mnt/jfs
if [ ! -d /mnt/jfs{{ .Values.fuse.prepare.subPath }} ]; then
mkdir /mnt/jfs{{ .Values.fuse.prepare.subPath }}
fi;
umount /mnt/jfs
{{ .Values.fuse.command }}
{{- end }}
15 changes: 7 additions & 8 deletions charts/juicefs/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ worker:
## FUSE ##

fuse:
prepare:
name: ""
accesskeySecret: ""
secretkeySecret: ""
bucket: ""
metaurlSecret: ""
storage: ""
subPath: ""
name: ""
accesskeySecret: ""
secretkeySecret: ""
bucket: ""
metaurlSecret: ""
storage: ""
subPath: ""
criticalPod: false
enabled: true
image: juicedata/juicefs-csi-driver
Expand Down
11 changes: 8 additions & 3 deletions config/crd/bases/data.fluid.io_juicefsruntimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ spec:
image:
description: Image for JuiceFS fuse
type: string
image_pull_policy:
imagePullPolicy:
description: 'One of the three policies: `Always`, `IfNotPresent`,
`Never`'
type: string
image_tag:
imageTag:
description: Image for JuiceFS fuse
type: string
node_selector:
nodeSelector:
additionalProperties:
type: string
description: NodeSelector is a selector which must be true for
Expand Down Expand Up @@ -1082,6 +1082,11 @@ spec:
masterReason:
description: Reason for Master's condition transition
type: string
mountTime:
description: MountTime represents time last mount happened if Mounttime
is early than master starting time, remount will be required
format: date-time
type: string
selector:
description: Selector is used for auto-scaling
type: string
Expand Down
15 changes: 7 additions & 8 deletions pkg/ddc/juicefs/transform_fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,22 @@ import (

func (j *JuiceFSEngine) transformFuse(runtime *datav1alpha1.JuiceFSRuntime, dataset *datav1alpha1.Dataset, value *JuiceFS) (err error) {
value.Fuse = Fuse{}
value.Fuse.Prepare = Prepare{}

if len(dataset.Spec.Mounts) <= 0 {
return errors.New("do not assign mount point")
}
mount := dataset.Spec.Mounts[0]

value.Fuse.Prepare.Name = mount.Name
value.Fuse.Name = mount.Name
opts := make(map[string]string)
source := ""
for k, v := range mount.Options {
switch k {
case JuiceStorage:
value.Fuse.Prepare.Storage = v
value.Fuse.Storage = v
continue
case JuiceBucket:
value.Fuse.Prepare.Bucket = v
value.Fuse.Bucket = v
continue
default:
opts[k] = v
Expand All @@ -64,16 +63,16 @@ func (j *JuiceFSEngine) transformFuse(runtime *datav1alpha1.JuiceFSRuntime, data

switch key {
case JuiceMetaUrl:
value.Fuse.Prepare.MetaUrlSecret = secretKeyRef.Name
value.Fuse.MetaUrlSecret = secretKeyRef.Name
v, ok := secret.Data[secretKeyRef.Key]
if !ok {
return fmt.Errorf("can't get metaurl from secret %s", secret.Name)
}
source = string(v)
case JuiceAccessKey:
value.Fuse.Prepare.AccessKeySecret = secretKeyRef.Name
value.Fuse.AccessKeySecret = secretKeyRef.Name
case JuiceSecretKey:
value.Fuse.Prepare.SecretKeySecret = secretKeyRef.Name
value.Fuse.SecretKeySecret = secretKeyRef.Name
}
}

Expand All @@ -96,7 +95,7 @@ func (j *JuiceFSEngine) transformFuse(runtime *datav1alpha1.JuiceFSRuntime, data
value.Fuse.MountPath = j.getMountPoint()
value.Fuse.NodeSelector = map[string]string{}
value.Fuse.HostMountPath = j.getHostMountPoint()
value.Fuse.Prepare.SubPath = subPath
value.Fuse.SubPath = subPath
value.Fuse.Envs = runtime.Spec.Fuse.Env

mountArgs := []string{common.JuiceFSMountPath, source, value.Fuse.MountPath}
Expand Down
18 changes: 7 additions & 11 deletions pkg/ddc/juicefs/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ type Worker struct {
}

type Fuse struct {
Prepare Prepare `yaml:"prepare,omitempty"`
SubPath string `yaml:"subPath,omitempty"`
Name string `yaml:"name"`
AccessKeySecret string `yaml:"accesskeySecret,omitempty"`
SecretKeySecret string `yaml:"secretkeySecret,omitempty"`
Bucket string `yaml:"bucket,omitempty"`
MetaUrlSecret string `yaml:"metaurlSecret,omitempty"`
Storage string `yaml:"storage,omitempty"`
Image string `yaml:"image,omitempty"`
NodeSelector map[string]string `yaml:"nodeSelector,omitempty"`
Envs []corev1.EnvVar `yaml:"envs,omitempty"`
Expand All @@ -63,16 +69,6 @@ type Fuse struct {
CriticalPod bool `yaml:"criticalPod,omitempty"`
}

type Prepare struct {
SubPath string `yaml:"subPath,omitempty"`
Name string `yaml:"name"`
AccessKeySecret string `yaml:"accesskeySecret,omitempty"`
SecretKeySecret string `yaml:"secretkeySecret,omitempty"`
Bucket string `yaml:"bucket,omitempty"`
MetaUrlSecret string `yaml:"metaurlSecret,omitempty"`
Storage string `yaml:"storage,omitempty"`
}

type TieredStore struct {
Path string `yaml:"path,omitempty"`
Quota string `yaml:"quota,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/scripts/poststart/check_fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (f *ScriptGeneratorForFuse) BuildConfigmap(ownerReference metav1.OwnerRefer
}

func (f *ScriptGeneratorForFuse) getConfigmapName() string {
return f.name + "-" + f.mountType + "-" + configMapName
return f.name + "-" + strings.ToLower(f.mountType) + "-" + configMapName
}

func (f *ScriptGeneratorForFuse) GetPostStartCommand() (handler *corev1.Handler) {
Expand Down
Loading

0 comments on commit fffba9f

Please sign in to comment.