mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(eks): accept EKS Auto Mode's cluster configuration (#8940)
* feat(eks): accept EKS Auto Mode's cluster configuration * fix(eks): create Auto Mode clusters from CloudFormation, refuse a lone node role * fix(eks): leave EKS Auto Mode out of AWS::EKS::Cluster until step 2
This commit is contained in:
1 parent
3316d46df3
commit
10824e6701
13 files changed
+337
-5
No files matched your search
+13
-5
@@ -10,6 +10,7 @@ import io.floci.aws.services.cloudformation.model.StackResource;
|
||||
import io.floci.aws.services.eks.EksService;
|
||||
import io.floci.aws.services.eks.model.Cluster;
|
||||
import io.floci.aws.services.eks.model.CreateClusterRequest;
|
||||
import io.floci.aws.services.eks.model.KubernetesNetworkConfig;
|
||||
import io.floci.aws.services.eks.model.LogSetup;
|
||||
import io.floci.aws.services.eks.model.Logging;
|
||||
import io.floci.aws.services.eks.model.Nodegroup;
|
||||
@@ -115,8 +116,14 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
|
||||
Map<String, String> templateTags = ctx.resolveTags(props, "Tags");
|
||||
request.setTags(templateTags);
|
||||
request.setEncryptionConfig(createSetting(props, "EncryptionConfig", ctx, new TypeReference<>() { }));
|
||||
request.setKubernetesNetworkConfig(
|
||||
createSetting(props, "KubernetesNetworkConfig", ctx, new TypeReference<>() { }));
|
||||
KubernetesNetworkConfig network =
|
||||
createSetting(props, "KubernetesNetworkConfig", ctx, new TypeReference<>() { });
|
||||
if (network != null) {
|
||||
// EKS Auto Mode stays out until ComputeConfig and StorageConfig go with it: CreateCluster refuses load
|
||||
// balancing without the other two.
|
||||
network.setElasticLoadBalancing(null);
|
||||
}
|
||||
request.setKubernetesNetworkConfig(network);
|
||||
request.setResourcesVpcConfig(createSetting(props, "ResourcesVpcConfig", ctx, new TypeReference<>() { }));
|
||||
request.setAccessConfig(createSetting(props, "AccessConfig", ctx, new TypeReference<>() { }));
|
||||
request.setLogging(logging(props, ctx));
|
||||
@@ -140,9 +147,10 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
|
||||
/**
|
||||
* A property in its API request shape, or null when the template leaves it out. The
|
||||
* template value is read against the type the resource schema declares, so a value of another type
|
||||
* fails the resource with CloudFormation's wording. The request model has no ElasticLoadBalancing
|
||||
* or ServiceIpv6Cidr member of KubernetesNetworkConfig and no ControlPlaneEgressMode member of
|
||||
* ResourcesVpcConfig, so those are not read.
|
||||
* fails the resource with CloudFormation's wording. The request model has no ServiceIpv6Cidr member
|
||||
* of KubernetesNetworkConfig and no ControlPlaneEgressMode member of ResourcesVpcConfig, so those
|
||||
* are not read, and a create leaves out KubernetesNetworkConfig's ElasticLoadBalancing, as it does
|
||||
* EKS Auto Mode's other settings.
|
||||
*/
|
||||
private static <T> T createSetting(JsonNode props, String name, ProvisionContext ctx, TypeReference<T> type) {
|
||||
JsonNode resolved = readSetting(props, name, ctx);
|
||||
|
||||
@@ -35,6 +35,7 @@ import io.floci.aws.services.eks.model.CertificateAuthority;
|
||||
import io.floci.aws.services.eks.model.Cluster;
|
||||
import io.floci.aws.services.eks.model.ClusterIdentity;
|
||||
import io.floci.aws.services.eks.model.ClusterStatus;
|
||||
import io.floci.aws.services.eks.model.ComputeConfig;
|
||||
import io.floci.aws.services.eks.model.CreateClusterRequest;
|
||||
import io.floci.aws.services.eks.model.CreateFargateProfileRequest;
|
||||
import io.floci.aws.services.eks.model.CreateNodeGroupRequest;
|
||||
@@ -50,6 +51,7 @@ import io.floci.aws.services.eks.model.NodegroupStatus;
|
||||
import io.floci.aws.services.eks.model.OidcIdentity;
|
||||
import io.floci.aws.services.eks.model.Provider;
|
||||
import io.floci.aws.services.eks.model.ResourcesVpcConfig;
|
||||
import io.floci.aws.services.eks.model.StorageConfig;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -758,6 +760,38 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuses the EKS Auto Mode configurations AWS refuses, with its errors. Its compute, block storage
|
||||
* and load balancing capabilities "must all be enabled or disabled in the same request", and node
|
||||
* pools launch their nodes with the node role, so a compute configuration naming pools names it.
|
||||
*/
|
||||
private static void validateAutoMode(ComputeConfig compute, StorageConfig storage,
|
||||
KubernetesNetworkConfig network) {
|
||||
boolean computeEnabled = compute != null && Boolean.TRUE.equals(compute.enabled());
|
||||
boolean blockStorageEnabled = storage != null && storage.blockStorage() != null
|
||||
&& Boolean.TRUE.equals(storage.blockStorage().enabled());
|
||||
boolean loadBalancingEnabled = network != null && network.getElasticLoadBalancing() != null
|
||||
&& Boolean.TRUE.equals(network.getElasticLoadBalancing().enabled());
|
||||
if (computeEnabled != blockStorageEnabled || computeEnabled != loadBalancingEnabled) {
|
||||
throw new AwsException("InvalidParameterException", "For EKS Auto Mode, please ensure that all "
|
||||
+ "required configs, including computeConfig, kubernetesNetworkConfig, and blockStorage are "
|
||||
+ "all either fully enabled or fully disabled.", 400);
|
||||
}
|
||||
if (compute == null) {
|
||||
return;
|
||||
}
|
||||
boolean hasNodePools = compute.nodePools() != null && !compute.nodePools().isEmpty();
|
||||
boolean hasNodeRole = compute.nodeRoleArn() != null && !compute.nodeRoleArn().isEmpty();
|
||||
if (hasNodePools && !hasNodeRole) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"When Compute Config nodeRoleArn is null or empty, nodePool list cannot be populated", 400);
|
||||
}
|
||||
if (hasNodeRole && !hasNodePools) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"When Compute Config nodeRoleArn is not null or empty, nodePool value(s) must be provided.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private Cluster createReservedCluster(CreateClusterRequest request, String name) {
|
||||
AccessConfig requestedAccess = request.getAccessConfig();
|
||||
String authenticationMode = requestedAccess == null || requestedAccess.authenticationMode() == null
|
||||
@@ -765,6 +799,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
if (!Set.of("CONFIG_MAP", "API_AND_CONFIG_MAP", "API").contains(authenticationMode)) {
|
||||
throw new AwsException("InvalidParameterException", "Invalid authenticationMode", 400);
|
||||
}
|
||||
validateAutoMode(request.getComputeConfig(), request.getStorageConfig(), request.getKubernetesNetworkConfig());
|
||||
AccessConfig accessConfig = new AccessConfig(authenticationMode,
|
||||
requestedAccess == null || requestedAccess.bootstrapClusterCreatorAdminPermissions() == null
|
||||
|| requestedAccess.bootstrapClusterCreatorAdminPermissions());
|
||||
@@ -776,6 +811,8 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName(name);
|
||||
cluster.setAccessConfig(accessConfig);
|
||||
cluster.setComputeConfig(request.getComputeConfig());
|
||||
cluster.setStorageConfig(request.getStorageConfig());
|
||||
cluster.setArn(arn);
|
||||
cluster.setAccountId(accountId);
|
||||
cluster.setCreatedAt(Instant.now());
|
||||
@@ -1817,6 +1854,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
}
|
||||
config.setServiceIpv4Cidr(resolvedCidr);
|
||||
config.setIpFamily(resolveIpFamily(request));
|
||||
config.setElasticLoadBalancing(request != null ? request.getElasticLoadBalancing() : null);
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.floci.aws.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/** EKS Auto Mode's block storage capability: whether it provisions EBS volumes for the cluster. */
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record BlockStorage(Boolean enabled) {}
|
||||
@@ -152,9 +152,21 @@ public class Cluster {
|
||||
|
||||
private AccessConfig accessConfig;
|
||||
|
||||
@JsonProperty("computeConfig")
|
||||
private ComputeConfig computeConfig;
|
||||
|
||||
@JsonProperty("storageConfig")
|
||||
private StorageConfig storageConfig;
|
||||
|
||||
public AccessConfig getAccessConfig() { return accessConfig; }
|
||||
public void setAccessConfig(AccessConfig accessConfig) { this.accessConfig = accessConfig; }
|
||||
|
||||
public ComputeConfig getComputeConfig() { return computeConfig; }
|
||||
public void setComputeConfig(ComputeConfig computeConfig) { this.computeConfig = computeConfig; }
|
||||
|
||||
public StorageConfig getStorageConfig() { return storageConfig; }
|
||||
public void setStorageConfig(StorageConfig storageConfig) { this.storageConfig = storageConfig; }
|
||||
|
||||
public Map<String, String> getJoinedInstanceIds() {
|
||||
if (joinedInstanceIds != null && !(joinedInstanceIds instanceof ConcurrentHashMap)) {
|
||||
joinedInstanceIds = new ConcurrentHashMap<>(joinedInstanceIds);
|
||||
@@ -291,6 +303,8 @@ public class Cluster {
|
||||
c.defaultStorageClass = this.defaultStorageClass;
|
||||
c.joinedInstanceIds = this.joinedInstanceIds != null ? new ConcurrentHashMap<>(this.joinedInstanceIds) : null;
|
||||
c.accessConfig = this.accessConfig;
|
||||
c.computeConfig = this.computeConfig;
|
||||
c.storageConfig = this.storageConfig;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.floci.aws.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EKS Auto Mode's compute capability: whether it is on, the built-in node pools it runs and the IAM role their nodes
|
||||
* take.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ComputeConfig(Boolean enabled, List<String> nodePools, String nodeRoleArn) {}
|
||||
@@ -40,9 +40,21 @@ public class CreateClusterRequest {
|
||||
|
||||
private AccessConfig accessConfig;
|
||||
|
||||
@JsonProperty("computeConfig")
|
||||
private ComputeConfig computeConfig;
|
||||
|
||||
@JsonProperty("storageConfig")
|
||||
private StorageConfig storageConfig;
|
||||
|
||||
public AccessConfig getAccessConfig() { return accessConfig; }
|
||||
public void setAccessConfig(AccessConfig accessConfig) { this.accessConfig = accessConfig; }
|
||||
|
||||
public ComputeConfig getComputeConfig() { return computeConfig; }
|
||||
public void setComputeConfig(ComputeConfig computeConfig) { this.computeConfig = computeConfig; }
|
||||
|
||||
public StorageConfig getStorageConfig() { return storageConfig; }
|
||||
public void setStorageConfig(StorageConfig storageConfig) { this.storageConfig = storageConfig; }
|
||||
|
||||
public CreateClusterRequest() {}
|
||||
|
||||
public String getName() { return name; }
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.floci.aws.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/** EKS Auto Mode's load balancing capability: whether it creates load balancers for the cluster. */
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ElasticLoadBalancing(Boolean enabled) {}
|
||||
@@ -14,8 +14,16 @@ public class KubernetesNetworkConfig {
|
||||
@JsonProperty("ipFamily")
|
||||
private String ipFamily;
|
||||
|
||||
@JsonProperty("elasticLoadBalancing")
|
||||
private ElasticLoadBalancing elasticLoadBalancing;
|
||||
|
||||
public KubernetesNetworkConfig() {}
|
||||
|
||||
public ElasticLoadBalancing getElasticLoadBalancing() { return elasticLoadBalancing; }
|
||||
public void setElasticLoadBalancing(ElasticLoadBalancing elasticLoadBalancing) {
|
||||
this.elasticLoadBalancing = elasticLoadBalancing;
|
||||
}
|
||||
|
||||
public String getServiceIpv4Cidr() { return serviceIpv4Cidr; }
|
||||
public void setServiceIpv4Cidr(String serviceIpv4Cidr) { this.serviceIpv4Cidr = serviceIpv4Cidr; }
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.floci.aws.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/** EKS Auto Mode's storage capabilities. */
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record StorageConfig(BlockStorage blockStorage) {}
|
||||
Reference in new issue
Block a user