Skip to content

Commit bc198f4

Browse files
authored
Merge pull request #4227 from vax-r/probe_provision
Make Probe.Script a pointer
2 parents 7335cd2 + 511feca commit bc198f4

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

pkg/hostagent/requirements.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ Also see "/var/log/cloud-init-output.log" in the guest.
241241
if probe.Mode == limatype.ProbeModeReadiness {
242242
req = append(req, requirement{
243243
description: probe.Description,
244-
script: probe.Script,
244+
script: *probe.Script,
245245
debugHint: probe.Hint,
246246
})
247247
}

pkg/limatmpl/embed.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ func (tmpl *Template) embedAllScripts(ctx context.Context, embedAll bool) error
634634
continue
635635
}
636636
// Don't overwrite existing script. This should throw an error during validation.
637-
if p.Script != "" {
637+
if p.Script == nil || *p.Script != "" {
638638
continue
639639
}
640640
isTemplate, _ := SeemsTemplateURL(p.File.URL)

pkg/limatype/lima_yaml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const (
271271
type Probe struct {
272272
Mode ProbeMode `yaml:"mode,omitempty" json:"mode,omitempty" jsonschema:"default=readiness"`
273273
Description string `yaml:"description,omitempty" json:"description,omitempty"`
274-
Script string `yaml:"script,omitempty" json:"script,omitempty"`
274+
Script *string `yaml:"script,omitempty" json:"script,omitempty"`
275275
File *LocatorWithDigest `yaml:"file,omitempty" json:"file,omitempty" jsonschema:"nullable"`
276276
Hint string `yaml:"hint,omitempty" json:"hint,omitempty"`
277277
}

pkg/limayaml/defaults.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,10 @@ func FillDefault(ctx context.Context, y, d, o *limatype.LimaYAML, filePath strin
439439
provision.Permissions = ptr.Of("644")
440440
}
441441
}
442-
if provision.Script != nil && *provision.Script != "" {
442+
if provision.Script == nil {
443+
provision.Script = ptr.Of("")
444+
}
445+
if *provision.Script != "" {
443446
if out, err := executeGuestTemplate(*provision.Script, instDir, y.User, y.Param); err == nil {
444447
*provision.Script = out.String()
445448
} else {
@@ -512,10 +515,13 @@ func FillDefault(ctx context.Context, y, d, o *limatype.LimaYAML, filePath strin
512515
if probe.Description == "" {
513516
probe.Description = fmt.Sprintf("user probe %d/%d", i+1, len(y.Probes))
514517
}
515-
if out, err := executeGuestTemplate(probe.Script, instDir, y.User, y.Param); err == nil {
516-
probe.Script = out.String()
518+
if probe.Script == nil {
519+
probe.Script = ptr.Of("")
520+
}
521+
if out, err := executeGuestTemplate(*probe.Script, instDir, y.User, y.Param); err == nil {
522+
probe.Script = ptr.Of(out.String())
517523
} else {
518-
logrus.WithError(err).Warnf("Couldn't process probing script %q as a template", probe.Script)
524+
logrus.WithError(err).Warnf("Couldn't process probing script %q as a template", *probe.Script)
519525
}
520526
}
521527

pkg/limayaml/defaults_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestFillDefault(t *testing.T) {
154154
{Script: ptr.Of("#!/bin/true # {{.Param.ONE}}")},
155155
},
156156
Probes: []limatype.Probe{
157-
{Script: "#!/bin/false # {{.Param.ONE}}"},
157+
{Script: ptr.Of("#!/bin/false # {{.Param.ONE}}")},
158158
},
159159
Networks: []limatype.Network{
160160
{Lima: "shared"},
@@ -240,7 +240,7 @@ func TestFillDefault(t *testing.T) {
240240
expect.Probes = slices.Clone(y.Probes)
241241
expect.Probes[0].Mode = limatype.ProbeModeReadiness
242242
expect.Probes[0].Description = "user probe 1/1"
243-
expect.Probes[0].Script = "#!/bin/false # Eins"
243+
expect.Probes[0].Script = ptr.Of("#!/bin/false # Eins")
244244

245245
expect.Networks = slices.Clone(y.Networks)
246246
expect.Networks[0].MACAddress = MACAddress(fmt.Sprintf("%s#%d", filePath, 0))
@@ -371,7 +371,7 @@ func TestFillDefault(t *testing.T) {
371371
},
372372
Probes: []limatype.Probe{
373373
{
374-
Script: "#!/bin/false",
374+
Script: ptr.Of("#!/bin/false"),
375375
Mode: limatype.ProbeModeReadiness,
376376
Description: "User Probe",
377377
},
@@ -580,7 +580,7 @@ func TestFillDefault(t *testing.T) {
580580
},
581581
Probes: []limatype.Probe{
582582
{
583-
Script: "#!/bin/false",
583+
Script: ptr.Of("#!/bin/false"),
584584
Mode: limatype.ProbeModeReadiness,
585585
Description: "Another Probe",
586586
},

pkg/limayaml/validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func Validate(y *limatype.LimaYAML, warn bool) error {
274274
errs = errors.Join(errs, fmt.Errorf("field `probe[%d].file.digest` support is not yet implemented", i))
275275
}
276276
}
277-
if !strings.HasPrefix(p.Script, "#!") {
277+
if p.Script != nil && !strings.HasPrefix(*p.Script, "#!") {
278278
errs = errors.Join(errs, fmt.Errorf("field `probe[%d].script` must start with a '#!' line", i))
279279
}
280280
switch p.Mode {
@@ -541,7 +541,7 @@ func validateParamIsUsed(y *limatype.LimaYAML) error {
541541
}
542542
}
543543
for _, p := range y.Probes {
544-
if re.MatchString(p.Script) {
544+
if p.Script != nil && re.MatchString(*p.Script) {
545545
keyIsUsed = true
546546
break
547547
}

0 commit comments

Comments
 (0)