Skip to content

Commit 8e9388a

Browse files
committed
fix: Use cluster service CIDR in NodeConfig CIDR
As per documentation at https://github.com/awslabs/amazon-eks-ami/blob/v20250813/nodeadm/api/v1alpha1/nodeconfig_types.go#L52-L53: ``` // CIDR is your cluster's service CIDR block. This value is used to infer your cluster's DNS address. CIDR string `json:"cidr,omitempty"` ``` Previously setting it to the VPC CIDR was breaking DNS resolution in pods because they were expecting CoreDNS at 10.0.0.10 (10th IP in VPC CIDR) rather than the 10th IP in the service CIDR. Also change the default service CIDR to EKS default of 172.20.0.0/12.
1 parent 6493efd commit 8e9388a

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

bootstrap/eks/controllers/eksconfig_controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ func (r *EKSConfigReconciler) joinWorker(ctx context.Context, cluster *clusterv1
264264
return ctrl.Result{}, err
265265
}
266266

267+
serviceCIDR := ""
268+
if cluster.Spec.ClusterNetwork != nil && cluster.Spec.ClusterNetwork.Services != nil && len(cluster.Spec.ClusterNetwork.Services.CIDRBlocks) > 0 {
269+
serviceCIDR = cluster.Spec.ClusterNetwork.Services.CIDRBlocks[0]
270+
}
271+
267272
// Create unified NodeInput for both AL2 and AL2023
268273
nodeInput := &userdata.NodeInput{
269274
ClusterName: controlPlane.Spec.EKSClusterName,
@@ -281,7 +286,7 @@ func (r *EKSConfigReconciler) joinWorker(ctx context.Context, cluster *clusterv1
281286
DiskSetup: config.Spec.DiskSetup,
282287
Mounts: config.Spec.Mounts,
283288
Files: files,
284-
ClusterCIDR: controlPlane.Spec.NetworkSpec.VPC.CidrBlock,
289+
ServiceCIDR: serviceCIDR,
285290
}
286291

287292
if config.Spec.PauseContainer != nil {

bootstrap/eks/internal/userdata/node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ spec:
8383
name: {{.ClusterName}}
8484
apiServerEndpoint: {{.APIServerEndpoint}}
8585
certificateAuthority: {{.CACert}}
86-
cidr: {{if .ClusterCIDR}}{{.ClusterCIDR}}{{else}}10.96.0.0/12{{end}}
86+
cidr: {{if .ServiceCIDR}}{{.ServiceCIDR}}{{else}}172.20.0.0/16{{end}}
8787
kubelet:
8888
config:
8989
maxPods: {{.MaxPods}}
@@ -130,7 +130,7 @@ type NodeInput struct {
130130
Boundary string
131131
CACert string
132132
CapacityType *v1beta2.ManagedMachinePoolCapacityType
133-
ClusterCIDR string // CIDR range for the cluster
133+
ServiceCIDR string // Service CIDR range for the cluster
134134
ClusterDNS string
135135
MaxPods *int32
136136
NodeGroupName string

bootstrap/eks/internal/userdata/node_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ EOF`,
450450
if !strings.Contains(output, "apiVersion: node.eks.aws/v1alpha1") ||
451451
!strings.Contains(output, "name: my-cluster") ||
452452
!strings.Contains(output, "apiServerEndpoint: https://example.com") ||
453-
!strings.Contains(output, `"--node-labels=app=my-app,environment=production"`) {
453+
!strings.Contains(output, `"--node-labels=app=my-app,environment=production"`) ||
454+
!strings.Contains(output, "cidr: 172.20.0.0/16") {
454455
return false
455456
}
456457

@@ -493,13 +494,15 @@ func TestGenerateAL2023UserData(t *testing.T) {
493494
CACert: "test-cert",
494495
NodeGroupName: "test-nodegroup",
495496
UseMaxPods: ptr.To[bool](false),
496-
DNSClusterIP: ptr.To[string]("10.96.0.10"),
497+
DNSClusterIP: ptr.To[string]("172.20.0.10"),
497498
},
498499
expectErr: false,
499500
verifyOutput: func(output string) bool {
500501
return strings.Contains(output, "name: test-cluster") &&
501502
strings.Contains(output, "maxPods: 58") &&
502-
strings.Contains(output, "nodegroup=test-nodegroup")
503+
strings.Contains(output, "nodegroup=test-nodegroup") &&
504+
strings.Contains(output, "cidr: 172.20.0.0/16") &&
505+
strings.Contains(output, "clusterDNS:\n - 172.20.0.10")
503506
},
504507
},
505508
{
@@ -513,7 +516,7 @@ func TestGenerateAL2023UserData(t *testing.T) {
513516
UseMaxPods: ptr.To[bool](true),
514517
DNSClusterIP: ptr.To[string]("10.100.0.10"),
515518
AMIImageID: "ami-123456",
516-
ClusterCIDR: "192.168.0.0/16",
519+
ServiceCIDR: "192.168.0.0/16",
517520
},
518521
expectErr: false,
519522
verifyOutput: func(output string) bool {
@@ -544,7 +547,8 @@ func TestGenerateAL2023UserData(t *testing.T) {
544547
verifyOutput: func(output string) bool {
545548
return strings.Contains(output, "echo 'pre-bootstrap'") &&
546549
strings.Contains(output, "echo 'post-bootstrap'") &&
547-
strings.Contains(output, `"--node-labels=app=my-app,environment=production"`)
550+
strings.Contains(output, `"--node-labels=app=my-app,environment=production"`) &&
551+
strings.Contains(output, "cidr: 172.20.0.0/16")
548552
},
549553
},
550554
{

0 commit comments

Comments
 (0)