Skip to content

Commit

Permalink
Code polishing 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Hacman committed Nov 23, 2019
1 parent a25b1bd commit b8d8ce4
Show file tree
Hide file tree
Showing 32 changed files with 313 additions and 200 deletions.
2 changes: 1 addition & 1 deletion k8s/crds/kops.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ spec:
address:
description: Address of containerd's GRPC server (default "/run/containerd/containerd.sock")
type: string
externalConfig:
conrigFile:
description: Complete containerd config file provided by the user
type: string
logLevel:
Expand Down
25 changes: 15 additions & 10 deletions nodeup/pkg/model/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,21 @@ func (b *ContainerdBuilder) Build(c *fi.ModelBuilderContext) error {
c.AddTask(t)
}

// Add config file
{
containerdConfigFile := ""
if b.Cluster.Spec.Containerd != nil {
containerdConfigFile = fi.StringValue(b.Cluster.Spec.Containerd.ConfigFile)
}

t := &nodetasks.File{
Path: "/etc/containerd/config-kops.toml",
Contents: fi.NewStringResource(containerdConfigFile),
Type: nodetasks.FileType_File,
}
c.AddTask(t)
}

containerdVersion := b.containerdVersion()

// Add packages
Expand Down Expand Up @@ -304,16 +319,6 @@ func (b *ContainerdBuilder) Build(c *fi.ModelBuilderContext) error {
c.AddTask(&nodetasks.Package{Name: dep})
}

// Add config file
{
t := &nodetasks.File{
Path: "/etc/containerd/config-kops.toml",
Contents: fi.NewStringResource(""),
Type: nodetasks.FileType_File,
}
c.AddTask(t)
}

// Note we do _not_ stop looping... centos/rhel comprises multiple packages
}

Expand Down
70 changes: 0 additions & 70 deletions nodeup/pkg/model/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,13 +795,7 @@ var dockerVersions = []dockerVersion{
Source: "https://download.docker.com/linux/debian/dists/stretch/pool/stable/amd64/docker-ce-cli_18.09.9~3-0~debian-stretch_amd64.deb",
Hash: "88f8f3103d2e5011e2f1a73b9e6dbf03d6e6698a",
},
"containerd.io": {
Version: "1.2.10-3",
Source: "https://download.docker.com/linux/debian/dists/stretch/pool/stable/amd64/containerd.io_1.2.10-3_amd64.deb",
Hash: "186f2f2c570f37b363102e6b879073db6dec671d",
},
},
Dependencies: []string{"bridge-utils", "libapparmor1", "libltdl7", "perl"},
},

// 18.09.9 - Debian Buster
Expand All @@ -819,13 +813,7 @@ var dockerVersions = []dockerVersion{
Source: "https://download.docker.com/linux/debian/dists/buster/pool/stable/amd64/docker-ce-cli_18.09.9~3-0~debian-buster_amd64.deb",
Hash: "510eee5b6884867be0d2b360f8ff8cf7f0c0d11a",
},
"containerd.io": {
Version: "1.2.10-3",
Source: "https://download.docker.com/linux/debian/dists/buster/pool/stable/amd64/containerd.io_1.2.10-3_amd64.deb",
Hash: "365e4a7541ce2cf3c3036ea2a9bf6b40a50893a8",
},
},
Dependencies: []string{"bridge-utils", "libapparmor1", "libltdl7", "perl"},
},

// 18.09.9 - Bionic
Expand All @@ -843,13 +831,7 @@ var dockerVersions = []dockerVersion{
Source: "https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/docker-ce-cli_18.09.9~3-0~ubuntu-bionic_amd64.deb",
Hash: "bca089a50ea22f02abe88f68d7ca35c26be9967b",
},
"containerd.io": {
Version: "1.2.10-3",
Source: "https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/containerd.io_1.2.10-3_amd64.deb",
Hash: "f4c941807310e3fa470dddfb068d599174a3daec",
},
},
Dependencies: []string{"bridge-utils", "iptables", "libapparmor1", "libltdl7", "perl"},
},

// 18.09.9 - CentOS / Rhel7
Expand All @@ -867,18 +849,7 @@ var dockerVersions = []dockerVersion{
Source: "https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-18.09.9-3.el7.x86_64.rpm",
Hash: "0c51b1339a95bd732ca305f07b7bcc95f132b9c8",
},
"containerd.io": {
Version: "1.2.10",
Source: "https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.10-3.2.el7.x86_64.rpm",
Hash: "f6447e84479df3a58ce04a3da87ccc384663493b",
},
"container-selinux": {
Version: "2.107",
Source: "http://vault.centos.org/7.6.1810/extras/x86_64/Packages/container-selinux-2.107-1.el7_6.noarch.rpm",
Hash: "7de4211fa0dfd240d8827b93763e1eb5f0d56411",
},
},
Dependencies: []string{"libtool-ltdl", "libseccomp", "libcgroup", "policycoreutils-python"},
},

