Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/v1.4] Add (re-)rendering container runtime config to flatcar upgrades #1918

Merged
merged 3 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This patch release enables the etcd corruption checks on every etcd member that

### Bug or Regression

- Regenerate container runtime configurations based on kubeone.yaml during control-plane upgrades on Flatcar Linux nodes, not only on the initial installation. ([#1918](https://github.com/kubermatic/kubeone/pull/1918))
- Approve pending CSRs when upgrading control plane and static worker nodes ([#1888](https://github.com/kubermatic/kubeone/pull/1888))
- Enable the etcd integrity checks (on startup and every 4 hours) for Kubernetes 1.22+ clusters. See [the official etcd announcement for more details](https://groups.google.com/a/kubernetes.io/g/dev/c/B7gJs88XtQc/m/rSgNOzV2BwAJ). ([#1909](https://github.com/kubermatic/kubeone/pull/1909))
- Fix CSR approving issue for existing nodes with already approved and GCed CSRs ([#1897](https://github.com/kubermatic/kubeone/pull/1897))
Expand Down
48 changes: 40 additions & 8 deletions pkg/scripts/os_flatcar.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ sudo systemctl daemon-reload

source /etc/kubeone/proxy-env

{{ if .INSTALL_DOCKER }}
{{ template "flatcar-docker" . }}
{{ end }}

{{ if .INSTALL_CONTAINERD }}
{{ template "flatcar-containerd" . }}
{{ end }}

sudo mkdir -p /opt/cni/bin
curl -L "https://github.com/containernetworking/plugins/releases/download/v{{ .KUBERNETES_CNI_VERSION }}/cni-plugins-linux-${HOST_ARCH}-v{{ .KUBERNETES_CNI_VERSION }}.tgz" |
sudo tar -C /opt/cni/bin -xz
Expand All @@ -130,6 +138,14 @@ source /etc/kubeone/proxy-env

{{ template "detect-host-cpu-architecture" }}

{{ if .INSTALL_DOCKER }}
{{ template "flatcar-docker" . }}
{{ end }}

{{ if .INSTALL_CONTAINERD }}
{{ template "flatcar-containerd" . }}
{{ end }}

RELEASE="v{{ .KUBERNETES_VERSION }}"
sudo mkdir -p /var/tmp/kube-binaries
cd /var/tmp/kube-binaries
Expand Down Expand Up @@ -197,15 +213,31 @@ func RemoveBinariesFlatcar() (string, error) {
return Render(removeBinariesFlatcarScriptTemplate, nil)
}

func UpgradeKubeadmAndCNIFlatcar(k8sVersion string) (string, error) {
return Render(upgradeKubeadmAndCNIFlatcarScriptTemplate, Data{
"KUBERNETES_VERSION": k8sVersion,
func UpgradeKubeadmAndCNIFlatcar(cluster *kubeoneapi.KubeOneCluster) (string, error) {
data := Data{
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"KUBERNETES_CNI_VERSION": defaultKubernetesCNIVersion,
})
"INSTALL_DOCKER": cluster.ContainerRuntime.Docker,
"INSTALL_CONTAINERD": cluster.ContainerRuntime.Containerd,
}

if err := containerruntime.UpdateDataMap(cluster, data); err != nil {
return "", err
}

return Render(upgradeKubeadmAndCNIFlatcarScriptTemplate, data)
}

func UpgradeKubeletAndKubectlFlatcar(k8sVersion string) (string, error) {
return Render(upgradeKubeletAndKubectlFlatcarScriptTemplate, Data{
"KUBERNETES_VERSION": k8sVersion,
})
func UpgradeKubeletAndKubectlFlatcar(cluster *kubeoneapi.KubeOneCluster) (string, error) {
data := Data{
"KUBERNETES_VERSION": cluster.Versions.Kubernetes,
"INSTALL_DOCKER": cluster.ContainerRuntime.Docker,
"INSTALL_CONTAINERD": cluster.ContainerRuntime.Containerd,
}

if err := containerruntime.UpdateDataMap(cluster, data); err != nil {
return "", err
}

return Render(upgradeKubeletAndKubectlFlatcarScriptTemplate, data)
}
6 changes: 4 additions & 2 deletions pkg/scripts/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ func TestUpgradeKubeadmAndCNIAmazonLinux(t *testing.T) {
func TestUpgradeKubeadmAndCNIFlatcar(t *testing.T) {
t.Parallel()

got, err := UpgradeKubeadmAndCNIFlatcar("v1.17.4")
cls := genCluster(withDocker)
got, err := UpgradeKubeadmAndCNIFlatcar(&cls)
if err != nil {
t.Errorf("UpgradeKubeadmAndCNIFlatcar() error = %v", err)

Expand Down Expand Up @@ -627,7 +628,8 @@ func TestUpgradeKubeletAndKubectlAmazonLinux(t *testing.T) {
func TestUpgradeKubeletAndKubectlFlatcar(t *testing.T) {
t.Parallel()

got, err := UpgradeKubeletAndKubectlFlatcar("v1.17.4")
cls := genCluster(withDocker)
got, err := UpgradeKubeletAndKubectlFlatcar(&cls)
if err != nil {
t.Errorf("UpgradeKubeletAndKubectlFlatcar() error = %v", err)

Expand Down
32 changes: 31 additions & 1 deletion pkg/scripts/testdata/TestUpgradeKubeadmAndCNIFlatcar.golden
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,41 @@ esac

source /etc/kubeone/proxy-env



sudo mkdir -p $(dirname /etc/docker/daemon.json)
sudo touch /etc/docker/daemon.json
sudo chmod 600 /etc/docker/daemon.json
cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": [
"native.cgroupdriver=systemd"
],
"storage-driver": "overlay2",
"log-driver": "json-file",
"log-opts": {
"max-file": "5",
"max-size": "100m"
}
}
EOF
cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now docker
sudo systemctl restart docker





sudo mkdir -p /opt/cni/bin
curl -L "https://github.com/containernetworking/plugins/releases/download/v0.8.7/cni-plugins-linux-${HOST_ARCH}-v0.8.7.tgz" |
sudo tar -C /opt/cni/bin -xz

RELEASE="vv1.17.4"
RELEASE="v1.17.4"

sudo mkdir -p /var/tmp/kube-binaries
cd /var/tmp/kube-binaries
Expand Down
32 changes: 31 additions & 1 deletion pkg/scripts/testdata/TestUpgradeKubeletAndKubectlFlatcar.golden
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,37 @@ aarch64)
esac


RELEASE="vv1.17.4"


sudo mkdir -p $(dirname /etc/docker/daemon.json)
sudo touch /etc/docker/daemon.json
sudo chmod 600 /etc/docker/daemon.json
cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": [
"native.cgroupdriver=systemd"
],
"storage-driver": "overlay2",
"log-driver": "json-file",
"log-opts": {
"max-file": "5",
"max-size": "100m"
}
}
EOF
cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now docker
sudo systemctl restart docker





RELEASE="v1.17.4"
sudo mkdir -p /var/tmp/kube-binaries
cd /var/tmp/kube-binaries
sudo curl -L --remote-name-all \
Expand Down
4 changes: 2 additions & 2 deletions pkg/tasks/kubernetes_binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func upgradeKubeletAndKubectlBinariesDebian(s *state.State) error {
}

func upgradeKubeletAndKubectlBinariesFlatcar(s *state.State) error {
cmd, err := scripts.UpgradeKubeletAndKubectlFlatcar(s.Cluster.Versions.Kubernetes)
cmd, err := scripts.UpgradeKubeletAndKubectlFlatcar(s.Cluster)
if err != nil {
return err
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func upgradeKubeadmAndCNIBinariesAmazonLinux(s *state.State) error {
}

func upgradeKubeadmAndCNIBinariesFlatcar(s *state.State) error {
cmd, err := scripts.UpgradeKubeadmAndCNIFlatcar(s.Cluster.Versions.Kubernetes)
cmd, err := scripts.UpgradeKubeadmAndCNIFlatcar(s.Cluster)
if err != nil {
return err
}
Expand Down