Skip to content

Commit 8ee410c

Browse files
committed
Remove empty ca_certs from cloud-config.yaml
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]>
1 parent 353d4fb commit 8ee410c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: pkg/cidata/cloud-config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ users:
3737
# resolv_conf is not included here
3838
{{- end }}
3939

40+
{{- if .CACerts.RemoveDefaults }}
4041
{{ with .CACerts }}
4142
ca_certs:
4243
remove_defaults: {{ .RemoveDefaults }}
@@ -50,6 +51,7 @@ ca_certs:
5051
{{- end }}
5152
{{- end }}
5253
{{- end }}
54+
{{- end }}
5355

5456
{{- if .BootCmds }}
5557
bootcmd:

Diff for: pkg/cidata/template.go

+7
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ func ExecuteTemplateCloudConfig(args *TemplateArgs) ([]byte, error) {
125125
if err := ValidateTemplateArgs(args); err != nil {
126126
return nil, err
127127
}
128+
// Remove empty CACerts struct from cloud-config output
129+
if !*args.CACerts.RemoveDefaults && len(args.CACerts.Trusted) == 0 {
130+
temp := *args
131+
temp.CACerts.RemoveDefaults = nil
132+
temp.CACerts.Trusted = nil
133+
args = &temp
134+
}
128135
return textutil.ExecuteTemplate(cloudConfigYaml, args)
129136
}
130137

0 commit comments

Comments
 (0)