// 18.09.9 - CentOS / Rhel8
Expand All @@ -896,13 +867,7 @@ var dockerVersions = []dockerVersion{
Source: "https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-18.09.9-3.el7.x86_64.rpm",
Hash: "0c51b1339a95bd732ca305f07b7bcc95f132b9c8",
},
"containerd.io": {
Version: "1.2.10",
Source: "https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.10-3.2.el7.x86_64.rpm",
Hash: "f6447e84479df3a58ce04a3da87ccc384663493b",
},
},
Dependencies: []string{"container-selinux", "libtool-ltdl", "libseccomp", "libcgroup", "policycoreutils-python-utils", "python3-policycoreutils"},
},

// 19.03.4 - k8s 1.17 - https://github.com/kubernetes/kubernetes/pull/84476
Expand All @@ -922,13 +887,7 @@ var dockerVersions = []dockerVersion{
Source: "https://download.docker.com/linux/debian/dists/stretch/pool/stable/amd64/docker-ce-cli_19.03.4~3-0~debian-stretch_amd64.deb",
Hash: "57f71ee764abb19a0b4c580ff14b1eb3de3a9e08",
},
"containerd.io": {
Version: "1.2.10-3",
Source: "https://download.docker.com/linux/debian/dists/stretch/pool/stable/amd64/containerd.io_1.2.10-3_amd64.deb",
Hash: "186f2f2c570f37b363102e6b879073db6dec671d",
},
},
Dependencies: []string{"bridge-utils", "libapparmor1", "libltdl7", "perl"},
},

// 19.03.4 - Debian Buster
Expand All @@ -946,13 +905,7 @@ var dockerVersions = []dockerVersion{
Source: "https://download.docker.com/linux/debian/dists/buster/pool/stable/amd64/docker-ce-cli_19.03.4~3-0~debian-buster_amd64.deb",
Hash: "2549a364f0e5ce489c79b292b78e349751385dd5",
},
"containerd.io": {
Version: "1.2.10-3",
Source: "https://download.docker.com/linux/debian/dists/buster/pool/stable/amd64/containerd.io_1.2.10-3_amd64.deb",
Hash: "365e4a7541ce2cf3c3036ea2a9bf6b40a50893a8",
},
},
Dependencies: []string{"bridge-utils", "libapparmor1", "libltdl7", "perl"},
},

// 19.03.4 - Bionic
Expand All @@ -970,13 +923,7 @@ var dockerVersions = []dockerVersion{
Source: "https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/docker-ce-cli_19.03.4~3-0~ubuntu-bionic_amd64.deb",
Hash: "09402bf5dac40f0c50f1071b17f38f6584a42ad1",
},
"containerd.io": {
Version: "1.2.10-3",
Source: "https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/containerd.io_1.2.10-3_amd64.deb",
Hash: "f4c941807310e3fa470dddfb068d599174a3daec",
},
},
Dependencies: []string{"bridge-utils", "iptables", "libapparmor1", "libltdl7", "perl"},
},

// 19.03.4 - CentOS / Rhel7
Expand All @@ -994,18 +941,7 @@ var dockerVersions = []dockerVersion{
Source: "https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.4-3.el7.x86_64.rpm",
Hash: "1fffcc716e74a59f753f8898ba96693a00e79e26",
},
"containerd.io": {
Version: "1.2.10",
Source: "https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.10-3.2.el7.x86_64.rpm",
Hash: "f6447e84479df3a58ce04a3da87ccc384663493b",
},
"container-selinux": {
Version: "2.107",
Source: "http://vault.centos.org/7.6.1810/extras/x86_64/Packages/container-selinux-2.107-1.el7_6.noarch.rpm",
Hash: "7de4211fa0dfd240d8827b93763e1eb5f0d56411",
},
},
Dependencies: []string{"libtool-ltdl", "libseccomp", "libcgroup", "policycoreutils-python"},
},

// 19.03.4 - CentOS / Rhel8
Expand All @@ -1023,13 +959,7 @@ var dockerVersions = []dockerVersion{
Source: "https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.4-3.el7.x86_64.rpm",
Hash: "1fffcc716e74a59f753f8898ba96693a00e79e26",
},
"containerd.io": {
Version: "1.2.10",
Source: "https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.10-3.2.el7.x86_64.rpm",
Hash: "f6447e84479df3a58ce04a3da87ccc384663493b",
},
},
Dependencies: []string{"container-selinux", "libtool-ltdl", "libseccomp", "libcgroup", "policycoreutils-python-utils", "python3-policycoreutils"},
},

