2023-01-17 20:11:50 +00:00
|
|
|
//go:build !no_cri_dockerd
|
|
|
|
// +build !no_cri_dockerd
|
|
|
|
|
2021-12-16 20:00:40 +00:00
|
|
|
package cridockerd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"runtime/debug"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/Mirantis/cri-dockerd/cmd"
|
2023-01-21 01:31:16 +00:00
|
|
|
"github.com/Mirantis/cri-dockerd/cmd/version"
|
2023-01-27 21:16:59 +00:00
|
|
|
|
|
|
|
"github.com/k3s-io/k3s/pkg/agent/cri"
|
2021-12-16 20:00:40 +00:00
|
|
|
"github.com/k3s-io/k3s/pkg/cgroups"
|
|
|
|
"github.com/k3s-io/k3s/pkg/daemons/config"
|
|
|
|
"github.com/sirupsen/logrus"
|
2023-01-27 21:16:59 +00:00
|
|
|
|
2021-12-16 20:00:40 +00:00
|
|
|
utilsnet "k8s.io/utils/net"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Run(ctx context.Context, cfg *config.Node) error {
|
|
|
|
if err := setupDockerCRIConfig(ctx, cfg); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
args := getDockerCRIArgs(cfg)
|
|
|
|
command := cmd.NewDockerCRICommand(ctx.Done())
|
|
|
|
command.SetArgs(args)
|
|
|
|
logrus.Infof("Running cri-dockerd %s", config.ArgString(args))
|
2023-01-21 01:31:16 +00:00
|
|
|
logrus.Infof("cri-dockerd version %s", version.FullVersion())
|
2021-12-16 20:00:40 +00:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
2023-04-21 19:44:08 +00:00
|
|
|
logrus.WithField("stack", string(debug.Stack())).Fatalf("cri-dockerd panic: %v", err)
|
2021-12-16 20:00:40 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
logrus.Fatalf("cri-dockerd exited: %v", command.ExecuteContext(ctx))
|
|
|
|
}()
|
|
|
|
|
2023-01-27 21:16:59 +00:00
|
|
|
return cri.WaitForService(ctx, cfg.CRIDockerd.Address, "cri-dockerd")
|
2021-12-16 20:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getDockerCRIArgs(cfg *config.Node) []string {
|
|
|
|
argsMap := map[string]string{
|
|
|
|
"container-runtime-endpoint": cfg.CRIDockerd.Address,
|
|
|
|
"cri-dockerd-root-directory": cfg.CRIDockerd.Root,
|
|
|
|
}
|
|
|
|
|
|
|
|
if dualNode, _ := utilsnet.IsDualStackIPs(cfg.AgentConfig.NodeIPs); dualNode {
|
|
|
|
argsMap["ipv6-dual-stack"] = "true"
|
|
|
|
}
|
|
|
|
|
|
|
|
if logLevel := os.Getenv("CRIDOCKERD_LOG_LEVEL"); logLevel != "" {
|
|
|
|
argsMap["log-level"] = logLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.ContainerRuntimeEndpoint != "" {
|
|
|
|
endpoint := cfg.ContainerRuntimeEndpoint
|
|
|
|
if !strings.HasPrefix(endpoint, socketPrefix) {
|
|
|
|
endpoint = socketPrefix + endpoint
|
|
|
|
}
|
|
|
|
argsMap["docker-endpoint"] = endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.AgentConfig.CNIConfDir != "" {
|
|
|
|
argsMap["cni-conf-dir"] = cfg.AgentConfig.CNIConfDir
|
|
|
|
}
|
|
|
|
if cfg.AgentConfig.CNIBinDir != "" {
|
|
|
|
argsMap["cni-bin-dir"] = cfg.AgentConfig.CNIBinDir
|
|
|
|
}
|
|
|
|
if cfg.AgentConfig.CNIPlugin {
|
|
|
|
argsMap["network-plugin"] = "cni"
|
|
|
|
}
|
|
|
|
if cfg.AgentConfig.PauseImage != "" {
|
|
|
|
argsMap["pod-infra-container-image"] = cfg.AgentConfig.PauseImage
|
|
|
|
}
|
|
|
|
|
|
|
|
_, runtimeRoot, _ := cgroups.CheckCgroups()
|
|
|
|
if runtimeRoot != "" {
|
|
|
|
argsMap["runtime-cgroups"] = runtimeRoot
|
|
|
|
}
|
|
|
|
|
|
|
|
return config.GetArgs(argsMap, nil)
|
|
|
|
}
|