mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
89f7062431
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
//go:build linux && !no_cri_dockerd
|
|
// +build linux,!no_cri_dockerd
|
|
|
|
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
|
|
}
|