Skip to content

Commit 02e8126

Browse files
committed
write_files: nil is invalid cloud-config
skip this field entirely if no files are given
1 parent 04a4f62 commit 02e8126

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

bootstrap/eks/internal/userdata/node.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const (
3030
defaultBootstrapCommand = "/etc/eks/bootstrap.sh"
3131

3232
nodeUserData = `#cloud-config
33+
{{- if .Files }}
3334
{{template "files" .Files}}
35+
{{- end }}
3436
runcmd:
3537
{{- template "commands" .PreBootstrapCommands }}
3638
- {{ .BootstrapCommand }} {{.ClusterName}} {{- template "args" . }}

bootstrap/eks/internal/userdata/node_test.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func TestNewNode(t *testing.T) {
4949
},
5050
},
5151
expectedBytes: []byte(`#cloud-config
52-
write_files:
5352
runcmd:
5453
- /etc/eks/bootstrap.sh test-cluster
5554
`),
@@ -67,7 +66,6 @@ runcmd:
6766
},
6867
},
6968
expectedBytes: []byte(`#cloud-config
70-
write_files:
7169
runcmd:
7270
- /etc/eks/bootstrap.sh test-cluster --kubelet-extra-args '--node-labels=node-role.undistro.io/infra=true --register-with-taints=dedicated=infra:NoSchedule'
7371
`),
@@ -81,7 +79,6 @@ runcmd:
8179
},
8280
},
8381
expectedBytes: []byte(`#cloud-config
84-
write_files:
8582
runcmd:
8683
- /etc/eks/bootstrap.sh test-cluster --container-runtime containerd
8784
`),
@@ -99,7 +96,6 @@ runcmd:
9996
},
10097
},
10198
expectedBytes: []byte(`#cloud-config
102-
write_files:
10399
runcmd:
104100
- /etc/eks/bootstrap.sh test-cluster --kubelet-extra-args '--node-labels=node-role.undistro.io/infra=true --register-with-taints=dedicated=infra:NoSchedule' --container-runtime containerd
105101
`),
@@ -114,7 +110,6 @@ runcmd:
114110
},
115111
},
116112
expectedBytes: []byte(`#cloud-config
117-
write_files:
118113
runcmd:
119114
- /etc/eks/bootstrap.sh test-cluster --ip-family ipv6 --service-ipv6-cidr fe80:0000:0000:0000:0204:61ff:fe9d:f156/24
120115
`),
@@ -128,7 +123,6 @@ runcmd:
128123
},
129124
},
130125
expectedBytes: []byte(`#cloud-config
131-
write_files:
132126
runcmd:
133127
- /etc/eks/bootstrap.sh test-cluster --use-max-pods false
134128
`),
@@ -142,7 +136,6 @@ runcmd:
142136
},
143137
},
144138
expectedBytes: []byte(`#cloud-config
145-
write_files:
146139
runcmd:
147140
- /etc/eks/bootstrap.sh test-cluster --aws-api-retry-attempts 5
148141
`),
@@ -157,7 +150,6 @@ runcmd:
157150
},
158151
},
159152
expectedBytes: []byte(`#cloud-config
160-
write_files:
161153
runcmd:
162154
- /etc/eks/bootstrap.sh test-cluster --pause-container-account 12345678 --pause-container-version v1
163155
`),
@@ -171,7 +163,6 @@ runcmd:
171163
},
172164
},
173165
expectedBytes: []byte(`#cloud-config
174-
write_files:
175166
runcmd:
176167
- /etc/eks/bootstrap.sh test-cluster --dns-cluster-ip 192.168.0.1
177168
`),
@@ -185,7 +176,6 @@ runcmd:
185176
},
186177
},
187178
expectedBytes: []byte(`#cloud-config
188-
write_files:
189179
runcmd:
190180
- /etc/eks/bootstrap.sh test-cluster --docker-config-json '{"debug":true}'
191181
`),
@@ -199,7 +189,6 @@ runcmd:
199189
},
200190
},
201191
expectedBytes: []byte(`#cloud-config
202-
write_files:
203192
runcmd:
204193
- "date"
205194
- "echo \"testing\""
@@ -215,7 +204,6 @@ runcmd:
215204
},
216205
},
217206
expectedBytes: []byte(`#cloud-config
218-
write_files:
219207
runcmd:
220208
- /etc/eks/bootstrap.sh test-cluster
221209
- "date"
@@ -232,7 +220,6 @@ runcmd:
232220
},
233221
},
234222
expectedBytes: []byte(`#cloud-config
235-
write_files:
236223
runcmd:
237224
- "echo \"testing pre\""
238225
- /etc/eks/bootstrap.sh test-cluster
@@ -248,7 +235,6 @@ runcmd:
248235
},
249236
},
250237
expectedBytes: []byte(`#cloud-config
251-
write_files:
252238
runcmd:
253239
- /custom/mybootstrap.sh test-cluster
254240
`),
@@ -280,7 +266,6 @@ runcmd:
280266
},
281267
},
282268
expectedBytes: []byte(`#cloud-config
283-
write_files:
284269
runcmd:
285270
- /etc/eks/bootstrap.sh test-cluster
286271
disk_setup:
@@ -323,6 +308,31 @@ write_files:
323308
fs.inotify.max_user_instances=256
324309
runcmd:
325310
- /etc/eks/bootstrap.sh test-cluster
311+
`),
312+
},
313+
{
314+
name: "with empty files",
315+
args: args{
316+
input: &NodeInput{
317+
ClusterName: "test-cluster",
318+
Files: []eksbootstrapv1.File{},
319+
},
320+
},
321+
expectedBytes: []byte(`#cloud-config
322+
runcmd:
323+
- /etc/eks/bootstrap.sh test-cluster
324+
`),
325+
},
326+
{
327+
name: "with nil files",
328+
args: args{
329+
input: &NodeInput{
330+
ClusterName: "test-cluster",
331+
},
332+
},
333+
expectedBytes: []byte(`#cloud-config
334+
runcmd:
335+
- /etc/eks/bootstrap.sh test-cluster
326336
`),
327337
},
328338
{
@@ -337,7 +347,6 @@ runcmd:
337347
},
338348
},
339349
expectedBytes: []byte(`#cloud-config
340-
write_files:
341350
runcmd:
342351
- /etc/eks/bootstrap.sh test-cluster
343352
ntp:
@@ -363,7 +372,6 @@ ntp:
363372
},
364373
},
365374
expectedBytes: []byte(`#cloud-config
366-
write_files:
367375
runcmd:
368376
- /etc/eks/bootstrap.sh test-cluster
369377
users:

0 commit comments

Comments
 (0)