Skip to content

Commit

Permalink
Remove support for Kubenet with containerd
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Hacman committed Dec 27, 2020
1 parent e39f8bc commit dafcf1a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 86 deletions.
3 changes: 3 additions & 0 deletions cmd/kops/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 0 additions & 43 deletions nodeup/pkg/model/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
24 changes: 0 additions & 24 deletions nodeup/pkg/model/tests/containerdbuilder/simple/tasks.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/kops/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
20 changes: 1 addition & 19 deletions pkg/model/components/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dafcf1a

Please sign in to comment.