2022-03-02 23:47:27 +00:00
|
|
|
//go:build windows
|
2021-06-10 19:27:00 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2022-07-28 19:32:15 +00:00
|
|
|
"strings"
|
2021-06-10 19:27:00 +00:00
|
|
|
|
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 (
|
2022-07-28 19:32:15 +00:00
|
|
|
dockershimSock = "npipe:////./pipe/docker_engine"
|
2021-06-10 19:27:00 +00:00
|
|
|
containerdSock = "npipe:////./pipe/containerd-containerd"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2022-07-28 19:32:15 +00:00
|
|
|
if cre == "" || strings.HasPrefix(cre, "npipe:") {
|
|
|
|
switch {
|
|
|
|
case cfg.Docker:
|
|
|
|
cre = dockershimSock
|
|
|
|
default:
|
|
|
|
cre = containerdSock
|
|
|
|
}
|
|
|
|
} else {
|
2021-06-10 19:27:00 +00:00
|
|
|
cre = containerdSock
|
|
|
|
}
|
|
|
|
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"
|
2022-10-08 00:36:57 +00:00
|
|
|
return os.WriteFile(filepath.Join(agentConfDir, "crictl.yaml"), []byte(crp), 0600)
|
2021-06-10 19:27:00 +00:00
|
|
|
}
|