Repository: kubermatic/machine-controller
Pull request #1277 (2022-05-06 12:27:10)

Update containerd to 1.5 for all Kubernetes versions
**What this PR does / why we need it**:
As discussed, this PR changes logic introduced with #1272 to only use containerd 1.5 in Kubernetes 1.24+. containerd 1.5 is now used for all Kubernetes versions still supported by `machine-controller`. Amazon Linux 2 is the exception as it does not have containerd 1.5 available.

Note: containerd installed with docker remains on 1.4 right now due to docker 19.03 only mentioning containerd 1.3 in its release notes. Maybe 1.5 works fine too, but let's investigate that in a separate PR which also bumps docker to 20.10.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:

**Optional Release Note**:
<!--
Write your release note:
1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
2. If no release note is required, just write "NONE".
-->
```release-note
Update containerd to 1.5 when using it as container runtime (Amazon Linux 2 remains on 1.4 until newer versions are available)
```


kubermatic-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubermatic/machine-controller/pull/1277#" title="Author self-approved">embik</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **ahmedwaleedmalik** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @ahmedwaleedmalik` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubermatic%2Fmachine-controller).

<details open>
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubermatic/machine-controller/blob/master/OWNERS)~~ [embik]
- **[pkg/userdata/OWNERS](https://github.com/kubermatic/machine-controller/blob/master/pkg/userdata/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["ahmedwaleedmalik"]} -->
kron4eg: /approve
/lgtm
kubermatic-bot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubermatic/machine-controller/pull/1277#pullrequestreview-964686046" title="Approved">ahmedwaleedmalik</a>*, *<a href="https://github.com/kubermatic/machine-controller/pull/1277#" title="Author self-approved">embik</a>*, *<a href="https://github.com/kubermatic/machine-controller/pull/1277#issuecomment-1119591694" title="LGTM">kron4eg</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubermatic%2Fmachine-controller).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubermatic/machine-controller/blob/master/OWNERS)~~ [ahmedwaleedmalik,embik,kron4eg]
- ~~[pkg/userdata/OWNERS](https://github.com/kubermatic/machine-controller/blob/master/pkg/userdata/OWNERS)~~ [ahmedwaleedmalik]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/pkg/containerruntime/containerd.go b/pkg/containerruntime/containerd.go
index 07280ab3..29f3e801 100644
--- a/pkg/containerruntime/containerd.go
+++ b/pkg/containerruntime/containerd.go
@@ -63,13 +63,10 @@ func (eng *Containerd) ScriptFor(os types.OperatingSystem) (string, error) {
 		args.ContainerdVersion = eng.version
 	}
 
-	// Amazon Linux 2 does not have containerd 1.5
-	if eng.version == "" && os == types.OperatingSystemAmazonLinux2 {
-		args.ContainerdVersion = LegacyContainerdVersion
-	}
-
 	switch os {
 	case types.OperatingSystemAmazonLinux2:
+		// Amazon Linux 2 does not have containerd 1.5
+		args.ContainerdVersion = LegacyContainerdVersion
 		err := containerdAmzn2Template.Execute(&buf, args)
 		return buf.String(), err
 	case types.OperatingSystemCentOS, types.OperatingSystemRHEL, types.OperatingSystemRockyLinux:
diff --git a/pkg/containerruntime/containerruntime.go b/pkg/containerruntime/containerruntime.go
index f9ce1934..f8c23ca2 100644
--- a/pkg/containerruntime/containerruntime.go
+++ b/pkg/containerruntime/containerruntime.go
@@ -117,13 +117,11 @@ func (cfg Config) Engine(kubeletVersion *semver.Version) Engine {
 	moreThan124, _ := semver.NewConstraint(">= 1.24")
 
 	switch {
-	case moreThan124.Check(kubeletVersion):
+	case moreThan124.Check(kubeletVersion) || cfg.Containerd != nil:
+		// docker support has been removed in Kubernetes 1.24
 		return containerd
 	case cfg.Docker != nil:
 		return docker
-	case cfg.Containerd != nil:
-		containerd.version = LegacyContainerdVersion
-		return containerd
 	}
 
 	return docker


Test patch:
diff --git a/pkg/userdata/ubuntu/testdata/containerd.yaml b/pkg/userdata/ubuntu/testdata/containerd.yaml
index 593abf21..b3ccf4b3 100644
--- a/pkg/userdata/ubuntu/testdata/containerd.yaml
+++ b/pkg/userdata/ubuntu/testdata/containerd.yaml
@@ -103,7 +103,7 @@ write_files:
     EnvironmentFile=-/etc/environment
     EOF
 
-    apt-get install -y --allow-downgrades containerd.io=1.4*
+    apt-get install -y --allow-downgrades containerd.io=1.5*
     apt-mark hold containerd.io
 
     systemctl daemon-reload