@@ -87,10 +87,12 @@ spec:
8787 kubelet:
8888 config:
8989 maxPods: {{.MaxPods}}
90+ {{- with .DNSClusterIP }}
9091 clusterDNS:
91- - {{.DNSClusterIP}}
92+ - {{.}}
93+ {{- end }}
9294 flags:
93- - "--node-labels={{if and .KubeletExtraArgs (index .KubeletExtraArgs "node-labels")}}{{index .KubeletExtraArgs "node-labels"}}{{else}}eks.amazonaws.com/nodegroup-image={{if .AMIImageID}}{{.AMIImageID}}{{end}},eks.amazonaws.com/capacityType={{if .CapacityType}}{{.CapacityType}}{{else}}ON_DEMAND{{end}},eks.amazonaws.com/nodegroup={{.NodeGroupName}}{{end }}"
95+ - "--node-labels={{.NodeLabels }}"
9496
9597--{{.Boundary}}--`
9698)
@@ -123,15 +125,16 @@ type NodeInput struct {
123125 AMIFamilyType string
124126
125127 // AL2023 specific fields
128+ AMIImageID string
126129 APIServerEndpoint string
130+ Boundary string
127131 CACert string
128- NodeGroupName string
129- AMIImageID string
130132 CapacityType * v1beta2.ManagedMachinePoolCapacityType
131- MaxPods * int32
132- Boundary string
133- ClusterDNS string
134133 ClusterCIDR string // CIDR range for the cluster
134+ ClusterDNS string
135+ MaxPods * int32
136+ NodeGroupName string
137+ NodeLabels string // Not exposed in CRD, computed from user input
135138}
136139
137140// PauseContainerInfo holds pause container information for templates.
@@ -255,6 +258,24 @@ func generateAL2023UserData(input *NodeInput) ([]byte, error) {
255258 return buf .Bytes (), nil
256259}
257260
261+ // getNodeLabels returns the string representation of node-labels flags for nodeadm
262+ func (ni * NodeInput ) getNodeLabels () string {
263+ if ni .KubeletExtraArgs != nil {
264+ if _ , ok := ni .KubeletExtraArgs ["node-labels" ]; ok {
265+ return ni .KubeletExtraArgs ["node-labels" ]
266+ }
267+ }
268+ nodeLabels := make ([]string , 0 , 3 )
269+ if ni .AMIImageID != "" {
270+ nodeLabels = append (nodeLabels , fmt .Sprintf ("eks.amazonaws.com/nodegroup-image=%s" , ni .AMIImageID ))
271+ }
272+ if ni .NodeGroupName != "" {
273+ nodeLabels = append (nodeLabels , fmt .Sprintf ("eks.amazonaws.com/nodegroup=%s" , ni .NodeGroupName ))
274+ }
275+ nodeLabels = append (nodeLabels , fmt .Sprintf ("eks.amazonaws.com/capacityType=%s" , ni .getCapacityTypeString ()))
276+ return strings .Join (nodeLabels , "," )
277+ }
278+
258279// getCapacityTypeString returns the string representation of the capacity type.
259280func (ni * NodeInput ) getCapacityTypeString () string {
260281 if ni .CapacityType == nil {
@@ -287,22 +308,22 @@ func validateAL2023Input(input *NodeInput) error {
287308
288309 if input .MaxPods == nil {
289310 if input .UseMaxPods != nil && * input .UseMaxPods {
290- input .MaxPods = ptr.To [int32 ](58 )
291- } else {
292311 input .MaxPods = ptr.To [int32 ](110 )
312+ } else {
313+ input .MaxPods = ptr.To [int32 ](58 )
293314 }
294315 }
295- if input .DNSClusterIP = = nil {
296- input .DNSClusterIP = ptr. To [ string ]( "10.96.0.10" )
316+ if input .DNSClusterIP ! = nil {
317+ input .ClusterDNS = * input . DNSClusterIP
297318 }
298- input .ClusterDNS = * input .DNSClusterIP
299319
300320 if input .Boundary == "" {
301321 input .Boundary = boundary
302322 }
323+ input .NodeLabels = input .getNodeLabels ()
303324
304- klog .V (2 ).Infof ("AL2023 Userdata Generation - maxPods: %d, clusterDNS: %s, amiID: %s, capacityType : %s" ,
305- * input .MaxPods , * input .DNSClusterIP , input . AMIImageID , input . getCapacityTypeString () )
325+ klog .V (2 ).Infof ("AL2023 Userdata Generation - maxPods: %d, node-labels : %s" ,
326+ * input .MaxPods , input .NodeLabels )
306327
307328 return nil
308329}
0 commit comments