From a2c71bec4f9fa6bba28ef5eeaff768720f99461d Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Tue, 3 Nov 2020 11:19:26 -0800 Subject: [PATCH] Respect --data-dir path for crictl.yaml Related to rancher/rke2#474 Note that anyone who customizes the data-dir path will have to set CRI_CONFIG_FILE to the correct path when using the wrapped binaries (crictl, etc). This is better than dropping files in the incorrect location. Signed-off-by: Brad Davidson --- pkg/agent/run.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/agent/run.go b/pkg/agent/run.go index b028df6f19a6..ee6e7864ccea 100644 --- a/pkg/agent/run.go +++ b/pkg/agent/run.go @@ -21,7 +21,6 @@ import ( "github.com/rancher/k3s/pkg/clientaccess" "github.com/rancher/k3s/pkg/daemons/agent" daemonconfig "github.com/rancher/k3s/pkg/daemons/config" - "github.com/rancher/k3s/pkg/datadir" "github.com/rancher/k3s/pkg/nodeconfig" "github.com/rancher/k3s/pkg/rootless" "github.com/rancher/k3s/pkg/version" @@ -58,9 +57,9 @@ func setupCriCtlConfig(cfg cmds.Agent, nodeConfig *daemonconfig.Node) error { } } - agentConfDir := datadir.DefaultDataDir + "/agent/etc" + agentConfDir := filepath.Join(cfg.DataDir, "agent", "etc") if _, err := os.Stat(agentConfDir); os.IsNotExist(err) { - if err := os.MkdirAll(agentConfDir, 0755); err != nil { + if err := os.MkdirAll(agentConfDir, 0700); err != nil { return err } } @@ -141,12 +140,12 @@ func Run(ctx context.Context, cfg cmds.Agent) error { } } - cfg.DataDir = filepath.Join(cfg.DataDir, "agent") - if err := os.MkdirAll(cfg.DataDir, 0700); err != nil { + agentDir := filepath.Join(cfg.DataDir, "agent") + if err := os.MkdirAll(agentDir, 0700); err != nil { return err } - proxy, err := proxy.NewAPIProxy(!cfg.DisableLoadBalancer, cfg.DataDir, cfg.ServerURL) + proxy, err := proxy.NewAPIProxy(!cfg.DisableLoadBalancer, agentDir, cfg.ServerURL) if err != nil { return err }