mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(eks): set the cluster node providerID (#4255)
This commit is contained in:
1 parent
69217dff2a
commit
766166fc35
4 files changed
+137
-7
No files matched your search
@@ -849,6 +849,30 @@ class EksClusterManagerTest {
|
||||
assertNotEquals(inst1.getInstanceId(), inst2.getInstanceId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void derivesClusterNodeProviderIdMatchingExpectedFormat() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName("prod-cluster");
|
||||
|
||||
String providerId = manager.deriveClusterNodeProviderId(cluster, "us-west-2", "123456789012");
|
||||
assertEquals("aws:///us-west-2a/i-0e413a1bfb5c3cd79", providerId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void derivedProviderIdAgreesWithSynthesizedClusterNodeInstance() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName("prod-cluster");
|
||||
cluster.setRoleArn("arn:aws:iam::123456789012:role/eks-node-role");
|
||||
|
||||
Instance instance = manager.synthesizeClusterNodeInstance(cluster, "172.17.0.2", "us-west-2", "123456789012");
|
||||
String providerId = manager.deriveClusterNodeProviderId(cluster, "us-west-2", "123456789012");
|
||||
|
||||
String expectedProviderId = "aws:///" + instance.getPlacement().getAvailabilityZone() + "/" + instance.getInstanceId();
|
||||
assertEquals(expectedProviderId, providerId);
|
||||
assertEquals(instance.getInstanceId(), manager.deriveClusterNodeInstanceId(cluster, "us-west-2", "123456789012"));
|
||||
assertEquals(instance.getPlacement().getAvailabilityZone(), manager.deriveClusterNodeAvailabilityZone(cluster, "us-west-2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configuresMetadataProxyWhenEnabled() {
|
||||
Cluster cluster = new Cluster();
|
||||
@@ -1296,6 +1320,44 @@ class EksClusterManagerTest {
|
||||
verify(copyCmd).withHostResource(pubFile.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void startClusterConfiguresKubeletProviderIdArg() {
|
||||
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 expectedProviderId = manager.deriveClusterNodeProviderId(cluster);
|
||||
assertEquals("aws:///us-west-2a/i-0e413a1bfb5c3cd79", expectedProviderId);
|
||||
assertTrue(cmd.contains("--kubelet-arg=provider-id=" + expectedProviderId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void startClusterContinuesWhenProviderIdDerivationFails() {
|
||||
EksClusterManager spyManager = Mockito.spy(manager);
|
||||
Mockito.doThrow(new RuntimeException("derivation failure"))
|
||||
.when(spyManager).deriveClusterNodeProviderId(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=provider-id=")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void signingKeyFilesWrittenWithRestrictivePermissions(@TempDir Path tempDir) throws Exception {
|
||||
when(eks.irsaSigningKey()).thenReturn(true);
|
||||
|
||||
+9
@@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -194,6 +195,14 @@ class EksIrsaDockerIntegrationTest {
|
||||
}
|
||||
assertTrue(podRunning, "irsa-workload-pod must reach Running state");
|
||||
|
||||
// The pod is Running, so it was scheduled onto the node, which the kubelet
|
||||
// registered with its provider ID: the node is guaranteed to exist here.
|
||||
ExecResult nodeResult = execInContainerWithExitCode(containerId,
|
||||
new String[]{"kubectl", "get", "nodes", "-o", "jsonpath={.items[0].spec.providerID}"});
|
||||
assertEquals(0, nodeResult.exitCode(), "kubectl get nodes failed");
|
||||
assertEquals(eksClusterManager.deriveClusterNodeProviderId(cluster), nodeResult.stdout().trim(),
|
||||
"Node providerID must match the derived AWS provider ID");
|
||||
|
||||
// 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