Skip to content

Commit bf81f67

Browse files
mloiseleurAmitSahastra
authored andcommitted
review:
1. Fix maxPods 2. Make clusterDNS optional 3. Move node-labels from gotemplate to go func, for readability 4. Add usage documentation in the book
1 parent 7acf4c3 commit bf81f67

File tree

3 files changed

+71
-15
lines changed

3 files changed

+71
-15
lines changed

bootstrap/eks/controllers/eksconfig_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ func (r *EKSConfigReconciler) resolveSecretFileContent(ctx context.Context, ns s
194194

195195
func (r *EKSConfigReconciler) joinWorker(ctx context.Context, cluster *clusterv1.Cluster, config *eksbootstrapv1.EKSConfig, configOwner *bsutil.ConfigOwner) (ctrl.Result, error) {
196196
log := logger.FromContext(ctx)
197-
log.Info("joinWorker called", "config", config.Name, "nodeType", config.Spec.NodeType, "cluster", cluster.Name)
198197

199198
// only need to reconcile the secret for Machine kinds once, but MachinePools need updates for new launch templates
200199
if config.Status.DataSecretName != nil && configOwner.GetKind() == "Machine" {

bootstrap/eks/internal/userdata/node.go

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
259280
func (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
}

docs/book/src/topics/eks/enabling.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@ Support for EKS is enabled by default when you use the AWS infrastructure provid
66
clusterctl init --infrastructure aws
77
```
88

9+
## Amazon Linux 2023
10+
11+
Amazon EKS will end support for EKS optimized AL2 AMIs on November 26, 2025.
12+
13+
With AL2023, [nodeadm](https://github.com/awslabs/amazon-eks-ami/tree/main/nodeadm) is used to join EKS cluster.
14+
Starting with v2.9.0, it's possible to set the node type in `EKSConfig` and `EKSConfigTemplate` like this:
15+
16+
```yaml
17+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
18+
kind: EKSConfigTemplate
19+
metadata:
20+
name: al2023
21+
spec:
22+
template:
23+
spec:
24+
nodeType: al2023
25+
```
26+
27+
AL2023 AMI can also be set in `AWSMAchineTemplate`. The use of Secrets Manager trick should be disabled because
28+
nodeadm expect the `NodeConfig` in plain text in EC2 instance's userdata.
29+
30+
31+
```yaml
32+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
33+
kind: AWSMachineTemplate
34+
metadata:
35+
name: al2023
36+
spec:
37+
template:
38+
spec:
39+
ami:
40+
eksLookupType: AmazonLinux2023
41+
cloudInit:
42+
insecureSkipSecretsManager: true
43+
```
44+
945
## Enabling optional **EKS** features
1046

1147
There are additional EKS experimental features that are disabled by default. The sections below cover how to enable these features.

0 commit comments

Comments
 (0)