Skip to content

Commit

Permalink
Introduce JUICEFS_IMMUTABLE, mount /etc/updatedb.conf only in mut…
Browse files Browse the repository at this point in the history
…able environments

In immutable environments, such as Talos Linux, most host directories are read-only.
As a result, for example, `FileOrCreate` for the `/etc/updatedb.conf` will fail to
create an empty file. This patch introduces `JUICEFS_IMMUTABLE` as a new environment
variable for both controller and node instances to handle these kinds of cases that
need special attention in immutable environments.
  • Loading branch information
twelho committed Jul 19, 2023
1 parent adaeed0 commit 03c6b11
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
9 changes: 9 additions & 0 deletions cmd/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"os"
"strconv"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -63,6 +64,14 @@ func parseControllerConfig() {
config.MountManager = false
config.ByProcess = false
}
if jfsImmutable := os.Getenv("JUICEFS_IMMUTABLE"); jfsImmutable != "" {
// check if running in an immutable environment
if immutable, err := strconv.ParseBool(jfsImmutable); err == nil {
config.Immutable = immutable
} else {
klog.Errorf("cannot parse JUICEFS_IMMUTABLE: %v", err)
}
}

config.NodeName = os.Getenv("NODE_NAME")
config.Namespace = os.Getenv("JUICEFS_MOUNT_NAMESPACE")
Expand Down
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 jfsImmutable := os.Getenv("JUICEFS_IMMUTABLE"); jfsImmutable != "" {
if immutable, err := strconv.ParseBool(jfsImmutable); err == nil {
config.Immutable = immutable
} else {
klog.Errorf("cannot parse JUICEFS_IMMUTABLE: %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
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
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)
Immutable = false // csi driver is running in an immutable environment

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.Immutable {
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.Immutable {
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 03c6b11

Please sign in to comment.