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

Switch bootstrap script from cloud-init to bash #36

Merged
merged 1 commit into from
May 19, 2021
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
2 changes: 1 addition & 1 deletion pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"k8s.io/apimachinery/pkg/util/runtime"
)

var cmd = "/usr/bin/cloud-init clean && /usr/bin/cloud-init --file %s init"
var cmd = "/usr/bin/env bash %s"
var cloudInitGenerator *ostemplate.CloudInitGenerator

//go:generate packr2
Expand Down
113 changes: 59 additions & 54 deletions pkg/generator/templates/cloud-init-ubuntu.template
Original file line number Diff line number Diff line change
@@ -1,60 +1,65 @@
#cloud-config
apt_update: false
manage_etc_hosts: true
write_files:
{{ if .Bootstrap -}}
- path: '/etc/cloud/cloud.cfg.d/custom-networking.cfg'
permissions: '0644'
encoding: b64
content: |
bmV0d29yazoKICBjb25maWc6IGRpc2FibGVkCg==
{{ end -}}
{{ if and (isContainerDEnabled .CRI) .Bootstrap -}}
- path: '/etc/systemd/system/containerd.service.d/11-exec_config.conf'
permissions: '0644'
encoding: b64
content: |
W1NlcnZpY2VdCkV4ZWNTdGFydD0KRXhlY1N0YXJ0PS91c3IvYmluL2NvbnRhaW5lcmQgLS1jb25maWc9L2V0Yy9jb250YWluZXJkL2NvbmZpZy50b21s
{{ end -}}
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I compared this file with the corresponding file in gardener-extension-os-ubuntu-alicloud and at first glance there seems to be quite a number of differences. It seems it's not immediately possible to archive the ubuntu-alicloud extension, at least not without further rework and testing. Are you aware of any major issues?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the major difference is the PROVIDER_ID env variable that is already injected by the provider-alicloud.


{{- define "put-content" -}}
cat << EOF | base64 -d > '{{ .Path }}'
{{ .Content }}
EOF
{{- end -}}

{{ if .Bootstrap }}
mkdir -p /etc/cloud/cloud.cfg.d/
cat <<EOF > /etc/cloud/cloud.cfg.d/custom-networking.cfg
network:
config: disabled
EOF
chmod 0644 /etc/cloud/cloud.cfg.d/custom-networking.cfg
{{- end }}

{{ if and (isContainerDEnabled .CRI) .Bootstrap }}
mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF > /etc/systemd/system/containerd.service.d/11-exec_config.conf
[Service]
ExecStart=
ExecStart=/usr/bin/containerd --config=/etc/containerd/config.toml
EOF
chmod 0644 /etc/systemd/system/containerd.service.d/11-exec_config.conf
{{- end }}

{{ range $_, $file := .Files -}}
- path: '{{ $file.Path }}'
{{- if $file.Permissions }}
permissions: '{{ $file.Permissions }}'
{{- end }}
encoding: b64
content: |
{{ $file.Content }}
{{ end -}}
{{- range $_, $unit := .Units -}}
mkdir -p '{{ $file.Dirname }}'
{{ template "put-content" $file }}
{{ if $file.Permissions -}}
chmod '{{ $file.Permissions }}' '{{ $file.Path }}'
{{ end }}
{{ end }}

{{ range $_, $unit := .Units -}}
{{ if $unit.Content -}}
- path: '{{ $unit.Path }}'
encoding: b64
content: |
{{ $unit.Content }}
{{ end -}}
{{ if $unit.DropIns -}}
{{ template "put-content" $unit }}
{{- end }}
{{ if $unit.DropIns }}
mkdir -p '{{ $unit.DropIns.Path }}'
{{ range $_, $dropIn := $unit.DropIns.Items -}}
- path: '{{ $dropIn.Path }}'
encoding: b64
content: |
{{printf "%s\n" $dropIn.Content}}
{{- end -}}
{{- end -}}
{{ template "put-content" $dropIn }}
{{- end }}
runcmd:
- 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 -}}
{{- 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 -}}
- 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 -}}
systemctl enable containerd && systemctl restart containerd
{{- else }}
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 }}'
{{ end -}}
{{ end -}}
systemctl enable '{{ $unit.Name }}' && systemctl restart '{{ $unit.Name }}'
{{- end }}
{{- end }}
65 changes: 33 additions & 32 deletions pkg/generator/testfiles/cloud-init
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
#cloud-config
apt_update: false
manage_etc_hosts: true
write_files:
- path: '/etc/cloud/cloud.cfg.d/custom-networking.cfg'
permissions: '0644'
encoding: b64
content: |
bmV0d29yazoKICBjb25maWc6IGRpc2FibGVkCg==
- path: '/foo'
permissions: '0600'
encoding: b64
content: |
YmFy
- path: '/etc/systemd/system/docker.service'
encoding: b64
content: |
dW5pdA==
- path: '/etc/systemd/system/docker.service.d/10-docker-opts.conf'
encoding: b64
content: |
b3ZlcnJpZGU=

