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

Force static manifests render on upgrade #1746

Merged
merged 3 commits into from
Jan 24, 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
10 changes: 6 additions & 4 deletions pkg/scripts/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ var (
sudo rm -rf /etc/kubeone
`)

kubeadmUpgradeLeaderScriptTemplate = heredoc.Doc(`
sudo {{ .KUBEADM_UPGRADE }} --config={{ .WORK_DIR }}/cfg/master_0.yaml
kubeadmUpgradeScriptTemplate = heredoc.Doc(`
sudo {{ .KUBEADM_UPGRADE }}{{ if .LEADER }} --config={{ .WORK_DIR }}/cfg/master_{{ .NODE_ID }}.yaml{{ end }}
`)

kubeadmPauseImageVersionScriptTemplate = heredoc.Doc(`
Expand Down Expand Up @@ -110,10 +110,12 @@ func KubeadmReset(verboseFlag, workdir string) (string, error) {
})
}

func KubeadmUpgradeLeader(kubeadmCmd, workdir string) (string, error) {
return Render(kubeadmUpgradeLeaderScriptTemplate, map[string]interface{}{
func KubeadmUpgrade(kubeadmCmd, workdir string, leader bool, nodeID int) (string, error) {
return Render(kubeadmUpgradeScriptTemplate, map[string]interface{}{
"KUBEADM_UPGRADE": kubeadmCmd,
"WORK_DIR": workdir,
"NODE_ID": nodeID,
"LEADER": leader,
})
}

Expand Down
15 changes: 12 additions & 3 deletions pkg/scripts/kubeadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,13 @@ func TestKubeadmReset(t *testing.T) {
}
}

func TestKubeadmUpgradeLeader(t *testing.T) {
func TestKubeadmUpgrade(t *testing.T) {
t.Parallel()

type args struct {
kubeadmCmd string
workdir string
leader bool
}
tests := []struct {
name string
Expand All @@ -261,15 +262,23 @@ func TestKubeadmUpgradeLeader(t *testing.T) {
name: "v1beta2",
args: args{
workdir: "test-wd",
kubeadmCmd: "kubeadm upgrade node --certificate-renewal=true",
kubeadmCmd: "kubeadm upgrade node",
},
},
{
name: "leader",
args: args{
workdir: "some",
kubeadmCmd: "kubeadm upgrade apply -y --certificate-renewal=true v1.1.1",
leader: true,
},
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got, err := KubeadmUpgradeLeader(tt.args.kubeadmCmd, tt.args.workdir)
got, err := KubeadmUpgrade(tt.args.kubeadmCmd, tt.args.workdir, tt.args.leader, 0)
if err != tt.err {
t.Errorf("KubeadmUpgradeLeader() error = %v, wantErr %v", err, tt.err)
return
Expand Down
1 change: 0 additions & 1 deletion pkg/scripts/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var migrateToContainerdScriptTemplate = heredoc.Doc(`
sudo docker ps -qa | xargs sudo docker rm || true

{{ template "container-runtime-daemon-config" . }}
{{ template "containerd-systemd-environment" . }}
{{ if .IS_FLATCAR -}}
{{ template "flatcar-systemd-drop-in" . }}
{{ end -}}
Expand Down
32 changes: 15 additions & 17 deletions pkg/scripts/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,21 @@ import (
)

const (
daemonsProxyScript = `
sudo mkdir -p /etc/systemd/system/docker.service.d
cat <<EOF | sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf
daemonsEnvironmentScriptTemplate = `
{{- range .SYSTEMD_SERVICES }}
sudo mkdir -p /etc/systemd/system/{{ . }}.service.d
cat <<EOF | sudo tee /etc/systemd/system/{{ . }}.service.d/http-proxy.conf
[Service]
EnvironmentFile=/etc/kubeone/proxy-env
EnvironmentFile=/etc/environment
EOF

sudo mkdir -p /etc/systemd/system/kubelet.service.d
cat <<EOF | sudo tee /etc/systemd/system/kubelet.service.d/http-proxy.conf
[Service]
EnvironmentFile=/etc/kubeone/proxy-env
EOF

{{ end }}
sudo systemctl daemon-reload
if sudo systemctl status docker &>/dev/null; then sudo systemctl restart docker; fi
if sudo systemctl status kubelet &>/dev/null; then sudo systemctl restart kubelet; fi
{{- range .SYSTEMD_SERVICES }}
if sudo systemctl status {{ . }} &>/dev/null; then sudo systemctl restart {{ . }}; fi
{{- end }}
`

environmentFileCmd = `
environmentFileScriptTemplate = `
sudo mkdir -p /etc/kubeone
cat <<EOF | sudo tee /etc/kubeone/proxy-env
{{ with .HTTP_PROXY -}}
Expand Down Expand Up @@ -70,13 +66,15 @@ sudo tee /etc/environment < $envtmp
)

func EnvironmentFile(cluster *kubeone.KubeOneCluster) (string, error) {
return Render(environmentFileCmd, Data{
return Render(environmentFileScriptTemplate, Data{
"HTTP_PROXY": cluster.Proxy.HTTP,
"HTTPS_PROXY": cluster.Proxy.HTTPS,
"NO_PROXY": cluster.Proxy.NoProxy,
})
}

func DaemonsProxy() (string, error) {
return Render(daemonsProxyScript, nil)
func DaemonsEnvironmentDropIn(daemons ...string) (string, error) {
return Render(daemonsEnvironmentScriptTemplate, Data{
"SYSTEMD_SERVICES": daemons,
})
}
4 changes: 2 additions & 2 deletions pkg/scripts/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ func TestEnvironmentFile(t *testing.T) {
}
}

func TestDaemonsProxy(t *testing.T) {
func TestTestDaemonsProxy(t *testing.T) {
t.Parallel()

got, err := DaemonsProxy()
got, err := DaemonsEnvironmentDropIn("docker", "containerd", "kubelet")
if err != nil {
t.Errorf("DaemonsProxy() error = %v", err)
return
Expand Down
11 changes: 0 additions & 11 deletions pkg/scripts/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,7 @@ var (
{{- end }}
`),

"containerd-systemd-environment": heredoc.Doc(`
sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF
`),

"containerd-systemd-setup": heredoc.Doc(`
{{ template "containerd-systemd-environment" . }}
sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down Expand Up @@ -207,7 +197,6 @@ var (

"flatcar-docker": heredoc.Doc(`
{{ template "container-runtime-daemon-config" . }}
{{ template "containerd-systemd-environment" . }}
sudo systemctl daemon-reload
sudo systemctl enable --now docker
sudo systemctl restart docker
Expand Down
7 changes: 0 additions & 7 deletions pkg/scripts/testdata/TestKubeadmAmazonLinux-force.golden
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
7 changes: 0 additions & 7 deletions pkg/scripts/testdata/TestKubeadmAmazonLinux-proxy.golden
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
7 changes: 0 additions & 7 deletions pkg/scripts/testdata/TestKubeadmAmazonLinux-simple.golden
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
7 changes: 0 additions & 7 deletions pkg/scripts/testdata/TestKubeadmAmazonLinux-v1.16.1.golden
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///run/containerd/containerd.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///run/containerd/containerd.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
7 changes: 0 additions & 7 deletions pkg/scripts/testdata/TestKubeadmCentOS-force.golden
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
7 changes: 0 additions & 7 deletions pkg/scripts/testdata/TestKubeadmCentOS-proxy.golden
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
7 changes: 0 additions & 7 deletions pkg/scripts/testdata/TestKubeadmCentOS-simple.golden
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
7 changes: 0 additions & 7 deletions pkg/scripts/testdata/TestKubeadmCentOS-v1.16.1.golden
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
7 changes: 0 additions & 7 deletions pkg/scripts/testdata/TestKubeadmCentOS-with_containerd.golden
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///run/containerd/containerd.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///run/containerd/containerd.sock
EOF

sudo mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF | sudo tee /etc/systemd/system/containerd.service.d/environment.conf
[Service]
Restart=always
EnvironmentFile=-/etc/environment
EOF

sudo systemctl daemon-reload
sudo systemctl enable containerd
sudo systemctl restart containerd
Expand Down
Loading