From b356fefeae78f0bcc27832142ca8dac4ec2ed991 Mon Sep 17 00:00:00 2001 From: mrfelek <17274927+mrfelek@users.noreply.github.com> Date: Mon, 30 Nov 2026 01:18:22 +0100 Subject: [PATCH] fix(eks): name an EKS Auto Mode node by its instance ID when its image runs a kubelet (#9785) An EKS Auto Mode instance whose image's own kubelet registers its node (kubeletRegistersNode) was looked for under its private DNS name, while the node is authenticated as system:node:. Node restriction refuses that kubelet a node under the DNS name, and one registered under the instance ID was never found, so the instance was terminated once its registration wait was up. The node is now named by the instance ID whoever registers it, and the NodeConfig Auto Mode launches with turns on nodeadm's InstanceIdNodeName feature gate, so the kubelet registers it under that name. --- docs/services/eks.md | 4 ++-- .../aws/services/eks/EksAutoModeCompute.java | 5 ++++- .../aws/services/eks/EksClusterManager.java | 7 ++++--- .../services/eks/EksAutoModeComputeTest.java | 2 ++ .../services/eks/EksClusterManagerTest.java | 21 +++++++++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/docs/services/eks.md b/docs/services/eks.md index 79314b673b..657f87a398 100644 --- a/docs/services/eks.md +++ b/docs/services/eks.md @@ -504,7 +504,8 @@ launches nodes on AWS. Floci checks every 10 seconds. `eks.amazonaws.com/instance-*` category, generation, family, size, CPU and memory labels. The node is named by its instance ID (`i-0123456789abcdef0`), as are its `kubernetes.io/hostname` label, as AWS names Auto Mode's nodes; its `InternalDNS` and `Hostname` addresses keep the private DNS name (`ip-10-0-1-10.ec2.internal`). An image whose own - kubelet registers the node keeps the name that kubelet gives it. + kubelet registers the node is told so too: the `NodeConfig` turns on nodeadm's `InstanceIdNodeName` feature gate, + and the node authenticates as `system:node:`. - **Empty nodes.** A node that runs no workload (DaemonSet and static pods aside) and that no pending pod is counting on is removed once it has been empty for its pool's `disruption.consolidateAfter`, as Auto Mode's consolidation removes it: it is tainted `karpenter.sh/disrupted:NoSchedule`, as Karpenter marks a node it removes, and unless @@ -555,7 +556,6 @@ launches nodes on AWS. Floci checks every 10 seconds. Each node is a managed instance, as on AWS: its `Operator` names `eks.amazonaws.com`, and a plain `DescribeInstances` or `DescribeInstanceStatus` leaves it out (see [EC2](ec2.md#managed-instances)). -An image whose own kubelet registers its node keeps the name that kubelet gives it, not the instance ID. Floci doesn't replace underutilized nodes with smaller ones, and a NodeClaim's requirements name only the instance type chosen, where AWS lists every type that would do. diff --git a/src/main/java/io/floci/aws/services/eks/EksAutoModeCompute.java b/src/main/java/io/floci/aws/services/eks/EksAutoModeCompute.java index b5bc8d7f6d..dd9fa5ed41 100644 --- a/src/main/java/io/floci/aws/services/eks/EksAutoModeCompute.java +++ b/src/main/java/io/floci/aws/services/eks/EksAutoModeCompute.java @@ -1004,7 +1004,8 @@ public class EksAutoModeCompute implements EksAutoModeCleanup { /** * nodeadm's {@code NodeConfig} for the cluster, the user data an instance joins it with, its kubelet registering - * the node with its pool's labels and taints, so a pod the pool's taints keep off never lands there first. + * the node under the instance ID with its pool's labels and taints, so a pod the pool's taints keep off never + * lands there first. */ static String nodeConfig(Cluster cluster, Launch launch) { StringBuilder yaml = new StringBuilder(""" @@ -1023,6 +1024,8 @@ public class EksAutoModeCompute implements EksAutoModeCleanup { if (cluster.getKubernetesNetworkConfig() != null && cluster.getKubernetesNetworkConfig().getServiceIpv4Cidr() != null) { yaml.append(" cidr: ").append(cluster.getKubernetesNetworkConfig().getServiceIpv4Cidr()).append('\n'); } + // nodeadm names the node by its instance ID, as Auto Mode's are named and authenticated, not its private DNS name. + yaml.append(" featureGates:\n InstanceIdNodeName: true\n"); yaml.append(" kubelet:\n flags:\n"); yaml.append(" - --node-labels=").append(String.join(",", launch.labels().entrySet().stream() .map(e -> e.getKey() + "=" + e.getValue()).toList())).append('\n'); diff --git a/src/main/java/io/floci/aws/services/eks/EksClusterManager.java b/src/main/java/io/floci/aws/services/eks/EksClusterManager.java index dcc05df293..abca8e7040 100644 --- a/src/main/java/io/floci/aws/services/eks/EksClusterManager.java +++ b/src/main/java/io/floci/aws/services/eks/EksClusterManager.java @@ -4461,11 +4461,12 @@ public class EksClusterManager /** * The name of an instance's node: an EKS Auto Mode instance's is its instance ID, as AWS names Auto Mode's nodes - * ({@code i-0123456789abcdef0}); any other's, or one whose own kubelet registers its node, is its private DNS name. + * ({@code i-0123456789abcdef0}), whether Floci registers the node or the image's own kubelet does, as its + * {@code NodeConfig} has it ({@code InstanceIdNodeName}) and as the node is authenticated + * ({@code system:node:}); any other's is its private DNS name. */ String deriveInstanceNodeName(Instance instance, String region) { - if (autoModeInstance(instance) && instance.getInstanceId() != null - && (instance.getImageId() == null || !kubeletRegistersNode(instance))) { + if (autoModeInstance(instance) && instance.getInstanceId() != null) { return instance.getInstanceId(); } return deriveInstanceDnsName(instance, region); diff --git a/src/test/java/io/floci/aws/services/eks/EksAutoModeComputeTest.java b/src/test/java/io/floci/aws/services/eks/EksAutoModeComputeTest.java index e1f3392fd4..9d78cfb707 100644 --- a/src/test/java/io/floci/aws/services/eks/EksAutoModeComputeTest.java +++ b/src/test/java/io/floci/aws/services/eks/EksAutoModeComputeTest.java @@ -148,6 +148,8 @@ class EksAutoModeComputeTest { name: prod apiServerEndpoint: https://prod.example certificateAuthority: Q0E= + featureGates: + InstanceIdNodeName: true kubelet: flags: - --node-labels=kubernetes.io/arch=amd64,kubernetes.io/os=linux,node.kubernetes.io/instance-type=c7a.large,karpenter.sh/capacity-type=on-demand,eks.amazonaws.com/instance-category=c,eks.amazonaws.com/instance-generation=7,eks.amazonaws.com/instance-family=c7a,eks.amazonaws.com/instance-size=large,eks.amazonaws.com/instance-cpu=2,eks.amazonaws.com/instance-memory=4096,karpenter.sh/nodepool=general-purpose,eks.amazonaws.com/compute-type=auto,topology.kubernetes.io/zone=us-east-1a diff --git a/src/test/java/io/floci/aws/services/eks/EksClusterManagerTest.java b/src/test/java/io/floci/aws/services/eks/EksClusterManagerTest.java index 22ef873211..13ff8c8b75 100644 --- a/src/test/java/io/floci/aws/services/eks/EksClusterManagerTest.java +++ b/src/test/java/io/floci/aws/services/eks/EksClusterManagerTest.java @@ -5846,6 +5846,27 @@ class EksClusterManagerTest { assertEquals(2, commands.getAllValues().size()); } + /** + * An Auto Mode instance whose image's own kubelet registers the node is named by its instance ID too, as its + * NodeConfig tells nodeadm and as the node is authenticated; another instance's kubelet keeps its private DNS + * name. + */ + @Test + void anAutoModeKubeletImagesNodeIsNamedByItsInstanceId() { + Instance auto = createInstance("i-0auto1234567890ac", "us-east-1a", "t3.medium", "x86_64", "10.0.1.81"); + auto.setPrivateDnsName("ip-10-0-1-81.ec2.internal"); + auto.setImageId("ami-kubelet-worker"); + auto.setTags(List.of(new Tag(EksAutoModeCompute.MANAGED_LAUNCH_TAG, EksAutoModeCompute.MANAGED_LAUNCH))); + Instance worker = createInstance("i-0work1234567890ac", "us-east-1a", "t3.medium", "x86_64", "10.0.1.82"); + worker.setPrivateDnsName("ip-10-0-1-82.ec2.internal"); + worker.setImageId("ami-kubelet-worker"); + + assertTrue(manager.kubeletRegistersNode(auto)); + assertEquals("i-0auto1234567890ac", manager.deriveInstanceNodeName(auto, "us-east-1")); + assertEquals("ip-10-0-1-81.ec2.internal", manager.deriveInstanceDnsName(auto, "us-east-1")); + assertEquals("ip-10-0-1-82.ec2.internal", manager.deriveInstanceNodeName(worker, "us-east-1")); + } + /** As a kubelet does: the node registers with the labels and taints its NodeConfig's kubelet flags name. */ @Test void aSyntheticNodeRegistersWithItsNodeConfigsLabelsAndTaints() {