Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 8e1c311

Browse files
authored
Merge pull request #280 from noamran/192
🐛 Fixes an issue where KubeadmConfig Pre/PostKubeadmCommands were not being properly escaped
2 parents 9cff8d8 + c643e8d commit 8e1c311

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

cloudinit/cloudinit_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,41 @@ func TestNewInitControlPlaneAdditionalFileEncodings(t *testing.T) {
7777
}
7878
}
7979
}
80+
81+
func TestNewInitControlPlaneCommands(t *testing.T) {
82+
cpinput := &ControlPlaneInput{
83+
BaseUserData: BaseUserData{
84+
Header: "test",
85+
PreKubeadmCommands: []string{`"echo $(date) ': hello world!'"`},
86+
PostKubeadmCommands: []string{"echo $(date) ': hello world!'"},
87+
AdditionalFiles: nil,
88+
WriteFiles: nil,
89+
Users: nil,
90+
NTP: nil,
91+
},
92+
Certificates: cluster.Certificates{},
93+
ClusterConfiguration: "my-cluster-config",
94+
InitConfiguration: "my-init-config",
95+
}
96+
97+
for _, certificate := range cpinput.Certificates {
98+
certificate.KeyPair = &certs.KeyPair{
99+
Cert: []byte("some certificate"),
100+
Key: []byte("some key"),
101+
}
102+
}
103+
104+
out, err := NewInitControlPlane(cpinput)
105+
if err != nil {
106+
t.Fatal(err)
107+
}
108+
expectedCommands := []string{
109+
`"\"echo $(date) ': hello world!'\""`,
110+
`"echo $(date) ': hello world!'"`,
111+
}
112+
for _, f := range expectedCommands {
113+
if !bytes.Contains(out, []byte(f)) {
114+
t.Errorf("%s\ndid not contain\n%s", out, f)
115+
}
116+
}
117+
}

cloudinit/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package cloudinit
1919
const (
2020
commandsTemplate = `{{- define "commands" -}}
2121
{{ range . }}
22-
- '{{.}}'
22+
- {{printf "%q" .}}
2323
{{- end -}}
2424
{{- end -}}
2525
`

0 commit comments

Comments
 (0)