mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -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
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.eks;
|
||||
|
||||
import io.github.hectorvent.floci.services.eks.model.Cluster;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateClusterRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.Nodegroup;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
@@ -63,4 +64,37 @@ public class EksController {
|
||||
return Response.ok(Map.of("cluster", cluster)).build();
|
||||
}
|
||||
|
||||
// Managed node groups. These explicit routes outrank S3's path-style catch-all
|
||||
// (@Path("/{bucket}/{key: .+}")), which previously swallowed these paths (issue #1137).
|
||||
|
||||
@POST
|
||||
@Path("/clusters/{name}/node-groups")
|
||||
public Response createNodegroup(@PathParam("name") String name, Nodegroup request) {
|
||||
Nodegroup nodegroup = eksService.createNodegroup(name, request);
|
||||
return Response.ok(Map.of("nodegroup", nodegroup)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/node-groups")
|
||||
public Response listNodegroups(@PathParam("name") String name) {
|
||||
List<String> nodegroups = eksService.listNodegroups(name);
|
||||
return Response.ok(Map.of("nodegroups", nodegroups)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/node-groups/{nodegroupName}")
|
||||
public Response describeNodegroup(@PathParam("name") String name,
|
||||
@PathParam("nodegroupName") String nodegroupName) {
|
||||
Nodegroup nodegroup = eksService.describeNodegroup(name, nodegroupName);
|
||||
return Response.ok(Map.of("nodegroup", nodegroup)).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/clusters/{name}/node-groups/{nodegroupName}")
|
||||
public Response deleteNodegroup(@PathParam("name") String name,
|
||||
@PathParam("nodegroupName") String nodegroupName) {
|
||||
Nodegroup nodegroup = eksService.deleteNodegroup(name, nodegroupName);
|
||||
return Response.ok(Map.of("nodegroup", nodegroup)).build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,9 @@ import io.github.hectorvent.floci.services.eks.model.Cluster;
|
||||
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.KubernetesNetworkConfig;
|
||||
import io.github.hectorvent.floci.services.eks.model.Nodegroup;
|
||||
import io.github.hectorvent.floci.services.eks.model.NodegroupScalingConfig;
|
||||
import io.github.hectorvent.floci.services.eks.model.NodegroupStatus;
|
||||
import io.github.hectorvent.floci.services.eks.model.ResourcesVpcConfig;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
@@ -22,9 +25,12 @@ import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -36,6 +42,7 @@ public class EksService implements TagHandler {
|
||||
private static final Logger LOG = Logger.getLogger(EksService.class);
|
||||
|
||||
private final StorageBackend<String, Cluster> storage;
|
||||
private final StorageBackend<String, Nodegroup> nodegroupStorage;
|
||||
private final EmulatorConfig config;
|
||||
private final RegionResolver regionResolver;
|
||||
private final EksClusterManager clusterManager;
|
||||
@@ -46,6 +53,8 @@ public class EksService implements TagHandler {
|
||||
RegionResolver regionResolver, EksClusterManager clusterManager) {
|
||||
this.storage = storageFactory.create("eks", "eks-clusters.json",
|
||||
new TypeReference<Map<String, Cluster>>() {});
|
||||
this.nodegroupStorage = storageFactory.create("eks", "eks-nodegroups.json",
|
||||
new TypeReference<Map<String, Nodegroup>>() {});
|
||||
this.config = config;
|
||||
this.regionResolver = regionResolver;
|
||||
this.clusterManager = clusterManager;
|
||||
@@ -137,6 +146,103 @@ public class EksService implements TagHandler {
|
||||
return cluster;
|
||||
}
|
||||
|
||||
// ──────────────────────────── Managed node groups ────────────────────────────
|
||||
|
||||
public Nodegroup createNodegroup(String clusterName, Nodegroup request) {
|
||||
Cluster cluster = describeCluster(clusterName);
|
||||
String nodegroupName = request.getNodegroupName();
|
||||
if (nodegroupName == null || nodegroupName.isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "nodegroupName is required", 400);
|
||||
}
|
||||
if (request.getNodeRole() == null || request.getNodeRole().isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "nodeRole is required", 400);
|
||||
}
|
||||
if (request.getSubnets() == null || request.getSubnets().isEmpty()) {
|
||||
throw new AwsException("InvalidParameterException", "subnets are required", 400);
|
||||
}
|
||||
String key = nodegroupKey(clusterName, nodegroupName);
|
||||
if (nodegroupStorage.get(key).isPresent()) {
|
||||
throw new AwsException("ResourceInUseException",
|
||||
"NodeGroup already exists: " + nodegroupName, 409);
|
||||
}
|
||||
|
||||
String region = config.defaultRegion();
|
||||
String accountId = regionResolver.getAccountId();
|
||||
Instant now = Instant.now();
|
||||
|
||||
Nodegroup ng = request;
|
||||
ng.setClusterName(clusterName);
|
||||
ng.setAccountId(accountId);
|
||||
ng.setNodegroupArn(AwsArnUtils.Arn.of("eks", region, accountId,
|
||||
"nodegroup/" + clusterName + "/" + nodegroupName + "/" + UUID.randomUUID()).toString());
|
||||
ng.setCreatedAt(now);
|
||||
ng.setModifiedAt(now);
|
||||
// Mock node groups become ACTIVE immediately, mirroring mock-mode cluster creation;
|
||||
// real worker nodes are not provisioned — k3s schedules pods on its built-in node.
|
||||
ng.setStatus(NodegroupStatus.ACTIVE);
|
||||
if (ng.getAmiType() == null) {
|
||||
ng.setAmiType("AL2_x86_64");
|
||||
}
|
||||
if (ng.getCapacityType() == null) {
|
||||
ng.setCapacityType("ON_DEMAND");
|
||||
}
|
||||
if (ng.getDiskSize() == null) {
|
||||
ng.setDiskSize(20);
|
||||
}
|
||||
if (ng.getVersion() == null) {
|
||||
ng.setVersion(cluster.getVersion());
|
||||
}
|
||||
if (ng.getReleaseVersion() == null) {
|
||||
ng.setReleaseVersion(ng.getVersion() + "-eks-1");
|
||||
}
|
||||
if (ng.getInstanceTypes() == null || ng.getInstanceTypes().isEmpty()) {
|
||||
ng.setInstanceTypes(List.of("t3.medium"));
|
||||
}
|
||||
if (ng.getScalingConfig() == null) {
|
||||
NodegroupScalingConfig scaling = new NodegroupScalingConfig();
|
||||
scaling.setMinSize(1);
|
||||
scaling.setMaxSize(2);
|
||||
scaling.setDesiredSize(2);
|
||||
ng.setScalingConfig(scaling);
|
||||
}
|
||||
Map<String, Object> resources = new LinkedHashMap<>();
|
||||
Map<String, Object> asg = new LinkedHashMap<>();
|
||||
asg.put("name", "eks-" + nodegroupName + "-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
resources.put("autoScalingGroups", List.of(asg));
|
||||
ng.setResources(resources);
|
||||
Map<String, Object> health = new LinkedHashMap<>();
|
||||
health.put("issues", new ArrayList<>());
|
||||
ng.setHealth(health);
|
||||
|
||||
nodegroupStorage.put(key, ng);
|
||||
return ng;
|
||||
}
|
||||
|
||||
public Nodegroup describeNodegroup(String clusterName, String nodegroupName) {
|
||||
return nodegroupStorage.get(nodegroupKey(clusterName, nodegroupName))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"No node group found for name: " + nodegroupName + " in cluster: " + clusterName, 404));
|
||||
}
|
||||
|
||||
public List<String> listNodegroups(String clusterName) {
|
||||
describeCluster(clusterName);
|
||||
return nodegroupStorage.scan(k -> true).stream()
|
||||
.filter(ng -> clusterName.equals(ng.getClusterName()))
|
||||
.map(Nodegroup::getNodegroupName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Nodegroup deleteNodegroup(String clusterName, String nodegroupName) {
|
||||
Nodegroup ng = describeNodegroup(clusterName, nodegroupName);
|
||||
ng.setStatus(NodegroupStatus.DELETING);
|
||||
nodegroupStorage.delete(nodegroupKey(clusterName, nodegroupName));
|
||||
return ng;
|
||||
}
|
||||
|
||||
private String nodegroupKey(String clusterName, String nodegroupName) {
|
||||
return clusterName + "/" + nodegroupName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serviceKey() {
|
||||
return "eks";
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* EKS managed node group. Doubles as the {@code CreateNodegroup} request body (the input
|
||||
* members are a subset) and the wire response. Recursive sub-structures
|
||||
* (remoteAccess, taints, launchTemplate, updateConfig, nodeRepairConfig, resources, health)
|
||||
* round-trip as generic JSON so we don't over-model what the management plane just echoes.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class Nodegroup {
|
||||
|
||||
@JsonProperty("nodegroupName")
|
||||
private String nodegroupName;
|
||||
|
||||
@JsonProperty("nodegroupArn")
|
||||
private String nodegroupArn;
|
||||
|
||||
@JsonProperty("clusterName")
|
||||
private String clusterName;
|
||||
|
||||
@JsonProperty("version")
|
||||
private String version;
|
||||
|
||||
@JsonProperty("releaseVersion")
|
||||
private String releaseVersion;
|
||||
|
||||
@JsonProperty("createdAt")
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant createdAt;
|
||||
|
||||
@JsonProperty("modifiedAt")
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant modifiedAt;
|
||||
|
||||
@JsonProperty("status")
|
||||
private NodegroupStatus status;
|
||||
|
||||
@JsonProperty("capacityType")
|
||||
private String capacityType;
|
||||
|
||||
@JsonProperty("scalingConfig")
|
||||
private NodegroupScalingConfig scalingConfig;
|
||||
|
||||
@JsonProperty("instanceTypes")
|
||||
private List<String> instanceTypes;
|
||||
|
||||
@JsonProperty("subnets")
|
||||
private List<String> subnets;
|
||||
|
||||
@JsonProperty("remoteAccess")
|
||||
private Object remoteAccess;
|
||||
|
||||
@JsonProperty("amiType")
|
||||
private String amiType;
|
||||
|
||||
@JsonProperty("nodeRole")
|
||||
private String nodeRole;
|
||||
|
||||
@JsonProperty("labels")
|
||||
private Map<String, String> labels;
|
||||
|
||||
@JsonProperty("taints")
|
||||
private List<Object> taints;
|
||||
|
||||
@JsonProperty("resources")
|
||||
private Object resources;
|
||||
|
||||
@JsonProperty("diskSize")
|
||||
private Integer diskSize;
|
||||
|
||||
@JsonProperty("health")
|
||||
private Object health;
|
||||
|
||||
@JsonProperty("updateConfig")
|
||||
private Object updateConfig;
|
||||
|
||||
@JsonProperty("nodeRepairConfig")
|
||||
private Object nodeRepairConfig;
|
||||
|
||||
@JsonProperty("launchTemplate")
|
||||
private Object launchTemplate;
|
||||
|
||||
@JsonProperty("tags")
|
||||
private Map<String, String> tags;
|
||||
|
||||
@JsonProperty("clientRequestToken")
|
||||
@JsonIgnore
|
||||
private String clientRequestToken;
|
||||
|
||||
@JsonIgnore
|
||||
private String accountId;
|
||||
|
||||
public Nodegroup() {}
|
||||
|
||||
public String getNodegroupName() { return nodegroupName; }
|
||||
public void setNodegroupName(String nodegroupName) { this.nodegroupName = nodegroupName; }
|
||||
|
||||
public String getNodegroupArn() { return nodegroupArn; }
|
||||
public void setNodegroupArn(String nodegroupArn) { this.nodegroupArn = nodegroupArn; }
|
||||
|
||||
public String getClusterName() { return clusterName; }
|
||||
public void setClusterName(String clusterName) { this.clusterName = clusterName; }
|
||||
|
||||
public String getVersion() { return version; }
|
||||
public void setVersion(String version) { this.version = version; }
|
||||
|
||||
public String getReleaseVersion() { return releaseVersion; }
|
||||
public void setReleaseVersion(String releaseVersion) { this.releaseVersion = releaseVersion; }
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
public Instant getModifiedAt() { return modifiedAt; }
|
||||
public void setModifiedAt(Instant modifiedAt) { this.modifiedAt = modifiedAt; }
|
||||
|
||||
public NodegroupStatus getStatus() { return status; }
|
||||
public void setStatus(NodegroupStatus status) { this.status = status; }
|
||||
|
||||
public String getCapacityType() { return capacityType; }
|
||||
public void setCapacityType(String capacityType) { this.capacityType = capacityType; }
|
||||
|
||||
public NodegroupScalingConfig getScalingConfig() { return scalingConfig; }
|
||||
public void setScalingConfig(NodegroupScalingConfig scalingConfig) { this.scalingConfig = scalingConfig; }
|
||||
|
||||
public List<String> getInstanceTypes() { return instanceTypes; }
|
||||
public void setInstanceTypes(List<String> instanceTypes) { this.instanceTypes = instanceTypes; }
|
||||
|
||||
public List<String> getSubnets() { return subnets; }
|
||||
public void setSubnets(List<String> subnets) { this.subnets = subnets; }
|
||||
|
||||
public Object getRemoteAccess() { return remoteAccess; }
|
||||
public void setRemoteAccess(Object remoteAccess) { this.remoteAccess = remoteAccess; }
|
||||
|
||||
public String getAmiType() { return amiType; }
|
||||
public void setAmiType(String amiType) { this.amiType = amiType; }
|
||||
|
||||
public String getNodeRole() { return nodeRole; }
|
||||
public void setNodeRole(String nodeRole) { this.nodeRole = nodeRole; }
|
||||
|
||||
public Map<String, String> getLabels() { return labels; }
|
||||
public void setLabels(Map<String, String> labels) { this.labels = labels; }
|
||||
|
||||
public List<Object> getTaints() { return taints; }
|
||||
public void setTaints(List<Object> taints) { this.taints = taints; }
|
||||
|
||||
public Object getResources() { return resources; }
|
||||
public void setResources(Object resources) { this.resources = resources; }
|
||||
|
||||
public Integer getDiskSize() { return diskSize; }
|
||||
public void setDiskSize(Integer diskSize) { this.diskSize = diskSize; }
|
||||
|
||||
public Object getHealth() { return health; }
|
||||
public void setHealth(Object health) { this.health = health; }
|
||||
|
||||
public Object getUpdateConfig() { return updateConfig; }
|
||||
public void setUpdateConfig(Object updateConfig) { this.updateConfig = updateConfig; }
|
||||
|
||||
public Object getNodeRepairConfig() { return nodeRepairConfig; }
|
||||
public void setNodeRepairConfig(Object nodeRepairConfig) { this.nodeRepairConfig = nodeRepairConfig; }
|
||||
|
||||
public Object getLaunchTemplate() { return launchTemplate; }
|
||||
public void setLaunchTemplate(Object launchTemplate) { this.launchTemplate = launchTemplate; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
public String getClientRequestToken() { return clientRequestToken; }
|
||||
public void setClientRequestToken(String clientRequestToken) { this.clientRequestToken = clientRequestToken; }
|
||||
|
||||
public String getAccountId() { return accountId; }
|
||||
public void setAccountId(String accountId) { this.accountId = accountId; }
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/** EKS node group scaling configuration (min/max/desired worker count). */
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class NodegroupScalingConfig {
|
||||
|
||||
@JsonProperty("minSize")
|
||||
private Integer minSize;
|
||||
|
||||
@JsonProperty("maxSize")
|
||||
private Integer maxSize;
|
||||
|
||||
@JsonProperty("desiredSize")
|
||||
private Integer desiredSize;
|
||||
|
||||
public NodegroupScalingConfig() {}
|
||||
|
||||
public Integer getMinSize() { return minSize; }
|
||||
public void setMinSize(Integer minSize) { this.minSize = minSize; }
|
||||
|
||||
public Integer getMaxSize() { return maxSize; }
|
||||
public void setMaxSize(Integer maxSize) { this.maxSize = maxSize; }
|
||||
|
||||
public Integer getDesiredSize() { return desiredSize; }
|
||||
public void setDesiredSize(Integer desiredSize) { this.desiredSize = desiredSize; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/** EKS managed node group lifecycle status (serialized as the enum name, e.g. "ACTIVE"). */
|
||||
@RegisterForReflection
|
||||
public enum NodegroupStatus {
|
||||
CREATING,
|
||||
ACTIVE,
|
||||
UPDATING,
|
||||
DELETING,
|
||||
CREATE_FAILED,
|
||||
DELETE_FAILED,
|
||||
DEGRADED
|
||||
}
|
||||
Reference in new issue
Block a user