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
+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