Skip to content

Commit e35f798

Browse files
committed
Skip containerd setup on images without systemd
They cannot work, so there is no point in running them. Show an optional requirements failure to the user instead. Signed-off-by: Jan Dubois <[email protected]>
1 parent 04e7678 commit e35f798

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

pkg/cidata/user-data.TEMPLATE

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,14 @@ write_files:
146146
owner: root:root
147147
path: /var/lib/cloud/scripts/per-boot/10-alpine-prep.boot.sh
148148
permissions: '0755'
149+
{{- if .Containerd.User}}
149150
- content: |
150151
#!/bin/bash
151152
set -eux -o pipefail
152153
153-
{{- if .Containerd.User}}
154+
# This script does not work unless systemd is available
155+
command -v systemctl 2>&1 >/dev/null || exit 0
156+
154157
# Set up env
155158
for f in .profile .bashrc; do
156159
if ! grep -q "# Lima BEGIN" "/home/{{.User}}.linux/$f"; then
@@ -194,7 +197,14 @@ write_files:
194197
195198
# Start systemd session
196199
loginctl enable-linger "{{.User}}"
197-
{{- end}}
200+
owner: root:root
201+
# We do not use per-once.
202+
path: /var/lib/cloud/scripts/per-boot/20-rootless-base.boot.sh
203+
permissions: '0755'
204+
{{- end}}
205+
- content: |
206+
#!/bin/bash
207+
set -eux -o pipefail
198208
199209
# Create mount points
200210
{{- range $val := .Mounts}}
@@ -218,12 +228,13 @@ write_files:
218228
fi
219229
owner: root:root
220230
# We do not use per-once.
221-
path: /var/lib/cloud/scripts/per-boot/20-base.boot.sh
231+
path: /var/lib/cloud/scripts/per-boot/25-guestagent-base.boot.sh
222232
permissions: '0755'
223233
{{- if or .Mounts .Containerd.System .Containerd.User }}
224234
- content: |
225235
#!/bin/bash
226236
set -eux -o pipefail
237+
227238
# Install minimum dependencies
228239
if command -v apt-get 2>&1 >/dev/null; then
229240
export DEBIAN_FRONTEND=noninteractive
@@ -276,6 +287,10 @@ write_files:
276287
- content: |
277288
#!/bin/bash
278289
set -eux -o pipefail
290+
291+
# This script does not work unless systemd is available
292+
command -v systemctl 2>&1 >/dev/null || exit 0
293+
279294
if [ ! -x /usr/local/bin/nerdctl ]; then
280295
mkdir -p -m 600 /mnt/lima-cidata
281296
mount -t iso9660 -o ro /dev/disk/by-label/cidata /mnt/lima-cidata

pkg/hostagent/requirements.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ func (a *HostAgent) waitForRequirements(ctx context.Context, label string, requi
2626
a.l.Infof("The %s requirement %d of %d is satisfied", label, i+1, len(requirements))
2727
break retryLoop
2828
}
29+
if req.fatal {
30+
a.l.Infof("No further %s requirements will be checked", label)
31+
return multierror.Append(mErr,
32+
errors.Wrapf(err, "failed to satisfy the %s requirement %d of %d %q: %s; skipping further checks",
33+
label, i+1, len(requirements), req.description, req.debugHint))
34+
}
2935
if j == retries-1 {
3036
mErr = multierror.Append(mErr,
3137
errors.Wrapf(err, "failed to satisfy the %s requirement %d of %d %q: %s",
@@ -52,6 +58,7 @@ type requirement struct {
5258
description string
5359
script string
5460
debugHint string
61+
fatal bool
5562
}
5663

5764
func (a *HostAgent) essentialRequirements() []requirement {
@@ -117,20 +124,37 @@ A possible workaround is to run "lima-guestagent install-systemd" in the guest.
117124
func (a *HostAgent) optionalRequirements() []requirement {
118125
req := make([]requirement, 0)
119126
if *a.y.Containerd.System || *a.y.Containerd.User {
120-
req = append(req, requirement{
121-
description: "containerd binaries to be installed",
122-
script: `#!/bin/bash
127+
req = append(req,
128+
requirement{
129+
description: "systemd must be available",
130+
fatal: true,
131+
script: `#!/bin/bash
132+
set -eux -o pipefail
133+
if ! command -v systemctl 2>&1 >/dev/null; then
134+
echo >&2 "systemd is not available on this OS"
135+
exit 1
136+
fi
137+
`,
138+
debugHint: `systemd is required to run containerd, but does not seem to be available.
139+
Make sure that you use an image that supports systemd. If you do not want to run
140+
containerd, please make sure that both 'container.system' and 'containerd.user'
141+
are set to 'false' in the config file.
142+
`,
143+
},
144+
requirement{
145+
description: "containerd binaries to be installed",
146+
script: `#!/bin/bash
123147
set -eux -o pipefail
124148
if ! timeout 30s bash -c "until command -v nerdctl; do sleep 3; done"; then
125149
echo >&2 "nerdctl is not installed yet"
126150
exit 1
127151
fi
128152
`,
129-
debugHint: `The nerdctl binary was not installed in the guest.
153+
debugHint: `The nerdctl binary was not installed in the guest.
130154
Make sure that you are using an officially supported image.
131155
Also see "/var/log/cloud-init-output.log" in the guest.
132156
`,
133-
})
157+
})
134158
}
135159
for _, probe := range a.y.Probes {
136160
if probe.Mode == limayaml.ProbeModeReadiness {

0 commit comments

Comments
 (0)