Skip to content
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
4 changes: 2 additions & 2 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name strin
case limatype.ProvisionModeSystem, limatype.ProvisionModeUser, limatype.ProvisionModeDependency:
layout = append(layout, iso9660util.Entry{
Path: fmt.Sprintf("provision.%s/%08d", f.Mode, i),
Reader: strings.NewReader(f.Script),
Reader: strings.NewReader(*f.Script),
})
case limatype.ProvisionModeData:
layout = append(layout, iso9660util.Entry{
Expand Down Expand Up @@ -490,7 +490,7 @@ func getBootCmds(p []limatype.Provision) []BootCmds {
for _, f := range p {
if f.Mode == limatype.ProvisionModeBoot {
lines := []string{}
for _, line := range strings.Split(f.Script, "\n") {
for _, line := range strings.Split(*f.Script, "\n") {
if line == "" {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/limatmpl/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ func (tmpl *Template) embedAllScripts(ctx context.Context, embedAll bool) error
continue
}
default:
if p.Script != "" {
if p.Script != nil && *p.Script != "" {
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/limatype/lima_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const (
type Provision struct {
Mode ProvisionMode `yaml:"mode,omitempty" json:"mode,omitempty" jsonschema:"default=system"`
SkipDefaultDependencyResolution *bool `yaml:"skipDefaultDependencyResolution,omitempty" json:"skipDefaultDependencyResolution,omitempty"`
Script string `yaml:"script,omitempty" json:"script,omitempty"`
Script *string `yaml:"script,omitempty" json:"script,omitempty"`
File *LocatorWithDigest `yaml:"file,omitempty" json:"file,omitempty" jsonschema:"nullable"`
Playbook string `yaml:"playbook,omitempty" json:"playbook,omitempty"` // DEPRECATED
// All ProvisionData fields must be nil unless Mode is ProvisionModeData
Expand Down
9 changes: 4 additions & 5 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,11 @@ func FillDefault(ctx context.Context, y, d, o *limatype.LimaYAML, filePath strin
provision.Permissions = ptr.Of("644")
}
}
// TODO Turn Script into a pointer; it is a plain string for historical reasons only
if provision.Script != "" {
if out, err := executeGuestTemplate(provision.Script, instDir, y.User, y.Param); err == nil {
provision.Script = out.String()
if provision.Script != nil && *provision.Script != "" {
if out, err := executeGuestTemplate(*provision.Script, instDir, y.User, y.Param); err == nil {
*provision.Script = out.String()
} else {
logrus.WithError(err).Warnf("Couldn't process provisioning script %q as a template", provision.Script)
logrus.WithError(err).Warnf("Couldn't process provisioning script %q as a template", *provision.Script)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestFillDefault(t *testing.T) {
},
MountType: ptr.Of(limatype.NINEP),
Provision: []limatype.Provision{
{Script: "#!/bin/true # {{.Param.ONE}}"},
{Script: ptr.Of("#!/bin/true # {{.Param.ONE}}")},
},
Probes: []limatype.Probe{
{Script: "#!/bin/false # {{.Param.ONE}}"},
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestFillDefault(t *testing.T) {

expect.Provision = slices.Clone(y.Provision)
expect.Provision[0].Mode = limatype.ProvisionModeSystem
expect.Provision[0].Script = "#!/bin/true # Eins"
expect.Provision[0].Script = ptr.Of("#!/bin/true # Eins")

expect.Probes = slices.Clone(y.Probes)
expect.Probes[0].Mode = limatype.ProbeModeReadiness
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestFillDefault(t *testing.T) {
},
Provision: []limatype.Provision{
{
Script: "#!/bin/true",
Script: ptr.Of("#!/bin/true"),
Mode: limatype.ProvisionModeUser,
},
},
Expand Down Expand Up @@ -572,7 +572,7 @@ func TestFillDefault(t *testing.T) {
MountInotify: ptr.Of(true),
Provision: []limatype.Provision{
{
Script: "#!/bin/true",
Script: ptr.Of("#!/bin/true"),
Mode: limatype.ProvisionModeSystem,
},
},
Expand Down
12 changes: 7 additions & 5 deletions pkg/limayaml/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func Validate(y *limatype.LimaYAML, warn bool) error {
errs = errors.Join(errs, fmt.Errorf("field `provision[%d].permissions` must be an octal number: %w", i, err))
}
default:
if p.Script == "" && p.Mode != limatype.ProvisionModeAnsible {
if (p.Script == nil || *p.Script == "") && p.Mode != limatype.ProvisionModeAnsible {
errs = errors.Join(errs, fmt.Errorf("field `provision[%d].script` must not be empty", i))
}
if p.Content != nil {
Expand All @@ -238,7 +238,7 @@ func Validate(y *limatype.LimaYAML, warn bool) error {
if p.Mode != limatype.ProvisionModeAnsible {
errs = errors.Join(errs, fmt.Errorf("field `provision[%d].playbook can only be set when mode is %q", i, limatype.ProvisionModeAnsible))
}
if p.Script != "" {
if p.Script != nil && *p.Script != "" {
errs = errors.Join(errs, fmt.Errorf("field `provision[%d].script must be empty if playbook is set", i))
}
playbook := p.Playbook
Expand All @@ -247,8 +247,10 @@ func Validate(y *limatype.LimaYAML, warn bool) error {
}
logrus.Warnf("provision mode %q is deprecated, use `ansible-playbook %q` instead", limatype.ProvisionModeAnsible, playbook)
}
if strings.Contains(p.Script, "LIMA_CIDATA") {
logrus.Warn("provisioning scripts should not reference the LIMA_CIDATA variables")
if p.Script != nil {
if strings.Contains(*p.Script, "LIMA_CIDATA") {
logrus.Warn("provisioning scripts should not reference the LIMA_CIDATA variables")
}
}
}
needsContainerdArchives := (y.Containerd.User != nil && *y.Containerd.User) || (y.Containerd.System != nil && *y.Containerd.System)
Expand Down Expand Up @@ -521,7 +523,7 @@ func validateParamIsUsed(y *limatype.LimaYAML) error {
}
keyIsUsed := false
for _, p := range y.Provision {
for _, ptr := range []*string{&p.Script, p.Content, p.Expression, p.Owner, p.Path, p.Permissions} {
for _, ptr := range []*string{p.Script, p.Content, p.Expression, p.Owner, p.Path, p.Permissions} {
if ptr != nil && re.MatchString(*ptr) {
keyIsUsed = true
break
Expand Down
Loading