mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(eks): support managed node groups (create/describe/list/delete) (#1226)
* feat(eks): support managed node groups (create/describe/list/delete)
aws eks create-nodegroup returned a 400 S3 error ("POST requires ?uploads
parameter") because EksController declared no route for
/clusters/{name}/node-groups, so the request fell through to S3's path-style
catch-all. Add the nodegroup REST routes (which outrank S3's templated path)
plus management-plane node group CRUD.
Node groups are emulated as catalog records that become ACTIVE immediately,
mirroring mock-mode cluster creation; no real worker nodes are provisioned
(k3s schedules pods on its built-in node in real mode).
Closes #1137
* refactor(eks): drop unused nextToken/maxResults params from listNodegroups
This commit is contained in:
1 parent
2ba1798b5d
commit
f669116908
8 files changed
+603
-1
No files matched your search
+92
@@ -0,0 +1,92 @@
|
||||
package io.github.hectorvent.floci.services.eks;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
/**
|
||||
* EKS managed node group REST flow (issue #1137). The key regression: {@code
|
||||
* POST /clusters/{name}/node-groups} must route to EKS and return a {@code nodegroup}
|
||||
* envelope, not fall through to S3's path-style catch-all (which returned a 400 "POST
|
||||
* requires ?uploads parameter").
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class EksNodegroupIntegrationTest {
|
||||
|
||||
private static final String JSON = "application/json";
|
||||
private static final String CLUSTER = "ng-it-cluster";
|
||||
private static final String NODE_ROLE = "arn:aws:iam::000000000000:role/eks-node-role";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createCluster() {
|
||||
given().contentType(JSON)
|
||||
.body("{\"name\":\"" + CLUSTER + "\",\"roleArn\":\"arn:aws:iam::000000000000:role/eks-role\","
|
||||
+ "\"version\":\"1.29\"}")
|
||||
.when().post("/clusters")
|
||||
.then().statusCode(200)
|
||||
.body("cluster.name", equalTo(CLUSTER));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createNodegroupRoutesToEksNotS3() {
|
||||
given().contentType(JSON)
|
||||
.body("{\"nodegroupName\":\"ng1\",\"subnets\":[\"subnet-abc\"],\"nodeRole\":\"" + NODE_ROLE + "\","
|
||||
+ "\"scalingConfig\":{\"minSize\":1,\"maxSize\":3,\"desiredSize\":2}}")
|
||||
.when().post("/clusters/" + CLUSTER + "/node-groups")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
// Regression: a nodegroup envelope proves EKS handled it, not S3.
|
||||
.body("nodegroup.nodegroupName", equalTo("ng1"))
|
||||
.body("nodegroup.clusterName", equalTo(CLUSTER))
|
||||
.body("nodegroup.nodegroupArn", containsString("nodegroup/" + CLUSTER + "/ng1/"))
|
||||
.body("nodegroup.status", anyOf(is("ACTIVE"), is("CREATING")))
|
||||
.body("nodegroup.scalingConfig.desiredSize", equalTo(2))
|
||||
.body("nodegroup.amiType", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void listNodegroups() {
|
||||
given().contentType(JSON)
|
||||
.when().get("/clusters/" + CLUSTER + "/node-groups")
|
||||
.then().statusCode(200)
|
||||
.body("nodegroups", hasItem("ng1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void describeNodegroup() {
|
||||
given().contentType(JSON)
|
||||
.when().get("/clusters/" + CLUSTER + "/node-groups/ng1")
|
||||
.then().statusCode(200)
|
||||
.body("nodegroup.nodegroupName", equalTo("ng1"))
|
||||
.body("nodegroup.subnets[0]", equalTo("subnet-abc"))
|
||||
.body("nodegroup.nodeRole", equalTo(NODE_ROLE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void deleteNodegroup() {
|
||||
given().contentType(JSON)
|
||||
.when().delete("/clusters/" + CLUSTER + "/node-groups/ng1")
|
||||
.then().statusCode(200)
|
||||
.body("nodegroup.status", equalTo("DELETING"));
|
||||
|
||||
given().contentType(JSON)
|
||||
.when().get("/clusters/" + CLUSTER + "/node-groups/ng1")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.eks.model.ClusterStatus;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateClusterRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.Cluster;
|
||||
import io.github.hectorvent.floci.services.eks.model.Nodegroup;
|
||||
import io.github.hectorvent.floci.services.eks.model.NodegroupStatus;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
@@ -27,8 +29,10 @@ class EksServiceTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
// Return a distinct backend per create() call so the cluster and node-group stores
|
||||
// don't share one instance (which would mix types and break node-group scans).
|
||||
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
|
||||
.thenReturn(new InMemoryStorage<>());
|
||||
.thenAnswer(invocation -> new InMemoryStorage<>());
|
||||
|
||||
config = Mockito.mock(EmulatorConfig.class);
|
||||
var servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class);
|
||||
@@ -143,4 +147,80 @@ class EksServiceTest {
|
||||
assertFalse(tags.containsKey("env"));
|
||||
assertEquals("platform", tags.get("team"));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Managed node groups (#1137) ────────────────────────────
|
||||
|
||||
private Cluster newCluster(String name) {
|
||||
CreateClusterRequest req = new CreateClusterRequest();
|
||||
req.setName(name);
|
||||
req.setRoleArn("arn:aws:iam::000000000000:role/eks-role");
|
||||
req.setVersion("1.29");
|
||||
return eksService.createCluster(req);
|
||||
}
|
||||
|
||||
private Nodegroup newNodegroupRequest(String name) {
|
||||
Nodegroup ng = new Nodegroup();
|
||||
ng.setNodegroupName(name);
|
||||
ng.setSubnets(List.of("subnet-123"));
|
||||
ng.setNodeRole("arn:aws:iam::000000000000:role/eks-node-role");
|
||||
return ng;
|
||||
}
|
||||
|
||||
@Test
|
||||
void createNodegroupBecomesActiveWithDefaults() {
|
||||
newCluster("ng-cluster");
|
||||
Nodegroup ng = eksService.createNodegroup("ng-cluster", newNodegroupRequest("ng1"));
|
||||
|
||||
assertEquals("ng1", ng.getNodegroupName());
|
||||
assertEquals("ng-cluster", ng.getClusterName());
|
||||
assertEquals(NodegroupStatus.ACTIVE, ng.getStatus());
|
||||
assertTrue(ng.getNodegroupArn().contains("nodegroup/ng-cluster/ng1/"));
|
||||
assertEquals("AL2_x86_64", ng.getAmiType());
|
||||
assertEquals("ON_DEMAND", ng.getCapacityType());
|
||||
assertEquals(20, ng.getDiskSize());
|
||||
assertEquals("1.29", ng.getVersion());
|
||||
assertEquals(List.of("t3.medium"), ng.getInstanceTypes());
|
||||
assertNotNull(ng.getScalingConfig());
|
||||
assertEquals(2, ng.getScalingConfig().getDesiredSize());
|
||||
assertNotNull(ng.getCreatedAt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createNodegroupOnMissingClusterFails() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> eksService.createNodegroup("no-such-cluster", newNodegroupRequest("ng1")));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createNodegroupDuplicateFails() {
|
||||
newCluster("ng-cluster");
|
||||
eksService.createNodegroup("ng-cluster", newNodegroupRequest("ng1"));
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> eksService.createNodegroup("ng-cluster", newNodegroupRequest("ng1")));
|
||||
assertEquals("ResourceInUseException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeListAndDeleteNodegroup() {
|
||||
newCluster("ng-cluster");
|
||||
eksService.createNodegroup("ng-cluster", newNodegroupRequest("ng1"));
|
||||
eksService.createNodegroup("ng-cluster", newNodegroupRequest("ng2"));
|
||||
|
||||
assertEquals("ng1", eksService.describeNodegroup("ng-cluster", "ng1").getNodegroupName());
|
||||
assertEquals(List.of("ng1", "ng2"),
|
||||
eksService.listNodegroups("ng-cluster").stream().sorted().toList());
|
||||
|
||||
Nodegroup deleted = eksService.deleteNodegroup("ng-cluster", "ng1");
|
||||
assertEquals(NodegroupStatus.DELETING, deleted.getStatus());
|
||||
assertThrows(AwsException.class, () -> eksService.describeNodegroup("ng-cluster", "ng1"));
|
||||
assertEquals(List.of("ng2"), eksService.listNodegroups("ng-cluster"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listNodegroupsOnMissingClusterFails() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> eksService.listNodegroups("no-such-cluster"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user