Skip to content

Commit

Permalink
Control mounting of /etc/updatedb.conf with JUICEFS_MODIFY_UPDATEDB
Browse files Browse the repository at this point in the history
  • Loading branch information
twelho committed Jul 14, 2023
1 parent adaeed0 commit c873948
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
11 changes: 11 additions & 0 deletions cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"os"
"strconv"
"time"

"k8s.io/klog"
Expand All @@ -42,12 +43,22 @@ func parseNodeConfig() {
return
}
config.FormatInPod = formatInPod

if modifyUpdateDB := os.Getenv("JUICEFS_MODIFY_UPDATEDB"); modifyUpdateDB != "" {
if mountUpdateDBCfg, err := strconv.ParseBool(modifyUpdateDB); err == nil {
config.MountUpdateDBCfg = mountUpdateDBCfg
} else {
klog.Errorf("cannot parse JUICEFS_MODIFY_UPDATEDB: %v", err)
}
}

config.NodeName = os.Getenv("NODE_NAME")
config.Namespace = os.Getenv("JUICEFS_MOUNT_NAMESPACE")
config.PodName = os.Getenv("POD_NAME")
config.MountPointPath = os.Getenv("JUICEFS_MOUNT_PATH")
config.JFSConfigPath = os.Getenv("JUICEFS_CONFIG_PATH")
config.MountLabels = os.Getenv("JUICEFS_MOUNT_LABELS")

config.HostIp = os.Getenv("HOST_IP")
config.KubeletPort = os.Getenv("KUBELET_PORT")
jfsMountPriorityName := os.Getenv("JUICEFS_MOUNT_PRIORITY_NAME")
Expand Down
11 changes: 6 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import (
)

var (
ByProcess = false // csi driver runs juicefs in process or not
FormatInPod = false // put format/auth in pod (only in k8s)
Provisioner = false // provisioner in controller
MountManager = false // manage mount pod in controller (only in k8s)
Webhook = false // inject juicefs client as sidecar in pod (only in k8s)
ByProcess = false // csi driver runs juicefs in process or not
FormatInPod = false // put format/auth in pod (only in k8s)
Provisioner = false // provisioner in controller
MountManager = false // manage mount pod in controller (only in k8s)
Webhook = false // inject juicefs client as sidecar in pod (only in k8s)
MountUpdateDBCfg = true // mount updatedb.cfg in the mount pods

NodeName = ""
Namespace = ""
Expand Down
33 changes: 22 additions & 11 deletions pkg/juicefs/mount/builder/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
JfsDirName = "jfs-dir"
JfsRootDirName = "jfs-root-dir"
UpdateDBDirName = "updatedb"
UpdateDBCfgFile = "/etc/updatedb.conf"
)

type Builder struct {
Expand Down Expand Up @@ -92,15 +93,20 @@ func (r *Builder) getVolumes() []corev1.Volume {
Path: config.MountPointPath,
Type: &dir,
},
}}, {
Name: UpdateDBDirName,
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/etc/updatedb.conf",
Type: &file,
},
},
}}

if config.MountUpdateDBCfg {
volumes = append(volumes, corev1.Volume{
Name: UpdateDBDirName,
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: UpdateDBCfgFile,
Type: &file,
},
}})
}

if r.jfsSetting.FormatCmd != "" {
// initContainer will generate xx.conf to share with mount container
volumes = append(volumes, corev1.Volume{
Expand Down Expand Up @@ -157,11 +163,16 @@ func (r *Builder) getVolumeMounts() []corev1.VolumeMount {
Name: JfsDirName,
MountPath: config.PodMountBase,
MountPropagation: &mp,
}, {
Name: UpdateDBDirName,
MountPath: "/etc/updatedb.conf",
MountPropagation: &mp,
}}

if config.MountUpdateDBCfg {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: UpdateDBDirName,
MountPath: UpdateDBCfgFile,
MountPropagation: &mp,
})
}

if r.jfsSetting.FormatCmd != "" {
// initContainer will generate xx.conf to share with mount container
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Expand Down
4 changes: 2 additions & 2 deletions pkg/juicefs/mount/builder/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var (
Name: UpdateDBDirName,
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/etc/updatedb.conf",
Path: UpdateDBCfgFile,
Type: &file,
},
},
Expand Down Expand Up @@ -107,7 +107,7 @@ var (
}, {

Name: UpdateDBDirName,
MountPath: "/etc/updatedb.conf",
MountPath: UpdateDBCfgFile,
MountPropagation: &mp,
},
},
Expand Down

0 comments on commit c873948

Please sign in to comment.