2022-03-02 23:47:27 +00:00
|
|
|
//go:build linux
|
2021-06-10 19:27:00 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2022-03-02 23:47:27 +00:00
|
|
|
"github.com/k3s-io/k3s/pkg/cli/cmds"
|
|
|
|
"github.com/k3s-io/k3s/pkg/daemons/config"
|
2021-06-10 19:27:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-12-16 20:00:40 +00:00
|
|
|
criDockerdSock = "unix:///run/k3s/cri-dockerd/cri-dockerd.sock"
|
2021-06-10 19:27:00 +00:00
|
|
|
containerdSock = "unix:///run/k3s/containerd/containerd.sock"
|
|
|
|
)
|
|
|
|
|
|
|
|
// setupCriCtlConfig creates the crictl config file and populates it
|
|
|
|
// with the given data from config.
|
|
|
|
func setupCriCtlConfig(cfg cmds.Agent, nodeConfig *config.Node) error {
|
|
|
|
cre := nodeConfig.ContainerRuntimeEndpoint
|
|
|
|
if cre == "" {
|
2022-07-28 19:32:15 +00:00
|
|
|
switch {
|
|
|
|
case cfg.Docker:
|
2021-12-16 20:00:40 +00:00
|
|
|
cre = criDockerdSock
|
2022-07-28 19:32:15 +00:00
|
|
|
default:
|
|
|
|
cre = containerdSock
|
|
|
|
}
|
2021-06-10 19:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
agentConfDir := filepath.Join(cfg.DataDir, "agent", "etc")
|
|
|
|
if _, err := os.Stat(agentConfDir); os.IsNotExist(err) {
|
|
|
|
if err := os.MkdirAll(agentConfDir, 0700); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
crp := "runtime-endpoint: " + cre + "\n"
|
2023-09-27 20:20:50 +00:00
|
|
|
ise := nodeConfig.ImageServiceEndpoint
|
|
|
|
if ise != "" && ise != cre {
|
|
|
|
crp += "image-endpoint: " + cre + "\n"
|
|
|
|
}
|
2022-10-08 00:36:57 +00:00
|
|
|
return os.WriteFile(agentConfDir+"/crictl.yaml", []byte(crp), 0600)
|
2021-06-10 19:27:00 +00:00
|
|
|
}
|