Skip to content

Commit 93f654f

Browse files
committed
Implement readiness probes
Signed-off-by: Jan Dubois <[email protected]>
1 parent 421c040 commit 93f654f

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

pkg/hostagent/requirements.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package hostagent
22

33
import (
44
"context"
5+
"github.com/AkihiroSuda/lima/pkg/limayaml"
56
"time"
67

78
"github.com/AkihiroSuda/sshocker/pkg/ssh"
@@ -120,5 +121,14 @@ Also see "/var/log/cloud-init-output.log" in the guest.
120121
`,
121122
})
122123
}
124+
for _, probe := range a.y.Probes {
125+
if probe.Mode == limayaml.ProbeModeReadiness {
126+
req = append(req, requirement{
127+
description: probe.Description,
128+
script: probe.Script,
129+
debugHint: probe.Hint,
130+
})
131+
}
132+
}
123133
return req
124134
}

pkg/limayaml/default.TEMPLATE.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,17 @@ containerd:
8585
# set number
8686
# EOF
8787

88+
# probes:
89+
# # Only `readiness` probes are supported right now.
90+
# - mode: readiness
91+
# description: vim to be installed
92+
# script: |
93+
# #!/bin/bash
94+
# set -eux -o pipefail
95+
# if ! timeout 30s bash -c "until command -v vim; do sleep 3; done"; then
96+
# echo >&2 "vim is not installed yet"
97+
# exit 1
98+
# fi
99+
# hint: |
100+
# vim was not installed in the guest. Make sure the package system is working correctly.
101+
# Also see "/var/log/cloud-init-output.log" in the guest.

pkg/limayaml/defaults.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package limayaml
22

3-
import "runtime"
3+
import (
4+
"fmt"
5+
"runtime"
6+
)
47

58
func FillDefault(y *LimaYAML) {
69
y.Arch = resolveArch(y.Arch)
@@ -34,6 +37,15 @@ func FillDefault(y *LimaYAML) {
3437
if y.Containerd.User == nil {
3538
y.Containerd.User = &[]bool{true}[0]
3639
}
40+
for i := range y.Probes {
41+
probe := &y.Probes[i]
42+
if probe.Mode == "" {
43+
probe.Mode = ProbeModeReadiness
44+
}
45+
if probe.Description == "" {
46+
probe.Description = fmt.Sprintf("user probe %d/%d", i+1, len(y.Probes))
47+
}
48+
}
3749
}
3850

3951
func resolveArch(s string) Arch {

pkg/limayaml/limayaml.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type LimaYAML struct {
1212
Video Video `yaml:"video,omitempty"`
1313
Provision []Provision `yaml:"provision,omitempty"`
1414
Containerd Containerd `yaml:"containerd,omitempty"`
15+
Probes []Probe `yaml:"probes,omitempty"`
1516
}
1617

1718
type Arch = string
@@ -62,3 +63,16 @@ type Containerd struct {
6263
System *bool `yaml:"system,omitempty"`
6364
User *bool `yaml:"user,omitempty"`
6465
}
66+
67+
type ProbeMode = string
68+
69+
const (
70+
ProbeModeReadiness ProbeMode = "readiness"
71+
)
72+
73+
type Probe struct {
74+
Mode ProbeMode // default: "readiness"
75+
Description string
76+
Script string
77+
Hint string
78+
}

pkg/limayaml/validate.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ func ValidateRaw(y LimaYAML) error {
111111
i, ProvisionModeSystem, ProvisionModeUser)
112112
}
113113
}
114-
114+
for i, p := range y.Probes {
115+
switch p.Mode {
116+
case ProbeModeReadiness:
117+
default:
118+
return errors.Errorf("field `probe[%d].mode` can only be %q",
119+
i, ProbeModeReadiness)
120+
}
121+
}
115122
return nil
116123
}

0 commit comments

Comments
 (0)