@@ -19,14 +19,12 @@ package userdata
1919import (
2020 "bytes"
2121 "fmt"
22- "strings"
2322 "text/template"
2423
2524 "k8s.io/apimachinery/pkg/runtime"
2625 "k8s.io/klog/v2"
2726
2827 eksbootstrapv1 "sigs.k8s.io/cluster-api-provider-aws/v2/bootstrap/eks/api/v1beta2"
29- "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
3028)
3129
3230const (
@@ -95,14 +93,16 @@ spec:
9593 {{$k}}: {{$v}}
9694 {{- end }}
9795 {{- end }}
96+ {{- if .KubeletConfig }}
9897 kubelet:
99- {{- if .KubeletConfig }}
10098 config:
10199{{ Indent 6 (toYaml .KubeletConfig) }}
102100 {{- end }}
101+ {{- if .KubeletFlags }}
103102 flags:
104- {{- range $flag := .KubeletFlags }}
105- - "{{$flag}}"
103+ {{- range $flag := .KubeletFlags }}
104+ - "{{$flag}}"
105+ {{- end }}
106106 {{- end }}
107107 {{- if or .ContainerdConfig .ContainerdBaseRuntimeSpec }}
108108 containerd:
@@ -133,10 +133,6 @@ spec:
133133 {{- end }}
134134
135135--{{.Boundary}}`
136-
137- nodeLabelImage = "eks.amazonaws.com/nodegroup-image"
138- nodeLabelNodeGroup = "eks.amazonaws.com/nodegroup"
139- nodeLabelCapacityType = "eks.amazonaws.com/capacityType"
140136)
141137
142138// NodeadmInput contains all the information required to generate user data for a node.
@@ -160,68 +156,8 @@ type NodeadmInput struct {
160156 APIServerEndpoint string
161157 Boundary string
162158 CACert string
163- CapacityType * v1beta2.ManagedMachinePoolCapacityType
164159 ServiceCIDR string // Service CIDR range for the cluster
165160 ClusterDNS string
166- NodeGroupName string
167- NodeLabels string // Not exposed in CRD, computed from user input
168- }
169-
170- func (input * NodeadmInput ) setKubeletFlags () error {
171- var nodeLabels string
172- newFlags := []string {}
173- for _ , flag := range input .KubeletFlags {
174- if strings .HasPrefix (flag , "--node-labels=" ) {
175- nodeLabels = strings .TrimPrefix (flag , "--node-labels=" )
176- } else {
177- newFlags = append (newFlags , flag )
178- }
179- }
180- labelsMap := make (map [string ]string )
181- if nodeLabels != "" {
182- labels := strings .Split (nodeLabels , "," )
183- for _ , label := range labels {
184- labelSplit := strings .Split (label , "=" )
185- if len (labelSplit ) != 2 {
186- return fmt .Errorf ("invalid label: %s" , label )
187- }
188- labelKey := labelSplit [0 ]
189- labelValue := labelSplit [1 ]
190- labelsMap [labelKey ] = labelValue
191- }
192- }
193- if _ , ok := labelsMap [nodeLabelImage ]; ! ok && input .AMIImageID != "" {
194- labelsMap [nodeLabelImage ] = input .AMIImageID
195- }
196- if _ , ok := labelsMap [nodeLabelNodeGroup ]; ! ok && input .NodeGroupName != "" {
197- labelsMap [nodeLabelNodeGroup ] = input .NodeGroupName
198- }
199- if _ , ok := labelsMap [nodeLabelCapacityType ]; ! ok {
200- labelsMap [nodeLabelCapacityType ] = input .getCapacityTypeString ()
201- }
202- stringBuilder := strings.Builder {}
203- for key , value := range labelsMap {
204- stringBuilder .WriteString (fmt .Sprintf ("%s=%s," , key , value ))
205- }
206- newLabels := stringBuilder .String ()[:len (stringBuilder .String ())- 1 ] // remove the last comma
207- newFlags = append (newFlags , fmt .Sprintf ("--node-labels=%s" , newLabels ))
208- input .KubeletFlags = newFlags
209- return nil
210- }
211-
212- // getCapacityTypeString returns the string representation of the capacity type.
213- func (input * NodeadmInput ) getCapacityTypeString () string {
214- if input .CapacityType == nil {
215- return "ON_DEMAND"
216- }
217- switch * input .CapacityType {
218- case v1beta2 .ManagedMachinePoolCapacityTypeSpot :
219- return "SPOT"
220- case v1beta2 .ManagedMachinePoolCapacityTypeOnDemand :
221- return "ON_DEMAND"
222- default :
223- return strings .ToUpper (string (* input .CapacityType ))
224- }
225161}
226162
227163// validateNodeInput validates the input for nodeadm user data generation.
@@ -235,18 +171,11 @@ func validateNodeadmInput(input *NodeadmInput) error {
235171 if input .ClusterName == "" {
236172 return fmt .Errorf ("cluster name is required for nodeadm" )
237173 }
238- if input .NodeGroupName == "" {
239- return fmt .Errorf ("node group name is required for nodeadm" )
240- }
241174 if input .Boundary == "" {
242175 input .Boundary = boundary
243176 }
244- err := input .setKubeletFlags ()
245- if err != nil {
246- return err
247- }
248177
249- klog .V (2 ).Infof ("Nodeadm Userdata Generation - node-labels: %s " , input . NodeLabels )
178+ klog .V (2 ).Infof ("Nodeadm Userdata Generation %v " , input )
250179
251180 return nil
252181}
0 commit comments