Skip to content

Commit 89b92e3

Browse files
committed
Use the same template for cloud-config
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 0ec3173 commit 89b92e3

File tree

4 files changed

+18
-70
lines changed

4 files changed

+18
-70
lines changed

pkg/cidata/cidata.TEMPLATE.d/user-data

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ users:
3939
- {{ printf "%q" $val }}
4040
{{- end }}
4141

42+
{{- if .BootScripts }}
4243
write_files:
4344
- content: |
4445
#!/bin/sh
@@ -52,6 +53,7 @@ write_files:
5253
owner: root:root
5354
path: /var/lib/cloud/scripts/per-boot/00-lima.boot.sh
5455
permissions: '0755'
56+
{{- end }}
5557

5658
{{- if .DNSAddresses }}
5759
# This has no effect on systems using systemd-resolved, but is used

pkg/cidata/cidata.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func setupEnv(y *limayaml.LimaYAML, args TemplateArgs) (map[string]string, error
111111
return env, nil
112112
}
113113

114-
func templateArgs(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string) (*TemplateArgs, error) {
114+
func templateArgs(bootScripts bool, instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string) (*TemplateArgs, error) {
115115
if err := limayaml.Validate(y, false); err != nil {
116116
return nil, err
117117
}
@@ -124,6 +124,7 @@ func templateArgs(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort, t
124124
return nil, err
125125
}
126126
args := TemplateArgs{
127+
BootScripts: bootScripts,
127128
Name: name,
128129
User: u.Username,
129130
UID: uid,
@@ -327,10 +328,14 @@ func templateArgs(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort, t
327328
}
328329

329330
func GenerateCloudConfig(instDir, name string, y *limayaml.LimaYAML) error {
330-
args, err := templateArgs(instDir, name, y, 0, 0, 0, "")
331+
args, err := templateArgs(false, instDir, name, y, 0, 0, 0, "")
331332
if err != nil {
332333
return err
333334
}
335+
// mounts are not included here
336+
args.Mounts = nil
337+
// resolv_conf is not included here
338+
args.DNSAddresses = nil
334339

335340
if err := ValidateTemplateArgs(args); err != nil {
336341
return err
@@ -345,7 +350,7 @@ func GenerateCloudConfig(instDir, name string, y *limayaml.LimaYAML) error {
345350
}
346351

347352
func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, nerdctlArchive string, vsockPort int, virtioPort string) error {
348-
args, err := templateArgs(instDir, name, y, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort)
353+
args, err := templateArgs(true, instDir, name, y, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort)
349354
if err != nil {
350355
return err
351356
}

pkg/cidata/cloud-config.yaml

-64
This file was deleted.

pkg/cidata/cloud-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cidata.TEMPLATE.d/user-data

pkg/cidata/template.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ var templateFS embed.FS
1919

2020
const templateFSRoot = "cidata.TEMPLATE.d"
2121

22-
//go:embed cloud-config.yaml
23-
var cloudConfigYaml string
24-
2522
type CACerts struct {
2623
RemoveDefaults *bool
2724
Trusted []Cert
@@ -76,6 +73,7 @@ type TemplateArgs struct {
7673
UDPDNSLocalPort int
7774
TCPDNSLocalPort int
7875
Env map[string]string
76+
BootScripts bool
7977
DNSAddresses []string
8078
CACerts CACerts
8179
HostHomeMountPoint string
@@ -122,7 +120,13 @@ func ExecuteTemplateCloudConfig(args *TemplateArgs) ([]byte, error) {
122120
if err := ValidateTemplateArgs(args); err != nil {
123121
return nil, err
124122
}
123+
124+
userData, err := templateFS.ReadFile(path.Join(templateFSRoot, "user-data"))
125+
if err != nil {
126+
return nil, err
125127
}
128+
129+
cloudConfigYaml := string(userData)
126130
return textutil.ExecuteTemplate(cloudConfigYaml, args)
127131
}
128132

0 commit comments

Comments
 (0)