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
@@ -350,6 +350,46 @@ EKS clusters support configuring KMS envelope encryption for secrets and control
|
||||
- **Component streams deviation**: AWS EKS provisions separate log streams for each component (`kube-apiserver-*`, `kube-apiserver-audit-*`, `kube-controller-manager-*`, `kube-scheduler-*`, `authenticator-*`). Because Floci runs clusters on k3s, which embeds the Kubernetes API server, controller manager, and scheduler within a single process, control plane container logs are delivered to the single `kube-apiserver-<hash>` stream when `api` is enabled, and API server audit logs are delivered to `kube-apiserver-audit-<hash>` when `audit` is enabled. Other control plane log types (`authenticator`, `controllerManager`, `scheduler`) do not provision separate streams.
|
||||
- **Authenticator logs**: Authenticator webhook authentication events are logged directly by Floci.
|
||||
|
||||
## EKS Auto Mode configuration
|
||||
|
||||
`CreateCluster` accepts EKS Auto Mode's configuration, and `CreateCluster` and `DescribeCluster` return it as it
|
||||
was given: `computeConfig` (`enabled`, `nodePools` and `nodeRoleArn`), `storageConfig.blockStorage.enabled` and
|
||||
`kubernetesNetworkConfig.elasticLoadBalancing.enabled`.
|
||||
|
||||
```json
|
||||
{
|
||||
"computeConfig": {
|
||||
"enabled": true,
|
||||
"nodePools": ["general-purpose", "system"],
|
||||
"nodeRoleArn": "arn:aws:iam::000000000000:role/AmazonEKSAutoNodeRole"
|
||||
},
|
||||
"storageConfig": {"blockStorage": {"enabled": true}},
|
||||
"kubernetesNetworkConfig": {"elasticLoadBalancing": {"enabled": true}}
|
||||
}
|
||||
```
|
||||
|
||||
As on AWS, the compute, block storage and load balancing capabilities are enabled together or not at all. A
|
||||
request that enables some of them and not the others is refused with `InvalidParameterException` ("For EKS Auto
|
||||
Mode, please ensure that all required configs, including computeConfig, kubernetesNetworkConfig, and
|
||||
blockStorage are all either fully enabled or fully disabled."), and a capability the request leaves out counts
|
||||
as not enabled. A `computeConfig` that names node pools without a `nodeRoleArn` is refused with
|
||||
`InvalidParameterException` ("When Compute Config nodeRoleArn is null or empty, nodePool list cannot be
|
||||
populated"), and one that names a `nodeRoleArn` without node pools with `InvalidParameterException` ("When
|
||||
Compute Config nodeRoleArn is not null or empty, nodePool value(s) must be provided."). A `computeConfig` with
|
||||
neither is accepted, as AWS accepts it for Auto Mode without its built-in node pools.
|
||||
|
||||
In CloudFormation, `AWS::EKS::Cluster` leaves EKS Auto Mode out for now: it accepts `ComputeConfig`,
|
||||
`StorageConfig` and `KubernetesNetworkConfig.ElasticLoadBalancing` and ignores them, so a template that enables
|
||||
Auto Mode creates its cluster without it.
|
||||
|
||||
With IAM enforcement on, `CreateCluster` checks `iam:PassRole` on the cluster role, passed to
|
||||
`eks.amazonaws.com`, and not yet on the node role. AWS's Service Reference lists both `ec2.amazonaws.com` and
|
||||
`eks.amazonaws.com` for the roles `CreateCluster` passes, and does not say which one the node role goes to.
|
||||
|
||||
Floci records the configuration and does nothing more with it yet. It does not create the node role's access
|
||||
entry, install the built-in node pools, serve the EBS provisioner or create load balancers, and
|
||||
`UpdateClusterConfig` is not implemented. [#8914](https://github.com/floci-io/floci/issues/8914) plans each.
|
||||
|
||||
## Node group inputs
|
||||
|
||||
`CreateNodegroup` accepts the full documented input set and stores every member, so `CreateNodegroup` and `DescribeNodegroup` both return exactly what was supplied.
|
||||
|
||||
+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) {}
|
||||
+28
@@ -248,6 +248,34 @@ class CloudFormationEksIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
/** EKS Auto Mode stays out of AWS::EKS::Cluster for now, so a template enabling it still creates its cluster. */
|
||||
@Test
|
||||
void aClusterEnablingAutoModeIsCreatedWithoutIt() {
|
||||
String stack = "cfn-eks-auto-" + Long.toString(System.nanoTime(), 36);
|
||||
String autoMode = "\"ComputeConfig\": {\"Enabled\": true, \"NodePools\": [\"general-purpose\", \"system\"],"
|
||||
+ " \"NodeRoleArn\": \"arn:aws:iam::000000000000:role/eks-auto-node\"},"
|
||||
+ " \"StorageConfig\": {\"BlockStorage\": {\"Enabled\": true}},"
|
||||
+ " \"KubernetesNetworkConfig\": {\"ElasticLoadBalancing\": {\"Enabled\": true}}";
|
||||
// The Gateway API settings, which Floci doesn't model, don't fail the conversion either.
|
||||
String gatewayApi = "\"KubernetesNetworkConfig\": {\"ElasticLoadBalancing\": {\"Enabled\": false,"
|
||||
+ " \"GatewayApi\": {\"Crds\": {\"Managed\": true}}}}";
|
||||
String template = "{\"Resources\": {"
|
||||
+ "\"Subject\": {\"Type\": \"AWS::EKS::Cluster\", \"Properties\": {" + ROLE + autoMode + "}},"
|
||||
+ "\"Gateway\": {\"Type\": \"AWS::EKS::Cluster\", \"Properties\": {" + ROLE + gatewayApi + "}}}}";
|
||||
try (CloudFormationClient client = AwsTestClients.create(
|
||||
CloudFormationClient.builder(), "test", Region.US_EAST_1)) {
|
||||
CfnStackWaits.createStack(client, stack, template, "CREATE_COMPLETE");
|
||||
for (String resource : List.of("Subject", "Gateway")) {
|
||||
JsonPath cluster = given().get("/clusters/" + physicalId(client, stack, resource)).jsonPath();
|
||||
assertNull(cluster.get("cluster.computeConfig"), resource);
|
||||
assertNull(cluster.get("cluster.storageConfig"), resource);
|
||||
assertNull(cluster.get("cluster.kubernetesNetworkConfig.elasticLoadBalancing"), resource);
|
||||
}
|
||||
} finally {
|
||||
CfnStackWaits.deleteStack(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void changingTheServiceCidrReplacesTheClusterWithTheNewOne() {
|
||||
String stack = "cfn-eks-cidr-" + Long.toString(System.nanoTime(), 36);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package io.floci.aws.services.eks;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.floci.aws.testing.EksRequests.eks;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class EksAutoModeIntegrationTest {
|
||||
|
||||
private static final String ACCOUNT = "864208642086";
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String NODE_ROLE = "arn:aws:iam::" + ACCOUNT + ":role/eks-auto-node";
|
||||
|
||||
@Test
|
||||
void anAutoModeClusterCreatesAndDescribesItsConfiguration() {
|
||||
String name = "auto-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
try {
|
||||
assertAutoModeEnabled(eks(ACCOUNT, REGION).body(cluster(name, true, true, true)).post("/clusters").then());
|
||||
assertAutoModeEnabled(eks(ACCOUNT, REGION).get("/clusters/" + name).then());
|
||||
} finally {
|
||||
eks(ACCOUNT, REGION).delete("/clusters/" + name).then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void anAutoModeClusterWithoutLoadBalancingIsRefusedAndNotCreated() {
|
||||
String name = "auto-partial-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
|
||||
eks(ACCOUNT, REGION).body(cluster(name, true, true, false)).post("/clusters").then().statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("message", equalTo("For EKS Auto Mode, please ensure that all required configs, including "
|
||||
+ "computeConfig, kubernetesNetworkConfig, and blockStorage are all either fully enabled "
|
||||
+ "or fully disabled."));
|
||||
eks(ACCOUNT, REGION).get("/clusters/" + name).then().statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
private static void assertAutoModeEnabled(ValidatableResponse response) {
|
||||
response.statusCode(200)
|
||||
.body("cluster.computeConfig.enabled", equalTo(true))
|
||||
.body("cluster.computeConfig.nodePools", contains("general-purpose", "system"))
|
||||
.body("cluster.computeConfig.nodeRoleArn", equalTo(NODE_ROLE))
|
||||
.body("cluster.storageConfig.blockStorage.enabled", equalTo(true))
|
||||
.body("cluster.kubernetesNetworkConfig.elasticLoadBalancing.enabled", equalTo(true));
|
||||
}
|
||||
|
||||
private static String cluster(String name, boolean compute, boolean blockStorage, boolean loadBalancing) {
|
||||
return """
|
||||
{"name":"%s","roleArn":"arn:aws:iam::%s:role/eks-auto-cluster",
|
||||
"computeConfig":{"enabled":%b,"nodePools":["general-purpose","system"],"nodeRoleArn":"%s"},
|
||||
"storageConfig":{"blockStorage":{"enabled":%b}},
|
||||
"kubernetesNetworkConfig":{"elasticLoadBalancing":{"enabled":%b}}}"""
|
||||
.formatted(name, ACCOUNT, compute, NODE_ROLE, blockStorage, loadBalancing);
|
||||
}
|
||||
}
|
||||
@@ -26,13 +26,16 @@ import io.floci.aws.services.ec2.model.SecurityGroup;
|
||||
import io.floci.aws.services.ec2.model.Tag;
|
||||
import io.floci.aws.services.ec2.model.Vpc;
|
||||
import io.floci.aws.services.ec2.portforward.Ec2PortForwardManager;
|
||||
import io.floci.aws.services.eks.model.BlockStorage;
|
||||
import io.floci.aws.services.eks.model.Cluster;
|
||||
import io.floci.aws.services.eks.model.ClusterIdentity;
|
||||
import io.floci.aws.services.eks.model.ClusterOidcKey;
|
||||
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;
|
||||
import io.floci.aws.services.eks.model.ElasticLoadBalancing;
|
||||
import io.floci.aws.services.eks.model.EncryptionConfig;
|
||||
import io.floci.aws.services.eks.model.FargateProfile;
|
||||
import io.floci.aws.services.eks.model.FargateProfileStatus;
|
||||
@@ -45,6 +48,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 io.floci.aws.testing.ThreadStates;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -2247,6 +2251,84 @@ class EksServiceTest {
|
||||
return req;
|
||||
}
|
||||
|
||||
private static final String AUTO_MODE_NODE_ROLE = "arn:aws:iam::000000000000:role/eks-auto-node";
|
||||
private static final String AUTO_MODE_PARTIAL = "For EKS Auto Mode, please ensure that all required configs, "
|
||||
+ "including computeConfig, kubernetesNetworkConfig, and blockStorage are all either fully enabled or "
|
||||
+ "fully disabled.";
|
||||
|
||||
/** A cluster request with EKS Auto Mode's three capabilities; a null one is left out of the request. */
|
||||
private CreateClusterRequest autoModeRequest(String name, ComputeConfig compute, Boolean blockStorage,
|
||||
Boolean loadBalancing) {
|
||||
CreateClusterRequest req = createTestClusterRequest(name);
|
||||
req.setComputeConfig(compute);
|
||||
if (blockStorage != null) {
|
||||
req.setStorageConfig(new StorageConfig(new BlockStorage(blockStorage)));
|
||||
}
|
||||
if (loadBalancing != null) {
|
||||
KubernetesNetworkConfig network = new KubernetesNetworkConfig();
|
||||
network.setElasticLoadBalancing(new ElasticLoadBalancing(loadBalancing));
|
||||
req.setKubernetesNetworkConfig(network);
|
||||
}
|
||||
return req;
|
||||
}
|
||||
|
||||
private void assertCreateClusterRefused(CreateClusterRequest req, String message) {
|
||||
AwsException refused = assertThrows(AwsException.class, () -> eksService.createCluster(req));
|
||||
assertEquals("InvalidParameterException", refused.getErrorCode());
|
||||
assertEquals(message, refused.getMessage());
|
||||
assertEquals("ResourceNotFoundException",
|
||||
assertThrows(AwsException.class, () -> eksService.describeCluster(req.getName())).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClusterCreatedWithAutoModeDescribesItsComputeStorageAndLoadBalancing() {
|
||||
ComputeConfig compute = new ComputeConfig(true, List.of("general-purpose", "system"), AUTO_MODE_NODE_ROLE);
|
||||
|
||||
eksService.createCluster(autoModeRequest("auto-mode-cluster", compute, true, true));
|
||||
Cluster described = eksService.describeCluster("auto-mode-cluster");
|
||||
|
||||
assertEquals(compute, described.getComputeConfig());
|
||||
assertEquals(new StorageConfig(new BlockStorage(true)), described.getStorageConfig());
|
||||
assertEquals(new ElasticLoadBalancing(true), described.getKubernetesNetworkConfig().getElasticLoadBalancing());
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoModeIsRefusedUnlessComputeBlockStorageAndLoadBalancingAreEnabledTogether() {
|
||||
ComputeConfig on = new ComputeConfig(true, List.of("general-purpose"), AUTO_MODE_NODE_ROLE);
|
||||
ComputeConfig off = new ComputeConfig(false, null, null);
|
||||
assertCreateClusterRefused(autoModeRequest("auto-compute", on, false, false), AUTO_MODE_PARTIAL);
|
||||
assertCreateClusterRefused(autoModeRequest("auto-storage", off, true, false), AUTO_MODE_PARTIAL);
|
||||
assertCreateClusterRefused(autoModeRequest("auto-load-balancing", off, false, true), AUTO_MODE_PARTIAL);
|
||||
assertCreateClusterRefused(autoModeRequest("auto-no-load-balancing", on, true, false), AUTO_MODE_PARTIAL);
|
||||
// A capability the request leaves out is not enabled.
|
||||
assertCreateClusterRefused(autoModeRequest("auto-compute-alone", on, null, null), AUTO_MODE_PARTIAL);
|
||||
assertCreateClusterRefused(autoModeRequest("auto-storage-alone", null, true, null), AUTO_MODE_PARTIAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoModeNodePoolsAreRefusedWithoutANodeRole() {
|
||||
String message = "When Compute Config nodeRoleArn is null or empty, nodePool list cannot be populated";
|
||||
assertCreateClusterRefused(autoModeRequest("auto-null-node-role",
|
||||
new ComputeConfig(true, List.of("general-purpose", "system"), null), true, true), message);
|
||||
assertCreateClusterRefused(autoModeRequest("auto-empty-node-role",
|
||||
new ComputeConfig(true, List.of("general-purpose", "system"), ""), true, true), message);
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoModeNodeRoleIsRefusedWithoutNodePools() {
|
||||
String message = "When Compute Config nodeRoleArn is not null or empty, nodePool value(s) must be provided.";
|
||||
assertCreateClusterRefused(autoModeRequest("auto-null-node-pools",
|
||||
new ComputeConfig(true, null, AUTO_MODE_NODE_ROLE), true, true), message);
|
||||
assertCreateClusterRefused(autoModeRequest("auto-empty-node-pools",
|
||||
new ComputeConfig(true, List.of(), AUTO_MODE_NODE_ROLE), true, true), message);
|
||||
|
||||
// Without built-in node pools, Auto Mode takes no node role either.
|
||||
eksService.createCluster(autoModeRequest("auto-without-node-pools", new ComputeConfig(true, List.of(), null),
|
||||
true, true));
|
||||
assertEquals(new ComputeConfig(true, List.of(), null),
|
||||
eksService.describeCluster("auto-without-node-pools").getComputeConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createClusterWithEncryptionConfigAndLogging() {
|
||||
CreateClusterRequest req = createTestClusterRequest("enc-log-cluster");
|
||||
|
||||
Reference in new issue
Block a user