// TIP: When adding the next version, copy the previous
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kops/containerdconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ContainerdConfig struct {
// Address of containerd's GRPC server (default "/run/containerd/containerd.sock")
Address *string `json:"address,omitempty" flag:"address"`
// Complete containerd config file provided by the user
ExternalConfig *string `json:"externalConfig,omitempty"`
ConfigFile *string `json:"configFile,omitempty"`
// Logging level [trace, debug, info, warn, error, fatal, panic] (default "warn")
LogLevel *string `json:"logLevel,omitempty" flag:"log-level"`
// Directory for persistent data (default "/var/lib/containerd")
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kops/v1alpha1/containerdconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ContainerdConfig struct {
// Address of containerd's GRPC server (default "/run/containerd/containerd.sock")
Address *string `json:"address,omitempty" flag:"address"`
// Complete containerd config file provided by the user
ExternalConfig *string `json:"externalConfig,omitempty"`
ConfigFile *string `json:"configFile,omitempty"`
// Logging level [trace, debug, info, warn, error, fatal, panic] (default "warn")
LogLevel *string `json:"logLevel,omitempty" flag:"log-level"`
// Directory for persistent data (default "/var/lib/containerd")
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/kops/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/apis/kops/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/apis/kops/v1alpha2/containerdconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ContainerdConfig struct {
// Address of containerd's GRPC server (default "/run/containerd/containerd.sock")
Address *string `json:"address,omitempty" flag:"address"`
// Complete containerd config file provided by the user
ExternalConfig *string `json:"externalConfig,omitempty"`
ConfigFile *string `json:"configFile,omitempty"`
// Logging level [trace, debug, info, warn, error, fatal, panic] (default "warn")
LogLevel *string `json:"logLevel,omitempty" flag:"log-level"`
// Directory for persistent data (default "/var/lib/containerd")
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/kops/v1alpha2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/apis/kops/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/model/bootstrapscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func (b *BootstrapScript) ResourceNodeUp(ig *kops.InstanceGroup, cluster *kops.C

spec := make(map[string]interface{})
spec["cloudConfig"] = cs.CloudConfig
spec["containerRuntime"] = cs.ContainerRuntime
spec["containerd"] = cs.Containerd
spec["docker"] = cs.Docker
spec["kubeProxy"] = cs.KubeProxy
spec["kubelet"] = cs.Kubelet
Expand Down
4 changes: 4 additions & 0 deletions pkg/model/bootstrapscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ func makeTestCluster(hookSpecRoles []kops.InstanceGroupRole, fileAssetSpecRoles
CloudConfig: &kops.CloudConfiguration{
NodeTags: s("something"),
},
ContainerRuntime: "docker",
Containerd: &kops.ContainerdConfig{
LogLevel: s("info"),
},
Docker: &kops.DockerConfig{
LogLevel: s("INFO"),
},
Expand Down
41 changes: 19 additions & 22 deletions pkg/model/components/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (b *ContainerdOptionsBuilder) BuildOptions(o interface{}) error {

if clusterSpec.ContainerRuntime == "containerd" {
if clusterSpec.KubernetesVersion == "" {
return fmt.Errorf("KubernetesVersion is required")
return fmt.Errorf("Kubernetes version is required")
}

sv, err := KubernetesVersion(clusterSpec)
Expand All @@ -58,20 +58,13 @@ func (b *ContainerdOptionsBuilder) BuildOptions(o interface{}) error {
// Containerd 1.2 is validated against Kubernetes v1.11+
// https://github.com/containerd/containerd/blob/master/releases/v1.2.0.toml#L34
containerdVersion = "1.2.10"
}

if containerdVersion == "" {
return fmt.Errorf("unknown version of kubernetes %q (cannot infer containerd version)", clusterSpec.KubernetesVersion)
} else {
// Apply containerd defaults for Docker
containerd.Address = fi.String("/run/containerd/containerd.sock")
containerd.LogLevel = fi.String("warn")
containerd.Root = fi.String("/var/lib/containerd")
containerd.State = fi.String("/run/containerd")
return fmt.Errorf("unknown version of kubernetes %q (cannot infer containerd version)", clusterSpec.KubernetesVersion)
}

} else if clusterSpec.ContainerRuntime == "docker" {
if fi.StringValue(clusterSpec.Docker.Version) == "" {
return fmt.Errorf("Docker.Version is required")
return fmt.Errorf("Docker version is required")
}

// Set containerd version for known Docker versions
Expand All @@ -83,25 +76,29 @@ func (b *ContainerdOptionsBuilder) BuildOptions(o interface{}) error {
containerdVersion = "1.2.10"
case "18.09.3":
containerdVersion = "1.2.10"
}

// Older version of Docker with bundled contained
if containerdVersion == "" {
default:
// Older version of docker
containerd.SkipInstall = true
} else {
// Apply containerd defaults
containerd.Address = fi.String("/run/containerd/containerd.sock")
containerd.LogLevel = fi.String("warn")
containerd.Root = fi.String("/var/lib/containerd")
containerd.State = fi.String("/run/containerd")
}

} else {
// Unknown container runtime, should not install containerd
containerd.SkipInstall = true
}

containerd.Version = &containerdVersion
if containerdVersion != "" {
containerd.Version = &containerdVersion
}
}

// Apply global containerd defaults
containerd.LogLevel = fi.String("warn")

configFile := ""
if clusterSpec.ContainerRuntime == "docker" {
configFile += "disabled_plugins = [\"cri\"]\n"
}
containerd.ConfigFile = &configFile

return nil
}
Loading

0 comments on commit b8d8ce4

Please sign in to comment.