File tree Expand file tree Collapse file tree 3 files changed +41
-9
lines changed
bootstrap/eks/internal/userdata Expand file tree Collapse file tree 3 files changed +41
-9
lines changed Original file line number Diff line number Diff line change 9797 {{- end }}
9898 kubelet:
9999 {{- if .KubeletConfig }}
100- config: |
101- {{ Indent 6 .KubeletConfig }}
100+ config:
101+ {{ Indent 6 (toYaml .KubeletConfig) }}
102102 {{- end }}
103103 flags:
104104 {{- range $flag := .KubeletFlags }}
@@ -107,12 +107,12 @@ spec:
107107 {{- if or .ContainerdConfig .ContainerdBaseRuntimeSpec }}
108108 containerd:
109109 {{- if .ContainerdConfig }}
110- config: |
110+ config:
111111{{ Indent 6 .ContainerdConfig }}
112112 {{- end }}
113113 {{- if .ContainerdBaseRuntimeSpec }}
114- baseRuntimeSpec: |
115- {{ Indent 6 .ContainerdBaseRuntimeSpec}}
114+ baseRuntimeSpec:
115+ {{ Indent 6 (toYaml .ContainerdBaseRuntimeSpec) }}
116116 {{- end }}
117117 {{- end }}
118118 {{- if .Instance }}
@@ -238,7 +238,6 @@ func validateNodeadmInput(input *NodeadmInput) error {
238238 if input .NodeGroupName == "" {
239239 return fmt .Errorf ("node group name is required for nodeadm" )
240240 }
241-
242241 if input .Boundary == "" {
243242 input .Boundary = boundary
244243 }
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import (
2323
2424 . "github.com/onsi/gomega"
2525 "github.com/onsi/gomega/format"
26+ "k8s.io/apimachinery/pkg/runtime"
2627 "k8s.io/utils/ptr"
2728
2829 eksbootstrapv1 "sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2"
@@ -168,11 +169,12 @@ func TestNodeadmUserdata(t *testing.T) {
168169 APIServerEndpoint : "https://example.com" ,
169170 CACert : "test-ca-cert" ,
170171 NodeGroupName : "test-nodegroup" ,
171- KubeletConfig : `
172+ KubeletConfig : & runtime.RawExtension {
173+ Raw : []byte (`
172174evictionHard:
173175 memory.available: "2000Mi"
174-
175- ` ,
176+ ` ),
177+ } ,
176178 },
177179 },
178180 expectErr : false ,
Original file line number Diff line number Diff line change @@ -17,13 +17,19 @@ limitations under the License.
1717package userdata
1818
1919import (
20+ "fmt"
2021 "strings"
2122 "text/template"
23+
24+ "github.com/pkg/errors"
25+ "k8s.io/apimachinery/pkg/runtime"
26+ "sigs.k8s.io/yaml"
2227)
2328
2429var (
2530 defaultTemplateFuncMap = template.FuncMap {
2631 "Indent" : templateYAMLIndent ,
32+ "toYaml" : templateToYAML ,
2733 }
2834)
2935
@@ -32,3 +38,28 @@ func templateYAMLIndent(i int, input string) string {
3238 ident := "\n " + strings .Repeat (" " , i )
3339 return strings .Repeat (" " , i ) + strings .Join (split , ident )
3440}
41+
42+ func templateToYAML (r * runtime.RawExtension ) (string , error ) {
43+ if r == nil {
44+ return "" , nil
45+ }
46+ if r .Object != nil {
47+ b , err := yaml .Marshal (r .Object )
48+ if err != nil {
49+ return "" , errors .Wrap (err , "failed to convert to yaml" )
50+ }
51+ return string (b ), nil
52+ }
53+ if len (r .Raw ) > 0 {
54+ if yb , err := yaml .JSONToYAML (r .Raw ); err == nil {
55+ return string (yb ), nil
56+ }
57+ var temp interface {}
58+ err := yaml .Unmarshal (r .Raw , & temp )
59+ if err == nil {
60+ return string (r .Raw ), nil
61+ }
62+ return "" , fmt .Errorf ("runtime object raw is neither json nor yaml %s" , string (r .Raw ))
63+ }
64+ return "" , nil
65+ }
You can’t perform that action at this time.
0 commit comments