Skip to content

Commit

Permalink
Remove empty ca_certs from cloud-config.yaml
Browse files Browse the repository at this point in the history
Since it is a pointer, it is always true (non-nil).

And structs are always true, so they can't be tested.

Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Jun 29, 2024
1 parent 353d4fb commit 8ee410c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/cidata/cloud-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ users:
# resolv_conf is not included here
{{- end }}

{{- if .CACerts.RemoveDefaults }}
{{ with .CACerts }}
ca_certs:
remove_defaults: {{ .RemoveDefaults }}
Expand All @@ -50,6 +51,7 @@ ca_certs:
{{- end }}
{{- end }}
{{- end }}
{{- end }}

{{- if .BootCmds }}
bootcmd:
Expand Down
7 changes: 7 additions & 0 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ 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 8ee410c

Please sign in to comment.