mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(eks): label cluster nodes with their topology zone and region (#4308)
This commit is contained in:
1 parent
06ec4b563a
commit
6de5e40f54
4 files changed
+123
-1
No files matched your search
@@ -874,6 +874,13 @@ class EksClusterManagerTest {
|
||||
assertEquals(instance.getPlacement().getAvailabilityZone(), manager.deriveClusterNodeAvailabilityZone(cluster, "us-west-2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deriveClusterNodeAvailabilityZoneDerivesFromClusterArn() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setArn("arn:aws:eks:ap-southeast-1:123456789012:cluster/test-cluster");
|
||||
assertEquals("ap-southeast-1a", manager.deriveClusterNodeAvailabilityZone(cluster));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configuresMetadataProxyWhenEnabled() {
|
||||
Cluster cluster = new Cluster();
|
||||
@@ -1407,6 +1414,85 @@ class EksClusterManagerTest {
|
||||
assertFalse(cmd.stream().anyMatch(arg -> arg.startsWith("--kubelet-arg=provider-id=")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void startClusterConfiguresKubeletTopologyLabelsArg() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName("prod-cluster");
|
||||
cluster.setAccountId("123456789012");
|
||||
cluster.setArn("arn:aws:eks:us-west-2:123456789012:cluster/prod-cluster");
|
||||
|
||||
manager.startCluster(cluster);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<String>> cmdCaptor = ArgumentCaptor.forClass(List.class);
|
||||
verify(builder).withCmd(cmdCaptor.capture());
|
||||
List<String> cmd = cmdCaptor.getValue();
|
||||
|
||||
String expectedAz = manager.deriveClusterNodeAvailabilityZone(cluster, "us-west-2");
|
||||
assertEquals("us-west-2a", expectedAz);
|
||||
assertTrue(cmd.contains("--kubelet-arg=node-labels=topology.kubernetes.io/zone=" + expectedAz
|
||||
+ ",topology.kubernetes.io/region=us-west-2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void topologyLabelZoneMatchesProviderIdZone() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName("prod-cluster");
|
||||
cluster.setAccountId("123456789012");
|
||||
cluster.setArn("arn:aws:eks:eu-central-1:123456789012:cluster/prod-cluster");
|
||||
|
||||
manager.startCluster(cluster);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<String>> cmdCaptor = ArgumentCaptor.forClass(List.class);
|
||||
verify(builder).withCmd(cmdCaptor.capture());
|
||||
List<String> cmd = cmdCaptor.getValue();
|
||||
|
||||
String providerIdArg = cmd.stream()
|
||||
.filter(arg -> arg.startsWith("--kubelet-arg=provider-id="))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("provider-id arg missing"));
|
||||
String providerId = providerIdArg.substring("--kubelet-arg=provider-id=".length());
|
||||
String[] parts = providerId.split("/");
|
||||
assertTrue(parts.length >= 4, "Provider ID should have format aws:///<zone>/<instance-id>");
|
||||
String providerZone = parts[3];
|
||||
|
||||
String nodeLabelsArg = cmd.stream()
|
||||
.filter(arg -> arg.startsWith("--kubelet-arg=node-labels="))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("node-labels arg missing"));
|
||||
String labelZone = null;
|
||||
String labelsPart = nodeLabelsArg.substring("--kubelet-arg=node-labels=".length());
|
||||
for (String pair : labelsPart.split(",")) {
|
||||
String[] kv = pair.split("=", 2);
|
||||
if ("topology.kubernetes.io/zone".equals(kv[0])) {
|
||||
labelZone = kv[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull(labelZone, "topology.kubernetes.io/zone must be present in node-labels arg");
|
||||
assertEquals(providerZone, labelZone);
|
||||
}
|
||||
|
||||
@Test
|
||||
void startClusterContinuesWhenTopologyLabelsDerivationFails() {
|
||||
EksClusterManager spyManager = Mockito.spy(manager);
|
||||
Mockito.doThrow(new RuntimeException("derivation failure"))
|
||||
.when(spyManager).deriveClusterNodeAvailabilityZone(any(), any());
|
||||
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName("fail-cluster");
|
||||
|
||||
assertDoesNotThrow(() -> spyManager.startCluster(cluster));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<List<String>> cmdCaptor = ArgumentCaptor.forClass(List.class);
|
||||
verify(builder).withCmd(cmdCaptor.capture());
|
||||
List<String> cmd = cmdCaptor.getValue();
|
||||
|
||||
assertFalse(cmd.stream().anyMatch(arg -> arg.startsWith("--kubelet-arg=node-labels=")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void signingKeyFilesWrittenWithRestrictivePermissions(@TempDir Path tempDir) throws Exception {
|
||||
when(eks.irsaSigningKey()).thenReturn(true);
|
||||
|
||||
+14
@@ -203,6 +203,20 @@ class EksIrsaDockerIntegrationTest {
|
||||
assertEquals(eksClusterManager.deriveClusterNodeProviderId(cluster), nodeResult.stdout().trim(),
|
||||
"Node providerID must match the derived AWS provider ID");
|
||||
|
||||
ExecResult zoneResult = execInContainerWithExitCode(containerId,
|
||||
new String[]{"kubectl", "get", "nodes", "-o",
|
||||
"jsonpath={.items[0].metadata.labels.topology\\.kubernetes\\.io/zone}"});
|
||||
assertEquals(0, zoneResult.exitCode(), "kubectl get nodes failed");
|
||||
assertEquals(eksClusterManager.deriveClusterNodeAvailabilityZone(cluster), zoneResult.stdout().trim(),
|
||||
"Node topology zone label must match the derived availability zone");
|
||||
|
||||
ExecResult regionResult = execInContainerWithExitCode(containerId,
|
||||
new String[]{"kubectl", "get", "nodes", "-o",
|
||||
"jsonpath={.items[0].metadata.labels.topology\\.kubernetes\\.io/region}"});
|
||||
assertEquals(0, regionResult.exitCode(), "kubectl get nodes failed");
|
||||
assertEquals(eksClusterManager.clusterRegion(cluster), regionResult.stdout().trim(),
|
||||
"Node topology region label must match the cluster region");
|
||||
|
||||
// Extract the projected token from the pod volume
|
||||
String token = execInContainer(containerId,
|
||||
new String[]{"kubectl", "exec", "irsa-workload-pod", "--", "cat", "/var/run/secrets/tokens/token"}).trim();
|
||||
|
||||
Reference in new issue
Block a user