Skip to content

K3s does not respect data-dir set via config file drop-in, or via env var #10589

@brandond

Description

@brandond
  1. The multicall wrapper script does not honor config file drop-ins for the --data-dir flag. The flag will be found if set in the CLI args, or in /etc/rancher/k3s/config.yaml, but not if it is set in any file in /etc/rancher/k3s/config.yaml.d (or the equivalent drop-in dir if the --config flag is used to change the path to config.yaml).

  2. The K3S_DATA_DIR env var does not map to the --data-dir CLI flag. It probably should. The multicall wrapper sets the K3S_DATA_DIR env var when it runs wrapped commands, but it appears that this is no longer used for anything - as there are no references to it anywhere else in the code base:

    if err := os.Setenv(version.ProgramUpper+"_DATA_DIR", dir); err != nil {

To reproduce:

  • Install k3s with mkdir -p /etc/rancher/k3s; echo "data-dir: /k8s" >> /etc/rancher/k3s/config.yaml; curl -sL get.k3s.io | sh -s - server
    • note that data-dir is used
  • Install k3s with curl -sL get.k3s.io | sh -s - server --data-dir=/k8s
    • note that data-dir is used
  • Install k3s with mkdir -p /etc/rancher/k3s/config.yaml.d; echo "data-dir: /k8s" >> /etc/rancher/k3s/config.yaml.d/99-data-dir.yaml; curl -sL get.k3s.io | sh -s - server
    • note that data-dir is NOT used
  • Install k3s with curl -sL get.k3s.io | K3S_DATA_DIR=/k8s sh -s - server
    • note that data-dir is NOT used

Note that for the case where data-dir is set in /etc/rancher/k3s/config.yaml.d/, the value is PARTIALLY respected. The stage 2 k3s server command honors the setting, but the binaries and packaged manifests are extracted out to the default path by the stage 1 multicall wrapper.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

Done Issue

Relationships

None yet

Development

No branches or pull requests

Issue actions