Skip to content

Commit 48719db

Browse files
authored
Merge pull request #1004 from spectrocloud/cp/PCP-5517
[PCP-5517] fixed setting clustercidr and dns in NodeInput
2 parents 47569d7 + 57e2554 commit 48719db

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

bootstrap/eks/controllers/eksconfig_controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func (r *EKSConfigReconciler) joinWorker(ctx context.Context, cluster *clusterv1
287287
DiskSetup: config.Spec.DiskSetup,
288288
Mounts: config.Spec.Mounts,
289289
Files: files,
290-
ClusterCIDR: controlPlane.Spec.NetworkSpec.VPC.CidrBlock,
290+
ClusterCIDR: r.getClusterCidr(cluster, controlPlane),
291291
}
292292

293293
if config.Spec.PauseContainer != nil {
@@ -587,3 +587,11 @@ func (r *EKSConfigReconciler) extractCAFromSecret(ctx context.Context, obj clien
587587

588588
return "", fmt.Errorf("no cluster with CA data found in kubeconfig")
589589
}
590+
591+
func (r *EKSConfigReconciler) getClusterCidr(cluster *clusterv1.Cluster, controlPlane *ekscontrolplanev1.AWSManagedControlPlane) string {
592+
if cluster.Spec.ClusterNetwork != nil && cluster.Spec.ClusterNetwork.Services != nil && len(cluster.Spec.ClusterNetwork.Services.CIDRBlocks) > 0 {
593+
return cluster.Spec.ClusterNetwork.Services.CIDRBlocks[0]
594+
}
595+
596+
return controlPlane.Spec.NetworkSpec.VPC.CidrBlock
597+
}

bootstrap/eks/internal/userdata/node.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,11 @@ func validateAL2023Input(input *NodeInput) error {
402402
}
403403
}
404404
if input.DNSClusterIP == nil {
405-
input.DNSClusterIP = ptr.To[string]("10.96.0.10")
405+
if input.ClusterCIDR != "" {
406+
input.DNSClusterIP = ptr.To(calculateDNSFromServiceCIDR(input.ClusterCIDR))
407+
} else {
408+
input.DNSClusterIP = ptr.To[string]("10.96.0.10")
409+
}
406410
}
407411
input.ClusterDNS = *input.DNSClusterIP
408412

@@ -415,3 +419,10 @@ func validateAL2023Input(input *NodeInput) error {
415419

416420
return nil
417421
}
422+
423+
// calculateDNSFromServiceCIDR calculates the DNS cluster IP by replacing the last octet with 10.
424+
func calculateDNSFromServiceCIDR(cidr string) string {
425+
ipStr := strings.Split(strings.TrimSpace(cidr), "/")[0]
426+
lastDotIdx := strings.LastIndex(ipStr, ".")
427+
return ipStr[:lastDotIdx] + ".10"
428+
}

0 commit comments

Comments
 (0)