Skip to content

Commit dca304d

Browse files
sbueringerpierreprinetti
authored andcommitted
fix generate-yaml by escaping newlines (kubernetes-sigs#404)
We had a problem with generate-yaml.sh because yq rejected the invalid YAML. To work around this we have to make sure the master.yaml is also a valid YAML. So functions like Indent are no option. One option to solve this would have been base64Encode, but the problem is that Ignition has no property to specify that the inline content is base64 encoded. The only would have been `inline: !! binary |`, but then yq complains that {{ .CaCert | Base64Encode }} is not correctly encoded. So the solution was to just replace the new lines with \n
1 parent ec9bdac commit dca304d

File tree

2 files changed

+14
-17
lines changed
  • cmd/clusterctl/examples/openstack/provider-component/user-data/coreos/templates
  • pkg/cloud/openstack/services/userdata

2 files changed

+14
-17
lines changed

cmd/clusterctl/examples/openstack/provider-component/user-data/coreos/templates/master.yaml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ storage:
99
id: 0
1010
mode: 0640
1111
contents:
12-
inline: |
13-
{{ .CACert | Indent 10}}
12+
inline: "{{ .CACert | EscapeNewLines }}"
1413

1514
- path: /etc/kubernetes/pki/ca.key
1615
filesystem: root
@@ -20,8 +19,7 @@ storage:
2019
id: 0
2120
mode: 0600
2221
contents:
23-
inline: |
24-
{{ .CAKey | Indent 10}}
22+
inline: "{{ .CAKey | EscapeNewLines }}"
2523

2624
- path: /etc/kubernetes/pki/etcd/ca.crt
2725
filesystem: root
@@ -31,8 +29,7 @@ storage:
3129
id: 0
3230
mode: 0640
3331
contents:
34-
inline: |
35-
{{ .EtcdCACert | Indent 10}}
32+
inline: "{{ .EtcdCACert | EscapeNewLines }}"
3633

3734
- path: /etc/kubernetes/pki/etcd/ca.key
3835
filesystem: root
@@ -42,8 +39,7 @@ storage:
4239
id: 0
4340
mode: 0600
4441
contents:
45-
inline: |
46-
{{ .EtcdCAKey | Indent 10}}
42+
inline: "{{ .EtcdCAKey | EscapeNewLines }}"
4743

4844
- path: /etc/kubernetes/pki/front-proxy-ca.crt
4945
filesystem: root
@@ -53,8 +49,7 @@ storage:
5349
id: 0
5450
mode: 0640
5551
contents:
56-
inline: |
57-
{{ .FrontProxyCACert | Indent 10}}
52+
inline: "{{ .FrontProxyCACert | EscapeNewLines }}"
5853

5954
- path: /etc/kubernetes/pki/front-proxy-ca.key
6055
filesystem: root
@@ -64,8 +59,7 @@ storage:
6459
id: 0
6560
mode: 0600
6661
contents:
67-
inline: |
68-
{{ .FrontProxyCAKey | Indent 10}}
62+
inline: "{{ .FrontProxyCAKey | EscapeNewLines }}"
6963

7064
- path: /etc/kubernetes/pki/sa.pub
7165
filesystem: root
@@ -75,8 +69,7 @@ storage:
7569
id: 0
7670
mode: 0640
7771
contents:
78-
inline: |
79-
{{ .SaCert | Indent 10}}
72+
inline: "{{ .SaCert | EscapeNewLines }}"
8073

8174
- path: /etc/kubernetes/pki/sa.key
8275
filesystem: root
@@ -86,8 +79,7 @@ storage:
8679
id: 0
8780
mode: 0600
8881
contents:
89-
inline: |
90-
{{ .SaKey | Indent 10}}
82+
inline: "{{ .SaKey | EscapeNewLines }}"
9183

9284

9385
- path: /etc/kubernetes/kubeadm_config.yaml

pkg/cloud/openstack/services/userdata/machinescript.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ func masterStartupScript(cluster *clusterv1.Cluster, machine *clusterv1.Machine,
289289
}
290290

291291
fMap := map[string]interface{}{
292-
"Indent": templateYAMLIndent,
292+
"EscapeNewLines": templateEscapeNewLines,
293+
"Indent": templateYAMLIndent,
293294
}
294295

295296
masterStartUpScript := template.Must(template.New("masterStartUp").Funcs(fMap).Parse(script))
@@ -368,6 +369,10 @@ func getSubnet(netRange clusterv1.NetworkRanges) string {
368369
return netRange.CIDRBlocks[0]
369370
}
370371

372+
func templateEscapeNewLines(s string) string {
373+
return strings.ReplaceAll(s, "\n", "\\n")
374+
}
375+
371376
func templateYAMLIndent(i int, input string) string {
372377
split := strings.Split(input, "\n")
373378
ident := "\n" + strings.Repeat(" ", i)

0 commit comments

Comments
 (0)