mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
Nodegroups eks fargate eks (#1523)
* feat(eks): add nodegroups and fargate profiles * docs: sync generated action tables
This commit is contained in:
1 parent
43a80381ee
commit
095e167bae
11 files changed
+1069
-192
No files matched your search
+2
-2
@@ -396,7 +396,7 @@ public class CloudFormationResourceProvisioner {
|
||||
String clusterName = resource.getAttributes().get("ClusterName");
|
||||
if (clusterName != null && !clusterName.isBlank()) {
|
||||
try {
|
||||
eksService.deleteNodegroup(clusterName, resource.getPhysicalId());
|
||||
eksService.deleteNodeGroup(clusterName, resource.getPhysicalId());
|
||||
} catch (Exception e) {
|
||||
LOG.debugv("Error deleting nodegroup {0}: {1}", resource.getPhysicalId(), e.getMessage());
|
||||
}
|
||||
@@ -1107,7 +1107,7 @@ public class CloudFormationResourceProvisioner {
|
||||
}
|
||||
}
|
||||
request.setSubnets(subnets);
|
||||
var nodegroup = eksService.createNodegroup(clusterName, request);
|
||||
var nodegroup = eksService.createNodeGroup(clusterName, request);
|
||||
r.setPhysicalId(nodegroup.getNodegroupName());
|
||||
r.getAttributes().put("ClusterName", nodegroup.getClusterName());
|
||||
r.getAttributes().put("NodegroupName", nodegroup.getNodegroupName());
|
||||
|
||||
@@ -2,6 +2,9 @@ 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.CreateFargateProfileRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateNodeGroupRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.FargateProfile;
|
||||
import io.github.hectorvent.floci.services.eks.model.Nodegroup;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
@@ -11,7 +14,6 @@ import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@@ -21,7 +23,9 @@ import java.util.Map;
|
||||
/**
|
||||
* EKS REST-JSON controller.
|
||||
*
|
||||
* <p>EKS uses standard HTTP verbs with JSON bodies — not JSON 1.1 (X-Amz-Target) or Query protocol.
|
||||
* <p>
|
||||
* EKS uses standard HTTP verbs with JSON bodies — not JSON 1.1 (X-Amz-Target)
|
||||
* or Query protocol.
|
||||
*/
|
||||
@Path("/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@@ -44,8 +48,7 @@ public class EksController {
|
||||
|
||||
@GET
|
||||
@Path("/clusters")
|
||||
public Response listClusters(@QueryParam("nextToken") String nextToken,
|
||||
@QueryParam("maxResults") Integer maxResults) {
|
||||
public Response listClusters() {
|
||||
List<String> clusterNames = eksService.listClusters();
|
||||
return Response.ok(Map.of("clusters", clusterNames)).build();
|
||||
}
|
||||
@@ -64,37 +67,65 @@ 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).
|
||||
|
||||
// Keep these concrete EKS resource paths declared explicitly so they outrank
|
||||
// the S3 catch-all route; see 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();
|
||||
public Response createNodeGroup(@PathParam("name") String name, CreateNodeGroupRequest 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();
|
||||
public Response listNodeGroups(@PathParam("name") String name) {
|
||||
List<String> nodeGroupNames = eksService.listNodeGroups(name);
|
||||
return Response.ok(Map.of("nodegroups", nodeGroupNames)).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();
|
||||
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();
|
||||
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();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/clusters/{name}/fargate-profiles")
|
||||
public Response createFargateProfile(@PathParam("name") String name, CreateFargateProfileRequest request) {
|
||||
FargateProfile profile = eksService.createFargateProfile(name, request);
|
||||
return Response.ok(Map.of("fargateProfile", profile)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/fargate-profiles")
|
||||
public Response listFargateProfiles(@PathParam("name") String name) {
|
||||
List<String> profileNames = eksService.listFargateProfiles(name);
|
||||
return Response.ok(Map.of("fargateProfileNames", profileNames)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/fargate-profiles/{fargateProfileName}")
|
||||
public Response describeFargateProfile(@PathParam("name") String name,
|
||||
@PathParam("fargateProfileName") String fargateProfileName) {
|
||||
FargateProfile profile = eksService.describeFargateProfile(name, fargateProfileName);
|
||||
return Response.ok(Map.of("fargateProfile", profile)).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/clusters/{name}/fargate-profiles/{fargateProfileName}")
|
||||
public Response deleteFargateProfile(@PathParam("name") String name,
|
||||
@PathParam("fargateProfileName") String fargateProfileName) {
|
||||
FargateProfile profile = eksService.deleteFargateProfile(name, fargateProfileName);
|
||||
return Response.ok(Map.of("fargateProfile", profile)).build();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,10 @@ import io.github.hectorvent.floci.services.eks.model.CertificateAuthority;
|
||||
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.CreateFargateProfileRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateNodeGroupRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.FargateProfile;
|
||||
import io.github.hectorvent.floci.services.eks.model.FargateProfileStatus;
|
||||
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;
|
||||
@@ -42,7 +46,8 @@ 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 StorageBackend<String, Nodegroup> nodeGroupStorage;
|
||||
private final StorageBackend<String, FargateProfile> fargateProfileStorage;
|
||||
private final EmulatorConfig config;
|
||||
private final RegionResolver regionResolver;
|
||||
private final EksClusterManager clusterManager;
|
||||
@@ -50,11 +55,16 @@ public class EksService implements TagHandler {
|
||||
|
||||
@Inject
|
||||
public EksService(StorageFactory storageFactory, EmulatorConfig config,
|
||||
RegionResolver regionResolver, EksClusterManager clusterManager) {
|
||||
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>>() {});
|
||||
new TypeReference<Map<String, Cluster>>() {
|
||||
});
|
||||
this.nodeGroupStorage = storageFactory.create("eks", "eks-nodegroups.json",
|
||||
new TypeReference<Map<String, Nodegroup>>() {
|
||||
});
|
||||
this.fargateProfileStorage = storageFactory.create("eks", "eks-fargate-profiles.json",
|
||||
new TypeReference<Map<String, FargateProfile>>() {
|
||||
});
|
||||
this.config = config;
|
||||
this.regionResolver = regionResolver;
|
||||
this.clusterManager = clusterManager;
|
||||
@@ -146,13 +156,31 @@ public class EksService implements TagHandler {
|
||||
return cluster;
|
||||
}
|
||||
|
||||
// ──────────────────────────── Managed node groups ────────────────────────────
|
||||
public Nodegroup createNodeGroup(String clusterName, CreateNodeGroupRequest request) {
|
||||
Nodegroup nodegroup = new Nodegroup();
|
||||
nodegroup.setNodegroupName(request.getNodegroupName());
|
||||
nodegroup.setVersion(request.getVersion());
|
||||
nodegroup.setReleaseVersion(request.getReleaseVersion());
|
||||
nodegroup.setSubnets(request.getSubnets());
|
||||
nodegroup.setNodeRole(request.getNodeRole());
|
||||
nodegroup.setAmiType(request.getAmiType());
|
||||
nodegroup.setCapacityType(request.getCapacityType());
|
||||
nodegroup.setDiskSize(request.getDiskSize());
|
||||
nodegroup.setInstanceTypes(request.getInstanceTypes());
|
||||
nodegroup.setScalingConfig(request.getScalingConfig());
|
||||
nodegroup.setUpdateConfig(request.getUpdateConfig());
|
||||
nodegroup.setLabels(request.getLabels());
|
||||
nodegroup.setTags(request.getTags());
|
||||
nodegroup.setClientRequestToken(request.getClientRequestToken());
|
||||
return createNodeGroup(clusterName, nodegroup);
|
||||
}
|
||||
|
||||
public Nodegroup createNodegroup(String clusterName, Nodegroup request) {
|
||||
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);
|
||||
throw new AwsException("InvalidParameterException", "Nodegroup name is required", 400);
|
||||
}
|
||||
if (request.getNodeRole() == null || request.getNodeRole().isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "nodeRole is required", 400);
|
||||
@@ -160,87 +188,132 @@ public class EksService implements TagHandler {
|
||||
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()) {
|
||||
|
||||
String storageKey = nodeGroupKey(clusterName, nodegroupName);
|
||||
if (nodeGroupStorage.get(storageKey).isPresent()) {
|
||||
throw new AwsException("ResourceInUseException",
|
||||
"NodeGroup already exists: " + nodegroupName, 409);
|
||||
"Nodegroup already exists: " + nodegroupName, 409);
|
||||
}
|
||||
|
||||
String region = config.defaultRegion();
|
||||
String accountId = regionResolver.getAccountId();
|
||||
String id = UUID.randomUUID().toString();
|
||||
String arn = AwsArnUtils.Arn.of("eks", region, accountId,
|
||||
"nodegroup/" + clusterName + "/" + nodegroupName + "/" + id).toString();
|
||||
|
||||
Instant now = Instant.now();
|
||||
Nodegroup nodeGroup = new Nodegroup();
|
||||
nodeGroup.setNodegroupName(nodegroupName);
|
||||
nodeGroup.setNodegroupArn(arn);
|
||||
nodeGroup.setClusterName(clusterName);
|
||||
nodeGroup.setAccountId(accountId);
|
||||
nodeGroup.setCreatedAt(now);
|
||||
nodeGroup.setModifiedAt(now);
|
||||
String resolvedVersion = request.getVersion() != null ? request.getVersion() : cluster.getVersion();
|
||||
nodeGroup.setVersion(resolvedVersion);
|
||||
nodeGroup.setReleaseVersion(request.getReleaseVersion() != null
|
||||
? request.getReleaseVersion() : resolvedVersion + "-eks-1");
|
||||
nodeGroup.setStatus(NodegroupStatus.ACTIVE);
|
||||
nodeGroup.setCapacityType(request.getCapacityType() != null ? request.getCapacityType() : "ON_DEMAND");
|
||||
nodeGroup.setScalingConfig(request.getScalingConfig() != null ? request.getScalingConfig() : defaultScalingConfig());
|
||||
nodeGroup.setInstanceTypes(request.getInstanceTypes() != null ? request.getInstanceTypes() : List.of("t3.medium"));
|
||||
nodeGroup.setSubnets(request.getSubnets() != null ? request.getSubnets() : List.of());
|
||||
nodeGroup.setAmiType(request.getAmiType() != null ? request.getAmiType() : "AL2_x86_64");
|
||||
nodeGroup.setNodeRole(request.getNodeRole());
|
||||
nodeGroup.setDiskSize(request.getDiskSize() != null ? request.getDiskSize() : 20);
|
||||
nodeGroup.setResources(defaultNodeGroupResources(nodegroupName));
|
||||
nodeGroup.setHealth(defaultNodeGroupHealth());
|
||||
nodeGroup.setUpdateConfig(request.getUpdateConfig() != null ? request.getUpdateConfig() : defaultUpdateConfig());
|
||||
nodeGroup.setLabels(request.getLabels() != null ? new HashMap<>(request.getLabels()) : null);
|
||||
nodeGroup.setTags(request.getTags() != null ? new HashMap<>(request.getTags()) : new HashMap<>());
|
||||
|
||||
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;
|
||||
nodeGroupStorage.put(storageKey, nodeGroup);
|
||||
return nodeGroup;
|
||||
}
|
||||
|
||||
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) {
|
||||
public Nodegroup describeNodeGroup(String clusterName, String nodegroupName) {
|
||||
describeCluster(clusterName);
|
||||
return nodegroupStorage.scan(k -> true).stream()
|
||||
.filter(ng -> clusterName.equals(ng.getClusterName()))
|
||||
return nodeGroupStorage.get(nodeGroupKey(clusterName, nodegroupName))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"No nodegroup found for name: " + nodegroupName, 404));
|
||||
}
|
||||
|
||||
public List<String> listNodeGroups(String clusterName) {
|
||||
describeCluster(clusterName);
|
||||
String prefix = clusterName + "/";
|
||||
return nodeGroupStorage.scan(key -> key.startsWith(prefix)).stream()
|
||||
.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;
|
||||
public Nodegroup deleteNodeGroup(String clusterName, String nodegroupName) {
|
||||
Nodegroup nodeGroup = describeNodeGroup(clusterName, nodegroupName);
|
||||
nodeGroup.setStatus(NodegroupStatus.DELETING);
|
||||
nodeGroup.setModifiedAt(Instant.now());
|
||||
nodeGroupStorage.delete(nodeGroupKey(clusterName, nodegroupName));
|
||||
return nodeGroup;
|
||||
}
|
||||
|
||||
private String nodegroupKey(String clusterName, String nodegroupName) {
|
||||
return clusterName + "/" + nodegroupName;
|
||||
public FargateProfile createFargateProfile(String clusterName, CreateFargateProfileRequest request) {
|
||||
describeCluster(clusterName);
|
||||
|
||||
String fargateProfileName = request.getFargateProfileName();
|
||||
if (fargateProfileName == null || fargateProfileName.isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "Fargate profile name is required", 400);
|
||||
}
|
||||
if (request.getPodExecutionRoleArn() == null || request.getPodExecutionRoleArn().isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "podExecutionRoleArn is required", 400);
|
||||
}
|
||||
|
||||
String storageKey = fargateProfileKey(clusterName, fargateProfileName);
|
||||
if (fargateProfileStorage.get(storageKey).isPresent()) {
|
||||
throw new AwsException("ResourceInUseException",
|
||||
"Fargate profile already exists: " + fargateProfileName, 409);
|
||||
}
|
||||
|
||||
String region = config.defaultRegion();
|
||||
String accountId = regionResolver.getAccountId();
|
||||
String id = UUID.randomUUID().toString();
|
||||
String arn = AwsArnUtils.Arn.of("eks", region, accountId,
|
||||
"fargateprofile/" + clusterName + "/" + fargateProfileName + "/" + id).toString();
|
||||
|
||||
FargateProfile profile = new FargateProfile();
|
||||
profile.setFargateProfileName(fargateProfileName);
|
||||
profile.setFargateProfileArn(arn);
|
||||
profile.setClusterName(clusterName);
|
||||
profile.setAccountId(accountId);
|
||||
profile.setCreatedAt(Instant.now());
|
||||
profile.setPodExecutionRoleArn(request.getPodExecutionRoleArn());
|
||||
profile.setSubnets(request.getSubnets() != null ? request.getSubnets() : List.of());
|
||||
profile.setSelectors(request.getSelectors() != null ? request.getSelectors() : List.of());
|
||||
profile.setStatus(FargateProfileStatus.ACTIVE);
|
||||
profile.setHealth(defaultFargateProfileHealth());
|
||||
profile.setTags(request.getTags() != null ? new HashMap<>(request.getTags()) : new HashMap<>());
|
||||
|
||||
fargateProfileStorage.put(storageKey, profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
public FargateProfile describeFargateProfile(String clusterName, String fargateProfileName) {
|
||||
describeCluster(clusterName);
|
||||
return fargateProfileStorage.get(fargateProfileKey(clusterName, fargateProfileName))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"No fargate profile found for name: " + fargateProfileName, 404));
|
||||
}
|
||||
|
||||
public List<String> listFargateProfiles(String clusterName) {
|
||||
describeCluster(clusterName);
|
||||
String prefix = clusterName + "/";
|
||||
return fargateProfileStorage.scan(key -> key.startsWith(prefix)).stream()
|
||||
.map(FargateProfile::getFargateProfileName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public FargateProfile deleteFargateProfile(String clusterName, String fargateProfileName) {
|
||||
FargateProfile profile = describeFargateProfile(clusterName, fargateProfileName);
|
||||
profile.setStatus(FargateProfileStatus.DELETING);
|
||||
fargateProfileStorage.delete(fargateProfileKey(clusterName, fargateProfileName));
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -313,9 +386,12 @@ public class EksService implements TagHandler {
|
||||
response.setSubnetIds(request.getSubnetIds() != null ? request.getSubnetIds() : List.of());
|
||||
response.setSecurityGroupIds(request.getSecurityGroupIds() != null ? request.getSecurityGroupIds() : List.of());
|
||||
response.setVpcId(request.getVpcId() != null ? request.getVpcId() : "");
|
||||
response.setEndpointPublicAccess(request.getEndpointPublicAccess() != null ? request.getEndpointPublicAccess() : Boolean.TRUE);
|
||||
response.setEndpointPrivateAccess(request.getEndpointPrivateAccess() != null ? request.getEndpointPrivateAccess() : Boolean.FALSE);
|
||||
response.setPublicAccessCidrs(request.getPublicAccessCidrs() != null ? request.getPublicAccessCidrs() : List.of("0.0.0.0/0"));
|
||||
response.setEndpointPublicAccess(
|
||||
request.getEndpointPublicAccess() != null ? request.getEndpointPublicAccess() : Boolean.TRUE);
|
||||
response.setEndpointPrivateAccess(
|
||||
request.getEndpointPrivateAccess() != null ? request.getEndpointPrivateAccess() : Boolean.FALSE);
|
||||
response.setPublicAccessCidrs(
|
||||
request.getPublicAccessCidrs() != null ? request.getPublicAccessCidrs() : List.of("0.0.0.0/0"));
|
||||
} else {
|
||||
response.setSubnetIds(List.of());
|
||||
response.setSecurityGroupIds(List.of());
|
||||
@@ -339,6 +415,46 @@ public class EksService implements TagHandler {
|
||||
return config;
|
||||
}
|
||||
|
||||
private String nodeGroupKey(String clusterName, String nodegroupName) {
|
||||
return clusterName + "/" + nodegroupName;
|
||||
}
|
||||
|
||||
private String fargateProfileKey(String clusterName, String fargateProfileName) {
|
||||
return clusterName + "/" + fargateProfileName;
|
||||
}
|
||||
|
||||
private NodegroupScalingConfig defaultScalingConfig() {
|
||||
NodegroupScalingConfig scalingConfig = new NodegroupScalingConfig();
|
||||
scalingConfig.setMinSize(1);
|
||||
scalingConfig.setMaxSize(1);
|
||||
scalingConfig.setDesiredSize(1);
|
||||
return scalingConfig;
|
||||
}
|
||||
|
||||
private Map<String, Integer> defaultUpdateConfig() {
|
||||
return Map.of("maxUnavailable", 1);
|
||||
}
|
||||
|
||||
private Map<String, Object> defaultNodeGroupResources(String nodegroupName) {
|
||||
Map<String, Object> resources = new LinkedHashMap<>();
|
||||
Map<String, Object> autoScalingGroup = new LinkedHashMap<>();
|
||||
autoScalingGroup.put("name", "eks-" + nodegroupName + "-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
resources.put("autoScalingGroups", List.of(autoScalingGroup));
|
||||
return resources;
|
||||
}
|
||||
|
||||
private Map<String, List<Object>> defaultNodeGroupHealth() {
|
||||
Map<String, List<Object>> health = new LinkedHashMap<>();
|
||||
health.put("issues", new ArrayList<>());
|
||||
return health;
|
||||
}
|
||||
|
||||
private FargateProfile.Health defaultFargateProfileHealth() {
|
||||
FargateProfile.Health health = new FargateProfile.Health();
|
||||
health.setIssues(List.of());
|
||||
return health;
|
||||
}
|
||||
|
||||
private void startReadinessPoller() {
|
||||
poller.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CreateFargateProfileRequest {
|
||||
|
||||
@JsonProperty("fargateProfileName")
|
||||
private String fargateProfileName;
|
||||
|
||||
@JsonProperty("podExecutionRoleArn")
|
||||
private String podExecutionRoleArn;
|
||||
|
||||
@JsonProperty("subnets")
|
||||
private List<String> subnets;
|
||||
|
||||
@JsonProperty("selectors")
|
||||
private List<FargateProfile.Selector> selectors;
|
||||
|
||||
@JsonProperty("clientRequestToken")
|
||||
private String clientRequestToken;
|
||||
|
||||
@JsonProperty("tags")
|
||||
private Map<String, String> tags;
|
||||
|
||||
public CreateFargateProfileRequest() {}
|
||||
|
||||
public String getFargateProfileName() { return fargateProfileName; }
|
||||
public void setFargateProfileName(String fargateProfileName) { this.fargateProfileName = fargateProfileName; }
|
||||
|
||||
public String getPodExecutionRoleArn() { return podExecutionRoleArn; }
|
||||
public void setPodExecutionRoleArn(String podExecutionRoleArn) { this.podExecutionRoleArn = podExecutionRoleArn; }
|
||||
|
||||
public List<String> getSubnets() { return subnets; }
|
||||
public void setSubnets(List<String> subnets) { this.subnets = subnets; }
|
||||
|
||||
public List<FargateProfile.Selector> getSelectors() { return selectors; }
|
||||
public void setSelectors(List<FargateProfile.Selector> selectors) { this.selectors = selectors; }
|
||||
|
||||
public String getClientRequestToken() { return clientRequestToken; }
|
||||
public void setClientRequestToken(String clientRequestToken) { this.clientRequestToken = clientRequestToken; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CreateNodeGroupRequest {
|
||||
|
||||
@JsonProperty("nodegroupName")
|
||||
private String nodegroupName;
|
||||
|
||||
@JsonProperty("version")
|
||||
private String version;
|
||||
|
||||
@JsonProperty("releaseVersion")
|
||||
private String releaseVersion;
|
||||
|
||||
@JsonProperty("subnets")
|
||||
private List<String> subnets;
|
||||
|
||||
@JsonProperty("nodeRole")
|
||||
private String nodeRole;
|
||||
|
||||
@JsonProperty("amiType")
|
||||
private String amiType;
|
||||
|
||||
@JsonProperty("capacityType")
|
||||
private String capacityType;
|
||||
|
||||
@JsonProperty("diskSize")
|
||||
private Integer diskSize;
|
||||
|
||||
@JsonProperty("instanceTypes")
|
||||
private List<String> instanceTypes;
|
||||
|
||||
@JsonProperty("scalingConfig")
|
||||
private NodegroupScalingConfig scalingConfig;
|
||||
|
||||
@JsonProperty("updateConfig")
|
||||
private Object updateConfig;
|
||||
|
||||
@JsonProperty("labels")
|
||||
private Map<String, String> labels;
|
||||
|
||||
@JsonProperty("tags")
|
||||
private Map<String, String> tags;
|
||||
|
||||
@JsonProperty("clientRequestToken")
|
||||
private String clientRequestToken;
|
||||
|
||||
public CreateNodeGroupRequest() {}
|
||||
|
||||
public String getNodegroupName() { return nodegroupName; }
|
||||
public void setNodegroupName(String nodegroupName) { this.nodegroupName = nodegroupName; }
|
||||
|
||||
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 List<String> getSubnets() { return subnets; }
|
||||
public void setSubnets(List<String> subnets) { this.subnets = subnets; }
|
||||
|
||||
public String getNodeRole() { return nodeRole; }
|
||||
public void setNodeRole(String nodeRole) { this.nodeRole = nodeRole; }
|
||||
|
||||
public String getAmiType() { return amiType; }
|
||||
public void setAmiType(String amiType) { this.amiType = amiType; }
|
||||
|
||||
public String getCapacityType() { return capacityType; }
|
||||
public void setCapacityType(String capacityType) { this.capacityType = capacityType; }
|
||||
|
||||
public Integer getDiskSize() { return diskSize; }
|
||||
public void setDiskSize(Integer diskSize) { this.diskSize = diskSize; }
|
||||
|
||||
public List<String> getInstanceTypes() { return instanceTypes; }
|
||||
public void setInstanceTypes(List<String> instanceTypes) { this.instanceTypes = instanceTypes; }
|
||||
|
||||
public NodegroupScalingConfig getScalingConfig() { return scalingConfig; }
|
||||
public void setScalingConfig(NodegroupScalingConfig scalingConfig) { this.scalingConfig = scalingConfig; }
|
||||
|
||||
public Object getUpdateConfig() { return updateConfig; }
|
||||
public void setUpdateConfig(Object updateConfig) { this.updateConfig = updateConfig; }
|
||||
|
||||
public Map<String, String> getLabels() { return labels; }
|
||||
public void setLabels(Map<String, String> labels) { this.labels = labels; }
|
||||
|
||||
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; }
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
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.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;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class FargateProfile {
|
||||
|
||||
@JsonProperty("fargateProfileName")
|
||||
private String fargateProfileName;
|
||||
|
||||
@JsonProperty("fargateProfileArn")
|
||||
private String fargateProfileArn;
|
||||
|
||||
@JsonProperty("clusterName")
|
||||
private String clusterName;
|
||||
|
||||
@JsonProperty("createdAt")
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant createdAt;
|
||||
|
||||
@JsonProperty("podExecutionRoleArn")
|
||||
private String podExecutionRoleArn;
|
||||
|
||||
@JsonProperty("subnets")
|
||||
private List<String> subnets;
|
||||
|
||||
@JsonProperty("selectors")
|
||||
private List<Selector> selectors;
|
||||
|
||||
@JsonProperty("status")
|
||||
private FargateProfileStatus status;
|
||||
|
||||
@JsonProperty("health")
|
||||
private Health health;
|
||||
|
||||
@JsonProperty("tags")
|
||||
private Map<String, String> tags;
|
||||
|
||||
@JsonIgnore
|
||||
private String accountId;
|
||||
|
||||
public FargateProfile() {}
|
||||
|
||||
public String getFargateProfileName() { return fargateProfileName; }
|
||||
public void setFargateProfileName(String fargateProfileName) { this.fargateProfileName = fargateProfileName; }
|
||||
|
||||
public String getFargateProfileArn() { return fargateProfileArn; }
|
||||
public void setFargateProfileArn(String fargateProfileArn) { this.fargateProfileArn = fargateProfileArn; }
|
||||
|
||||
public String getClusterName() { return clusterName; }
|
||||
public void setClusterName(String clusterName) { this.clusterName = clusterName; }
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
public String getPodExecutionRoleArn() { return podExecutionRoleArn; }
|
||||
public void setPodExecutionRoleArn(String podExecutionRoleArn) { this.podExecutionRoleArn = podExecutionRoleArn; }
|
||||
|
||||
public List<String> getSubnets() { return subnets; }
|
||||
public void setSubnets(List<String> subnets) { this.subnets = subnets; }
|
||||
|
||||
public List<Selector> getSelectors() { return selectors; }
|
||||
public void setSelectors(List<Selector> selectors) { this.selectors = selectors; }
|
||||
|
||||
public FargateProfileStatus getStatus() { return status; }
|
||||
public void setStatus(FargateProfileStatus status) { this.status = status; }
|
||||
|
||||
public Health getHealth() { return health; }
|
||||
public void setHealth(Health health) { this.health = health; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
public String getAccountId() { return accountId; }
|
||||
public void setAccountId(String accountId) { this.accountId = accountId; }
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Selector {
|
||||
@JsonProperty("namespace")
|
||||
private String namespace;
|
||||
|
||||
@JsonProperty("labels")
|
||||
private Map<String, String> labels;
|
||||
|
||||
public Selector() {}
|
||||
|
||||
public String getNamespace() { return namespace; }
|
||||
public void setNamespace(String namespace) { this.namespace = namespace; }
|
||||
|
||||
public Map<String, String> getLabels() { return labels; }
|
||||
public void setLabels(Map<String, String> labels) { this.labels = labels; }
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Health {
|
||||
@JsonProperty("issues")
|
||||
private List<Issue> issues;
|
||||
|
||||
public Health() {}
|
||||
|
||||
public List<Issue> getIssues() { return issues; }
|
||||
public void setIssues(List<Issue> issues) { this.issues = issues; }
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Issue {
|
||||
@JsonProperty("code")
|
||||
private String code;
|
||||
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
|
||||
@JsonProperty("resourceIds")
|
||||
private List<String> resourceIds;
|
||||
|
||||
public Issue() {}
|
||||
|
||||
public String getCode() { return code; }
|
||||
public void setCode(String code) { this.code = code; }
|
||||
|
||||
public String getMessage() { return message; }
|
||||
public void setMessage(String message) { this.message = message; }
|
||||
|
||||
public List<String> getResourceIds() { return resourceIds; }
|
||||
public void setResourceIds(List<String> resourceIds) { this.resourceIds = resourceIds; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
public enum FargateProfileStatus {
|
||||
CREATING, ACTIVE, DELETING, CREATE_FAILED, DELETE_FAILED
|
||||
}
|
||||
Reference in new issue
Block a user