From dafcf1a159cb46e2483d94db70509899ee758277 Mon Sep 17 00:00:00 2001 From: Ciprian Hacman Date: Sun, 27 Dec 2020 14:36:19 +0200 Subject: [PATCH] Remove support for Kubenet with containerd --- cmd/kops/create_cluster.go | 3 ++ nodeup/pkg/model/containerd.go | 43 ------------------- .../tests/containerdbuilder/simple/tasks.yaml | 24 ----------- pkg/apis/kops/validation/validation.go | 3 ++ pkg/model/components/containerd.go | 20 +-------- 5 files changed, 7 insertions(+), 86 deletions(-) diff --git a/cmd/kops/create_cluster.go b/cmd/kops/create_cluster.go index 358db57ea2564..47d6bd2eba52c 100644 --- a/cmd/kops/create_cluster.go +++ b/cmd/kops/create_cluster.go @@ -488,6 +488,9 @@ func RunCreateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *Cr if c.ContainerRuntime != "" { cluster.Spec.ContainerRuntime = c.ContainerRuntime } + if cluster.Spec.ContainerRuntime == "containerd" && cluster.Spec.Networking.Kubenet != nil { + return fmt.Errorf("--networking with CNI plugin is required for containerd") + } if c.NetworkCIDR != "" { cluster.Spec.NetworkCIDR = c.NetworkCIDR diff --git a/nodeup/pkg/model/containerd.go b/nodeup/pkg/model/containerd.go index 7cfa8d465a4e4..8583e91e80896 100644 --- a/nodeup/pkg/model/containerd.go +++ b/nodeup/pkg/model/containerd.go @@ -27,7 +27,6 @@ import ( "k8s.io/kops/nodeup/pkg/model/resources" "k8s.io/kops/pkg/apis/kops" "k8s.io/kops/pkg/flagbuilder" - "k8s.io/kops/pkg/model/components" "k8s.io/kops/pkg/systemd" "k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi/nodeup/nodetasks" @@ -134,14 +133,6 @@ func (b *ContainerdBuilder) Build(c *fi.ModelBuilderContext) error { return err } - // Using containerd with Kubenet requires special configuration. This is a temporary backwards-compatible solution - // and will be deprecated when Kubenet is deprecated: - // https://github.com/containerd/cri/blob/master/docs/config.md#cni-config-template - usesKubenet := components.UsesKubenet(b.Cluster.Spec.Networking) - if b.Cluster.Spec.ContainerRuntime == "containerd" && usesKubenet { - b.buildKubenetCNIConfigTemplate(c) - } - return nil } @@ -259,40 +250,6 @@ func (b *ContainerdBuilder) buildSysconfig(c *fi.ModelBuilderContext) error { return nil } -// buildKubenetCNIConfigTemplate is responsible for creating a special template for setups using Kubenet -func (b *ContainerdBuilder) buildKubenetCNIConfigTemplate(c *fi.ModelBuilderContext) { - lines := []string{ - "{", - " \"cniVersion\": \"0.3.1\",", - " \"name\": \"kubenet\",", - " \"plugins\": [", - " {", - " \"type\": \"bridge\",", - " \"bridge\": \"cbr0\",", - " \"mtu\": 1460,", - " \"addIf\": \"eth0\",", - " \"isGateway\": true,", - " \"ipMasq\": true,", - " \"promiscMode\": true,", - " \"ipam\": {", - " \"type\": \"host-local\",", - " \"subnet\": \"{{.PodCIDR}}\",", - " \"routes\": [{ \"dst\": \"0.0.0.0/0\" }]", - " }", - " }", - " ]", - "}", - } - contents := strings.Join(lines, "\n") - klog.V(8).Infof("Built kubenet CNI config file\n%s", contents) - - c.AddTask(&nodetasks.File{ - Path: "/etc/containerd/cni-config.template", - Contents: fi.NewStringResource(contents), - Type: nodetasks.FileType_File, - }) -} - // skipInstall determines if kops should skip the installation and configuration of containerd func (b *ContainerdBuilder) skipInstall() bool { d := b.Cluster.Spec.Containerd diff --git a/nodeup/pkg/model/tests/containerdbuilder/simple/tasks.yaml b/nodeup/pkg/model/tests/containerdbuilder/simple/tasks.yaml index edea6ddd5cb78..3c2671e9f4de5 100644 --- a/nodeup/pkg/model/tests/containerdbuilder/simple/tasks.yaml +++ b/nodeup/pkg/model/tests/containerdbuilder/simple/tasks.yaml @@ -1,27 +1,3 @@ -contents: |- - { - "cniVersion": "0.3.1", - "name": "kubenet", - "plugins": [ - { - "type": "bridge", - "bridge": "cbr0", - "mtu": 1460, - "addIf": "eth0", - "isGateway": true, - "ipMasq": true, - "promiscMode": true, - "ipam": { - "type": "host-local", - "subnet": "{{.PodCIDR}}", - "routes": [{ "dst": "0.0.0.0/0" }] - } - } - ] - } -path: /etc/containerd/cni-config.template -type: file ---- contents: "" path: /etc/containerd/config-kops.toml type: file diff --git a/pkg/apis/kops/validation/validation.go b/pkg/apis/kops/validation/validation.go index f3dfe1e15b0ac..7438a301ed873 100644 --- a/pkg/apis/kops/validation/validation.go +++ b/pkg/apis/kops/validation/validation.go @@ -552,6 +552,9 @@ func validateNetworking(cluster *kops.Cluster, v *kops.NetworkingSpec, fldPath * } if v.Kubenet != nil { + if c.ContainerRuntime == "containerd" { + allErrs = append(allErrs, field.Invalid(fldPath, "kubenet", "kubenet networking is not supported with containerd")) + } optionTaken = true } diff --git a/pkg/model/components/containerd.go b/pkg/model/components/containerd.go index 1953b7fa24ae2..2721c57ab3539 100644 --- a/pkg/model/components/containerd.go +++ b/pkg/model/components/containerd.go @@ -18,10 +18,8 @@ package components import ( "fmt" - "strings" "github.com/blang/semver/v4" - "k8s.io/klog/v2" "k8s.io/kops/pkg/apis/kops" "k8s.io/kops/upup/pkg/fi" @@ -61,23 +59,7 @@ func (b *ContainerdOptionsBuilder) BuildOptions(o interface{}) error { // Apply defaults for containerd running in container runtime mode containerd.LogLevel = fi.String("info") - usesKubenet := UsesKubenet(clusterSpec.Networking) - if clusterSpec.Networking != nil && usesKubenet { - // Using containerd with Kubenet requires special configuration. This is a temporary backwards-compatible solution - // and will be deprecated when Kubenet is deprecated: - // https://github.com/containerd/cri/blob/master/docs/config.md#cni-config-template - lines := []string{ - "version = 2", - "[plugins]", - " [plugins.\"io.containerd.grpc.v1.cri\"]", - " [plugins.\"io.containerd.grpc.v1.cri\".cni]", - " conf_template = \"/etc/containerd/cni-config.template\"", - } - contents := strings.Join(lines, "\n") - containerd.ConfigOverride = fi.String(contents) - } else { - containerd.ConfigOverride = fi.String("") - } + containerd.ConfigOverride = fi.String("version = 2") } else if clusterSpec.ContainerRuntime == "docker" { // Docker version should always be available