runcmd:
- 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'
#!/bin/bash
mkdir -p /etc/cloud/cloud.cfg.d/
cat <<EOF > /etc/cloud/cloud.cfg.d/custom-networking.cfg
network:
config: disabled
EOF
chmod 0644 /etc/cloud/cloud.cfg.d/custom-networking.cfg



mkdir -p '/'
cat << EOF | base64 -d > '/foo'
YmFy
EOF
chmod '0600' '/foo'



cat << EOF | base64 -d > '/etc/systemd/system/docker.service'
dW5pdA==
EOF

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'
48 changes: 26 additions & 22 deletions pkg/generator/testfiles/cloud-init-containerd-provision
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
#cloud-config
apt_update: false
manage_etc_hosts: true
write_files:
- path: '/etc/cloud/cloud.cfg.d/custom-networking.cfg'
permissions: '0644'
encoding: b64
content: |
bmV0d29yazoKICBjb25maWc6IGRpc2FibGVkCg==
- path: '/etc/systemd/system/containerd.service.d/11-exec_config.conf'
permissions: '0644'
encoding: b64
content: |
W1NlcnZpY2VdCkV4ZWNTdGFydD0KRXhlY1N0YXJ0PS91c3IvYmluL2NvbnRhaW5lcmQgLS1jb25maWc9L2V0Yy9jb250YWluZXJkL2NvbmZpZy50b21s

runcmd:
- 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 containerd && systemctl restart containerd

- systemctl enable 'cloud-config-downloader.service' && systemctl restart 'cloud-config-downloader.service'
#!/bin/bash
mkdir -p /etc/cloud/cloud.cfg.d/
cat <<EOF > /etc/cloud/cloud.cfg.d/custom-networking.cfg
network:
config: disabled
EOF
chmod 0644 /etc/cloud/cloud.cfg.d/custom-networking.cfg


mkdir -p /etc/systemd/system/containerd.service.d
cat <<EOF > /etc/systemd/system/containerd.service.d/11-exec_config.conf
[Service]
ExecStart=
ExecStart=/usr/bin/containerd --config=/etc/containerd/config.toml
EOF
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
systemctl daemon-reload
systemctl enable containerd && systemctl restart containerd
systemctl enable 'cloud-config-downloader.service' && systemctl restart 'cloud-config-downloader.service'
18 changes: 10 additions & 8 deletions pkg/generator/testfiles/cloud-init-containerd-reconcile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#cloud-config
apt_update: false
manage_etc_hosts: true
write_files:

runcmd:
- 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
#!/bin/bash







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
57 changes: 27 additions & 30 deletions pkg/generator/testfiles/cloud-init-with-drop-in
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
#cloud-config
apt_update: false
manage_etc_hosts: true
write_files:
- path: '/etc/systemd/system/abc.service.d/10-exec-start-pre-init-config.conf'
encoding: b64
content: |
W1NlcnZpY2VdCkV4ZWNTdGFydFByZT0vb3B0L2Jpbi9pbml0LWNvbnRhaW5lcmQ=
- path: '/etc/systemd/system/abc.service.d/12-exec-start-pre-init-config.conf'
encoding: b64
content: |
W1NlcnZpY2VdCkV4ZWNTdGFydFByZT0vb3B0L2Jpbi9pbml0LWNvbnRhaW5lcmQ=
- path: '/etc/systemd/system/mtu-customizer.service'
encoding: b64
content: |
W1NlcnZpY2VdCkV4ZWNTdGFydFByZT0vb3B0L2Jpbi9pbml0LWNvbnRhaW5lcmQ=
- path: '/etc/systemd/system/other.service'
encoding: b64
content: |
W1NlcnZpY2VdCkV4ZWNTdGFydFByZT0vb3B0L2Jpbi9pbml0LWNvbnRhaW5lcmQ=

runcmd:
- 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'
#!/bin/bash







mkdir -p '/etc/systemd/system/abc.service.d'
cat << EOF | base64 -d > '/etc/systemd/system/abc.service.d/10-exec-start-pre-init-config.conf'
W1NlcnZpY2VdCkV4ZWNTdGFydFByZT0vb3B0L2Jpbi9pbml0LWNvbnRhaW5lcmQ=
EOFcat << EOF | base64 -d > '/etc/systemd/system/abc.service.d/12-exec-start-pre-init-config.conf'
W1NlcnZpY2VdCkV4ZWNTdGFydFByZT0vb3B0L2Jpbi9pbml0LWNvbnRhaW5lcmQ=
EOFcat << EOF | base64 -d > '/etc/systemd/system/mtu-customizer.service'
W1NlcnZpY2VdCkV4ZWNTdGFydFByZT0vb3B0L2Jpbi9pbml0LWNvbnRhaW5lcmQ=
EOF
cat << EOF | base64 -d > '/etc/systemd/system/other.service'
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'