k3s/pkg/agent/cridockerd/config_linux.go
Brad Davidson 4aca21a1f1 Add cri-dockerd support as backend for --docker flag
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2022-08-05 02:39:25 -07:00

40 lines
1.1 KiB
Go

//go:build linux
// +build linux
package cridockerd
import (
"context"
"strings"
"github.com/docker/docker/client"
"github.com/k3s-io/k3s/pkg/daemons/config"
"github.com/pkg/errors"
)
const socketPrefix = "unix://"
func setupDockerCRIConfig(ctx context.Context, cfg *config.Node) error {
clientOpts := []client.Opt{client.FromEnv, client.WithAPIVersionNegotiation()}
if cfg.ContainerRuntimeEndpoint != "" {
host := cfg.ContainerRuntimeEndpoint
if !strings.HasPrefix(host, socketPrefix) {
host = socketPrefix + host
}
clientOpts = append(clientOpts, client.WithHost(host))
}
c, err := client.NewClientWithOpts(clientOpts...)
if err != nil {
return errors.Wrap(err, "failed to create docker client")
}
i, err := c.Info(ctx)
if err != nil {
return errors.Wrap(err, "failed to get docker runtime info")
}
// note: this mutatation of the passed agent.Config is later used to set the
// kubelet's cgroup-driver flag. This may merit moving to somewhere else in order
// to avoid mutating the configuration while setting up the docker CRI.
cfg.AgentConfig.Systemd = i.CgroupDriver == "systemd"
return nil
}