2021-06-01 19:29:46 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package containerd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-06-10 19:27:00 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"time"
|
2021-06-01 19:29:46 +00:00
|
|
|
|
2021-06-10 19:27:00 +00:00
|
|
|
"github.com/rancher/k3s/pkg/agent/templates"
|
|
|
|
util2 "github.com/rancher/k3s/pkg/agent/util"
|
2021-06-01 19:29:46 +00:00
|
|
|
"github.com/rancher/k3s/pkg/daemons/config"
|
2021-06-10 19:27:00 +00:00
|
|
|
"github.com/rancher/wharfie/pkg/registries"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
|
|
|
"k8s.io/kubernetes/pkg/kubelet/util"
|
2021-06-01 19:29:46 +00:00
|
|
|
)
|
|
|
|
|
2021-06-10 19:27:00 +00:00
|
|
|
func getContainerdArgs(cfg *config.Node) []string {
|
|
|
|
args := []string{
|
|
|
|
"containerd",
|
|
|
|
"-c", cfg.Containerd.Config,
|
|
|
|
}
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
2021-06-01 19:29:46 +00:00
|
|
|
// setupContainerdConfig generates the containerd.toml, using a template combined with various
|
|
|
|
// runtime configurations and registry mirror settings provided by the administrator.
|
|
|
|
func setupContainerdConfig(ctx context.Context, cfg *config.Node) error {
|
2021-06-10 19:27:00 +00:00
|
|
|
privRegistries, err := registries.GetPrivateRegistries(cfg.AgentConfig.PrivateRegistry)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.SELinux {
|
|
|
|
logrus.Warn("SELinux isn't supported on windows")
|
|
|
|
}
|
|
|
|
|
|
|
|
var containerdTemplate string
|
|
|
|
|
|
|
|
containerdConfig := templates.ContainerdConfig{
|
|
|
|
NodeConfig: cfg,
|
|
|
|
DisableCgroup: true,
|
|
|
|
IsRunningInUserNS: false,
|
|
|
|
PrivateRegistryConfig: privRegistries.Registry(),
|
|
|
|
}
|
|
|
|
|
|
|
|
containerdTemplateBytes, err := ioutil.ReadFile(cfg.Containerd.Template)
|
|
|
|
if err == nil {
|
|
|
|
logrus.Infof("Using containerd template at %s", cfg.Containerd.Template)
|
|
|
|
containerdTemplate = string(containerdTemplateBytes)
|
|
|
|
} else if os.IsNotExist(err) {
|
|
|
|
containerdTemplate = templates.ContainerdConfigTemplate
|
|
|
|
} else {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
parsedTemplate, err := templates.ParseTemplateFromConfig(containerdTemplate, containerdConfig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return util2.WriteFile(cfg.Containerd.Config, parsedTemplate)
|
|
|
|
}
|
|
|
|
|
|
|
|
// criConnection connects to a CRI socket at the given path.
|
|
|
|
func CriConnection(ctx context.Context, address string) (*grpc.ClientConn, error) {
|
|
|
|
addr, dialer, err := util.GetAddressAndDialer(address)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(3*time.Second), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
c := runtimeapi.NewRuntimeServiceClient(conn)
|
|
|
|
_, err = c.Version(ctx, &runtimeapi.VersionRequest{
|
|
|
|
Version: "0.1.0",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
conn.Close()
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return conn, nil
|
2021-06-01 19:29:46 +00:00
|
|
|
}
|