mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
refactor(cloudformation): move EKS types into EksCfnProvisioner (#3891)
Move AWS::EKS::Cluster and AWS::EKS::Nodegroup out of the CloudFormationResourceProvisioner monolith into a new EksCfnProvisioner over EksService. A nodegroup belongs to a cluster and its delete needs the cluster name, stored as a create-time attribute, so the two share one provisioner. Ref returns the cluster name for a Cluster and the nodegroup name for a Nodegroup, as the legacy switch did. With the arms gone, the monolith no longer needs its eksService dependency, which is dropped. The move preserves Ref, but it is not a pure move for Fn::GetAtt. Leaving LEGACY_SWITCH subjects these types to CfnSchemaCoverageTest, which requires every readOnly attribute to be published or recorded as a gap. The Cluster arm previously set only Arn and Endpoint, so it now also publishes CertificateAuthorityData and OpenIdConnectIssuerUrl (both available from the model), and four attributes Floci does not model (Cluster ClusterSecurityGroupId, EncryptionConfigKeyArn and Id, and Nodegroup Id) are recorded as gap rows. Both deletes tolerate an already-gone resource through CfnDeletes.safeDelete on ResourceNotFoundException.
This commit is contained in:
1 parent
1370dc02fa
commit
efd08b3a77
7 files changed
+321
-74
No files matched your search
-69
@@ -12,9 +12,6 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnDynami
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnResourceProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.UpdateCleanupResult;
|
||||
import io.github.hectorvent.floci.services.eventbridge.model.Target;
|
||||
import io.github.hectorvent.floci.services.eks.EksService;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateClusterRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.Nodegroup;
|
||||
import io.github.hectorvent.floci.services.iam.IamService;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamRole;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
@@ -93,7 +90,6 @@ public class CloudFormationResourceProvisioner {
|
||||
static final Set<String> DELETE_NEEDS_STACK_RESOURCE = Set.of(
|
||||
"AWS::ApiGatewayV2::Authorizer",
|
||||
"AWS::CloudFormation::CustomResource",
|
||||
"AWS::EKS::Nodegroup",
|
||||
"AWS::IAM::ManagedPolicy",
|
||||
"AWS::IAM::Policy");
|
||||
|
||||
@@ -112,8 +108,6 @@ public class CloudFormationResourceProvisioner {
|
||||
"AWS::ApiGatewayV2::Route",
|
||||
"AWS::ApiGatewayV2::Stage",
|
||||
"AWS::CloudFormation::CustomResource",
|
||||
"AWS::EKS::Cluster",
|
||||
"AWS::EKS::Nodegroup",
|
||||
"AWS::IAM::AccessKey",
|
||||
"AWS::IAM::InstanceProfile",
|
||||
"AWS::IAM::ManagedPolicy",
|
||||
@@ -139,7 +133,6 @@ public class CloudFormationResourceProvisioner {
|
||||
private final ObjectMapper objectMapper;
|
||||
private final CustomResourceResponseStore customResourceResponseStore;
|
||||
private final ContainerReachableEndpoint reachableEndpoint;
|
||||
private final EksService eksService;
|
||||
// Item 15 decomposition: extracted per-service provisioners are consulted before the switch
|
||||
// below. As types migrate, their switch cases and provisionXxx methods are removed here; the
|
||||
// now-dead service deps above are cleared in the final cleanup once the switch is empty.
|
||||
@@ -156,7 +149,6 @@ public class CloudFormationResourceProvisioner {
|
||||
ObjectMapper objectMapper,
|
||||
CustomResourceResponseStore customResourceResponseStore,
|
||||
ContainerReachableEndpoint reachableEndpoint,
|
||||
EksService eksService,
|
||||
CloudFormationResourceRegistry resourceRegistry,
|
||||
CfnDynamicReferences dynamicReferences,
|
||||
EmulatorConfig config) {
|
||||
@@ -169,7 +161,6 @@ public class CloudFormationResourceProvisioner {
|
||||
this.objectMapper = objectMapper;
|
||||
this.customResourceResponseStore = customResourceResponseStore;
|
||||
this.reachableEndpoint = reachableEndpoint;
|
||||
this.eksService = eksService;
|
||||
this.resourceRegistry = resourceRegistry;
|
||||
this.dynamicReferences = dynamicReferences;
|
||||
}
|
||||
@@ -239,8 +230,6 @@ public class CloudFormationResourceProvisioner {
|
||||
case "AWS::ApiGatewayV2::Deployment" -> provisionApiGatewayV2Deployment(resource, properties, engine, region);
|
||||
case "AWS::CloudFormation::CustomResource" ->
|
||||
provisionCustomResource(resource, properties, engine, region, accountId, stackName);
|
||||
case "AWS::EKS::Cluster" -> provisionEksCluster(resource, properties, engine, stackName);
|
||||
case "AWS::EKS::Nodegroup" -> provisionEksNodegroup(resource, properties, engine, stackName);
|
||||
default -> {
|
||||
if (resourceType != null && resourceType.startsWith("Custom::")) {
|
||||
provisionCustomResource(resource, properties, engine, region, accountId, stackName);
|
||||
@@ -383,19 +372,6 @@ public class CloudFormationResourceProvisioner {
|
||||
deleteCustomResource(resource, region);
|
||||
return;
|
||||
}
|
||||
// Nodegroup deletion needs both the cluster name (from a Fn::GetAtt attribute) and the
|
||||
// nodegroup name (the physical id), which the type/physicalId delete path can't provide.
|
||||
if ("AWS::EKS::Nodegroup".equals(resourceType)) {
|
||||
String clusterName = resource.getAttributes().get("ClusterName");
|
||||
if (clusterName != null && !clusterName.isBlank()) {
|
||||
try {
|
||||
eksService.deleteNodeGroup(clusterName, resource.getPhysicalId());
|
||||
} catch (Exception e) {
|
||||
LOG.debugv("Error deleting nodegroup {0}: {1}", resource.getPhysicalId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Authorizer deletion needs the api id (a stored attribute, not the physical id, which is
|
||||
// the authorizer id) — same shape as the Nodegroup case above. Without this, the generic
|
||||
// type/physicalId delete path has no case for this type at all and silently no-ops,
|
||||
@@ -453,7 +429,6 @@ public class CloudFormationResourceProvisioner {
|
||||
// No bus context on the type/physicalId path (e.g. CREATE-rollback); targets the default bus.
|
||||
case "AWS::ApiGatewayV2::Api" -> apiGatewayV2Service.deleteApi(region, physicalId);
|
||||
case "AWS::Lambda::LayerVersion" -> deleteLambdaLayerVersion(physicalId, region);
|
||||
case "AWS::EKS::Cluster" -> eksService.deleteCluster(physicalId);
|
||||
// Warn for the same reason the create path does: the delete reports success over a
|
||||
// type nothing here removes, and at debug that is invisible at the default log level.
|
||||
// The line names the physical id without claiming a resource survives it: this arm
|
||||
@@ -523,50 +498,6 @@ public class CloudFormationResourceProvisioner {
|
||||
|
||||
// ── EKS ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
private void provisionEksCluster(StackResource r, JsonNode props, CloudFormationTemplateEngine engine,
|
||||
String stackName) {
|
||||
String name = resolveOptional(props, "Name", engine);
|
||||
if (name == null || name.isBlank()) {
|
||||
name = generatePhysicalName(stackName, r.getLogicalId(), 100, false);
|
||||
}
|
||||
CreateClusterRequest request = new CreateClusterRequest();
|
||||
request.setName(name);
|
||||
request.setVersion(resolveOptional(props, "Version", engine));
|
||||
request.setRoleArn(resolveOptional(props, "RoleArn", engine));
|
||||
var cluster = eksService.createCluster(request);
|
||||
r.setPhysicalId(cluster.getName());
|
||||
r.getAttributes().put("Arn", cluster.getArn());
|
||||
if (cluster.getEndpoint() != null) {
|
||||
r.getAttributes().put("Endpoint", cluster.getEndpoint());
|
||||
}
|
||||
}
|
||||
|
||||
private void provisionEksNodegroup(StackResource r, JsonNode props, CloudFormationTemplateEngine engine,
|
||||
String stackName) {
|
||||
String clusterName = resolveOptional(props, "ClusterName", engine);
|
||||
Nodegroup request = new Nodegroup();
|
||||
String nodegroupName = resolveOptional(props, "NodegroupName", engine);
|
||||
if (nodegroupName == null || nodegroupName.isBlank()) {
|
||||
nodegroupName = generatePhysicalName(stackName, r.getLogicalId(), 100, false);
|
||||
}
|
||||
request.setNodegroupName(nodegroupName);
|
||||
request.setNodeRole(resolveOptional(props, "NodeRole", engine));
|
||||
List<String> subnets = new ArrayList<>();
|
||||
if (props != null && props.has("Subnets") && props.get("Subnets").isArray()) {
|
||||
for (JsonNode subnet : props.get("Subnets")) {
|
||||
subnets.add(engine.resolve(subnet));
|
||||
}
|
||||
}
|
||||
request.setSubnets(subnets);
|
||||
var nodegroup = eksService.createNodeGroup(clusterName, request);
|
||||
r.setPhysicalId(nodegroup.getNodegroupName());
|
||||
r.getAttributes().put("ClusterName", nodegroup.getClusterName());
|
||||
r.getAttributes().put("NodegroupName", nodegroup.getNodegroupName());
|
||||
if (nodegroup.getNodegroupArn() != null) {
|
||||
r.getAttributes().put("Arn", nodegroup.getNodegroupArn());
|
||||
}
|
||||
}
|
||||
|
||||
// ── Lambda ────────────────────────────────────────────────────────────────
|
||||
|
||||
private void provisionLambda(StackResource r, JsonNode props, CloudFormationTemplateEngine engine,
|
||||
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation.provisioners;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
|
||||
import io.github.hectorvent.floci.services.eks.EksService;
|
||||
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.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* CloudFormation provisioning for the EKS control-plane types. {@code AWS::EKS::Cluster} and
|
||||
* {@code AWS::EKS::Nodegroup} share one provisioner over {@link EksService} because a nodegroup
|
||||
* belongs to a cluster and its delete needs the cluster name, which is stored as a create-time
|
||||
* attribute. {@code Ref} returns the cluster name for a Cluster and the nodegroup name for a
|
||||
* Nodegroup, matching what the legacy switch published.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class EksCfnProvisioner implements CfnResourceProvisioner {
|
||||
|
||||
private static final String CLUSTER = "AWS::EKS::Cluster";
|
||||
private static final String NODEGROUP = "AWS::EKS::Nodegroup";
|
||||
|
||||
private final EksService eksService;
|
||||
|
||||
@Inject
|
||||
public EksCfnProvisioner(EksService eksService) {
|
||||
this.eksService = eksService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> resourceTypes() {
|
||||
return Set.of(CLUSTER, NODEGROUP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provision(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
switch (r.getResourceType()) {
|
||||
case CLUSTER -> provisionCluster(r, props, ctx);
|
||||
case NODEGROUP -> provisionNodegroup(r, props, ctx);
|
||||
default -> throw new IllegalStateException("Unhandled type: " + r.getResourceType());
|
||||
}
|
||||
}
|
||||
|
||||
private void provisionCluster(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
String name = ctx.resolveOptional(props, "Name");
|
||||
if (name == null || name.isBlank()) {
|
||||
name = ctx.generatePhysicalName(r.getLogicalId(), 100, false);
|
||||
}
|
||||
CreateClusterRequest request = new CreateClusterRequest();
|
||||
request.setName(name);
|
||||
request.setVersion(ctx.resolveOptional(props, "Version"));
|
||||
request.setRoleArn(ctx.resolveOptional(props, "RoleArn"));
|
||||
|
||||
Cluster cluster = eksService.createCluster(request);
|
||||
r.setPhysicalId(cluster.getName());
|
||||
r.getAttributes().put("Arn", cluster.getArn());
|
||||
if (cluster.getEndpoint() != null) {
|
||||
r.getAttributes().put("Endpoint", cluster.getEndpoint());
|
||||
}
|
||||
if (cluster.getCertificateAuthority() != null && cluster.getCertificateAuthority().getData() != null) {
|
||||
r.getAttributes().put("CertificateAuthorityData", cluster.getCertificateAuthority().getData());
|
||||
}
|
||||
if (cluster.getIdentity() != null && cluster.getIdentity().getOidc() != null
|
||||
&& cluster.getIdentity().getOidc().getIssuer() != null) {
|
||||
r.getAttributes().put("OpenIdConnectIssuerUrl", cluster.getIdentity().getOidc().getIssuer());
|
||||
}
|
||||
}
|
||||
|
||||
private void provisionNodegroup(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
String clusterName = ctx.resolveOptional(props, "ClusterName");
|
||||
Nodegroup request = new Nodegroup();
|
||||
String nodegroupName = ctx.resolveOptional(props, "NodegroupName");
|
||||
if (nodegroupName == null || nodegroupName.isBlank()) {
|
||||
nodegroupName = ctx.generatePhysicalName(r.getLogicalId(), 100, false);
|
||||
}
|
||||
request.setNodegroupName(nodegroupName);
|
||||
request.setNodeRole(ctx.resolveOptional(props, "NodeRole"));
|
||||
request.setSubnets(ctx.resolveStringList(props, "Subnets"));
|
||||
|
||||
Nodegroup nodegroup = eksService.createNodeGroup(clusterName, request);
|
||||
r.setPhysicalId(nodegroup.getNodegroupName());
|
||||
// ClusterName is stored so delete() can find the cluster, and NodegroupName mirrors the
|
||||
// physical id; Arn is the schema's read-only attribute.
|
||||
r.getAttributes().put("ClusterName", nodegroup.getClusterName());
|
||||
r.getAttributes().put("NodegroupName", nodegroup.getNodegroupName());
|
||||
if (nodegroup.getNodegroupArn() != null) {
|
||||
r.getAttributes().put("Arn", nodegroup.getNodegroupArn());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(StackResource resource, String region) {
|
||||
switch (resource.getResourceType()) {
|
||||
case CLUSTER -> CfnDeletes.safeDelete("EKS cluster", resource.getPhysicalId(),
|
||||
() -> eksService.deleteCluster(resource.getPhysicalId()), "ResourceNotFoundException");
|
||||
case NODEGROUP -> {
|
||||
// Deleting a nodegroup needs the cluster name (a create-time attribute) as well as
|
||||
// the nodegroup name (the physical id), which the id-only delete path cannot supply.
|
||||
String clusterName = resource.getAttributes().get("ClusterName");
|
||||
if (clusterName != null && !clusterName.isBlank()) {
|
||||
CfnDeletes.safeDelete("EKS nodegroup", resource.getPhysicalId(),
|
||||
() -> eksService.deleteNodeGroup(clusterName, resource.getPhysicalId()),
|
||||
"ResourceNotFoundException");
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
// No other type reaches this provisioner's delete.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user