Skip to content

Commit

Permalink
Always remove empty ca_certs struct
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Aug 31, 2024
1 parent 83b7c7b commit 39bad01
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pkg/cidata/cidata.TEMPLATE.d/user-data
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ resolv_conf:
{{- end }}
{{- end }}

{{- if .CACerts.RemoveDefaults }}
{{ with .CACerts }}
ca_certs:
remove_defaults: {{ .RemoveDefaults }}
Expand All @@ -76,6 +77,7 @@ ca_certs:
{{- range $line := $cert.Lines }}
{{ $line }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Expand Down
5 changes: 5 additions & 0 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ func templateArgs(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort, t
args.CACerts.Trusted = append(args.CACerts.Trusted, cert)
}

if !*args.CACerts.RemoveDefaults && len(args.CACerts.Trusted) == 0 {
args.CACerts.RemoveDefaults = nil
args.CACerts.Trusted = nil
}

args.BootCmds = getBootCmds(y.Provision)

for _, f := range y.Provision {
Expand Down
9 changes: 0 additions & 9 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,13 @@ func ValidateTemplateArgs(args *TemplateArgs) error {
return fmt.Errorf("field mounts[%d] must be absolute, got %q", i, f)
}
}
if args.CACerts.RemoveDefaults == nil {
return errors.New("field CACerts.RemoveDefaults must be set")
}
return nil
}

func ExecuteTemplateCloudConfig(args *TemplateArgs) ([]byte, error) {
if err := ValidateTemplateArgs(args); err != nil {
return nil, err
}
// Remove empty CACerts struct from cloud-config output
if !*args.CACerts.RemoveDefaults && len(args.CACerts.Trusted) == 0 {
temp := *args
temp.CACerts.RemoveDefaults = nil
temp.CACerts.Trusted = nil
args = &temp
}
return textutil.ExecuteTemplate(cloudConfigYaml, args)
}
Expand Down

0 comments on commit 39bad01

Please sign in to comment.