Skip to content

Commit

Permalink
Avoid unnecessary restart of systemd services (gardener#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpnachev authored Jul 6, 2021
1 parent a8bdfbf commit c2c8462
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
8 changes: 8 additions & 0 deletions pkg/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ var _ = Describe("Ubuntu OS Generator Test", func() {
expectedCloudInit, err := testfiles.Files.ReadFile("cloud-init-containerd-reconcile")
Expect(err).NotTo(HaveOccurred())
expected := string(expectedCloudInit)

osc.Files = []*commongen.File{
{
Path: "/path",
Content: []byte("content"),
},
}

osc.Bootstrap = false
osc.Object.Spec.Purpose = v1alpha1.OperatingSystemConfigPurposeReconcile
cloudInit, _, err := g.Generate(osc)
Expand Down
18 changes: 6 additions & 12 deletions pkg/generator/templates/cloud-init-ubuntu.template
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,15 @@ mkdir -p '{{ $unit.DropIns.Path }}'
{{- end }}
{{- end }}

until apt-get update -qq && apt-get install --no-upgrade -qqy docker.io socat nfs-common logrotate jq policykit-1; do sleep 1; done
systemctl daemon-reload

{{- if .Bootstrap }}
{{- if isContainerDEnabled .CRI }}
systemctl enable containerd && systemctl restart containerd
{{- else }}
until apt-get update -qq && apt-get install --no-upgrade -qqy docker.io socat nfs-common logrotate jq policykit-1; do sleep 1; done
ln -s /usr/bin/docker /bin/docker
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
systemctl restart docker
{{- end }}
{{- end }}

{{- range $_, $unit := .Units }}
{{- if or (ne $unit.Name "cloud-config-downloader.service") ($.Bootstrap) }}
systemctl enable '{{ $unit.Name }}' && systemctl restart '{{ $unit.Name }}'
systemctl daemon-reload
{{- if isContainerDEnabled .CRI }}
systemctl enable containerd && systemctl restart containerd
{{- end }}
systemctl enable docker && systemctl restart docker
systemctl enable cloud-config-downloader && systemctl restart cloud-config-downloader
{{- end }}
7 changes: 3 additions & 4 deletions pkg/generator/testfiles/cloud-init
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ mkdir -p '/etc/systemd/system/docker.service.d'
cat << EOF | base64 -d > '/etc/systemd/system/docker.service.d/10-docker-opts.conf'
b3ZlcnJpZGU=
EOF

until apt-get update -qq && apt-get install --no-upgrade -qqy docker.io socat nfs-common logrotate jq policykit-1; do sleep 1; done
systemctl daemon-reload
ln -s /usr/bin/docker /bin/docker
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
systemctl restart docker
systemctl enable 'docker.service' && systemctl restart 'docker.service'
systemctl daemon-reload
systemctl enable docker && systemctl restart docker
systemctl enable cloud-config-downloader && systemctl restart cloud-config-downloader
6 changes: 4 additions & 2 deletions pkg/generator/testfiles/cloud-init-containerd-provision
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ chmod 0644 /etc/systemd/system/containerd.service.d/11-exec_config.conf




until apt-get update -qq && apt-get install --no-upgrade -qqy docker.io socat nfs-common logrotate jq policykit-1; do sleep 1; done
ln -s /usr/bin/docker /bin/docker
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
systemctl daemon-reload
systemctl enable containerd && systemctl restart containerd
systemctl enable 'cloud-config-downloader.service' && systemctl restart 'cloud-config-downloader.service'
systemctl enable docker && systemctl restart docker
systemctl enable cloud-config-downloader && systemctl restart cloud-config-downloader
6 changes: 4 additions & 2 deletions pkg/generator/testfiles/cloud-init-containerd-reconcile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@



mkdir -p '/'
cat << EOF | base64 -d > '/path'
Y29udGVudA==
EOF




until apt-get update -qq && apt-get install --no-upgrade -qqy docker.io socat nfs-common logrotate jq policykit-1; do sleep 1; done
systemctl daemon-reload
6 changes: 0 additions & 6 deletions pkg/generator/testfiles/cloud-init-with-drop-in
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,3 @@ W1NlcnZpY2VdCkV4ZWNTdGFydFByZT0vb3B0L2Jpbi9pbml0LWNvbnRhaW5lcmQ=
EOF



until apt-get update -qq && apt-get install --no-upgrade -qqy docker.io socat nfs-common logrotate jq policykit-1; do sleep 1; done
systemctl daemon-reload
systemctl enable 'abc.service' && systemctl restart 'abc.service'
systemctl enable 'mtu-customizer.service' && systemctl restart 'mtu-customizer.service'
systemctl enable 'other.service' && systemctl restart 'other.service'

0 comments on commit c2c8462

Please sign in to comment.