From 16c2505a25eadc839edbfc7e90f4240c1db02ba5 Mon Sep 17 00:00:00 2001 From: mrfelek <17274927+mrfelek@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:06:24 +0100 Subject: [PATCH] feat(eks): turn EKS Auto Mode on and off with UpdateClusterConfig (#9264) UpdateClusterConfig accepts computeConfig, storageConfig and kubernetesNetworkConfig.elasticLoadBalancing together as one AutoModeUpdate family. The cluster stores the result for DescribeCluster, and the update is recorded for DescribeUpdate and clientRequestToken replay. A member the request omits keeps its stored value, and the request is checked against the configuration it leaves: the three capabilities on or off together, node pools named with a node role, the node role unchanged while compute stays on, and a request that changes nothing refused with "No changes needed for EKS Auto Mode configuration provided". An omitted node role keeps the stored one, so {"enabled": true, "nodePools": []} turns off the built-in node pools as in the AWS user guide. Other kubernetesNetworkConfig and elasticLoadBalancing members, gatewayApi among them, are refused as unsupported. A null node pool is refused on CreateCluster and UpdateClusterConfig instead of failing with a server error. Part of #8914. --- .../floci/aws/services/eks/EksController.java | 25 ++- .../io/floci/aws/services/eks/EksService.java | 125 ++++++++++- .../eks/model/UpdateClusterConfigRequest.java | 22 +- .../eks/EksAutoModeIntegrationTest.java | 196 ++++++++++++++++++ 4 files changed, 356 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/floci/aws/services/eks/EksController.java b/src/main/java/io/floci/aws/services/eks/EksController.java index 4bdca6e935..a7a3d8ffe6 100644 --- a/src/main/java/io/floci/aws/services/eks/EksController.java +++ b/src/main/java/io/floci/aws/services/eks/EksController.java @@ -63,8 +63,10 @@ public class EksController { private static final List UPDATE_CONFIG_FAMILIES = List.of("resourcesVpcConfig", "logging", "accessConfig", "upgradePolicy"); - private static final Set UPDATE_CONFIG_MEMBERS = - Set.of("name", "clientRequestToken", "resourcesVpcConfig", "logging", "accessConfig", "upgradePolicy"); + /** The members that together make one EKS Auto Mode update. */ + private static final List AUTO_MODE_MEMBERS = List.of("computeConfig", "storageConfig", "kubernetesNetworkConfig"); + private static final Set UPDATE_CONFIG_MEMBERS = Set.of("name", "clientRequestToken", "resourcesVpcConfig", + "logging", "accessConfig", "upgradePolicy", "computeConfig", "storageConfig", "kubernetesNetworkConfig"); private final EksService eksService; private final EksAccessEntryService accessEntries; @@ -367,7 +369,24 @@ public class EksController { "Floci does not support updating " + member + " through UpdateClusterConfig yet", 400); } } - if (UPDATE_CONFIG_FAMILIES.stream().filter(body::has).count() > 1) { + JsonNode network = body.path("kubernetesNetworkConfig"); + for (String member : (Iterable) network::fieldNames) { + if (!"elasticLoadBalancing".equals(member)) { + throw new AwsException("InvalidParameterException", + "Floci does not support updating kubernetesNetworkConfig." + member + + " through UpdateClusterConfig yet", 400); + } + } + for (String member : (Iterable) network.path("elasticLoadBalancing")::fieldNames) { + if (!"enabled".equals(member)) { + throw new AwsException("InvalidParameterException", + "Floci does not support updating kubernetesNetworkConfig.elasticLoadBalancing." + member + + " through UpdateClusterConfig yet", 400); + } + } + long families = UPDATE_CONFIG_FAMILIES.stream().filter(body::has).count() + + (AUTO_MODE_MEMBERS.stream().anyMatch(body::has) ? 1 : 0); + if (families > 1) { throw new AwsException("InvalidParameterException", "Only one type of update can be allowed.", 400); } try { diff --git a/src/main/java/io/floci/aws/services/eks/EksService.java b/src/main/java/io/floci/aws/services/eks/EksService.java index 6cada25a25..e70339b6c6 100644 --- a/src/main/java/io/floci/aws/services/eks/EksService.java +++ b/src/main/java/io/floci/aws/services/eks/EksService.java @@ -41,6 +41,7 @@ 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; @@ -776,19 +777,32 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun */ private static void validateAutoMode(ComputeConfig compute, StorageConfig storage, KubernetesNetworkConfig network) { + requireCapabilitiesTogether(compute, storage, elasticLoadBalancing(network)); + requireNodePoolsWithRole(compute); + } + + /** The compute, block storage and load balancing capabilities are on together or off together. */ + private static void requireCapabilitiesTogether(ComputeConfig compute, StorageConfig storage, + ElasticLoadBalancing loadBalancing) { 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()); + boolean loadBalancingEnabled = loadBalancing != null && Boolean.TRUE.equals(loadBalancing.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); } + } + + /** Node pools launch their nodes with the node role, so a compute configuration naming pools names it. */ + private static void requireNodePoolsWithRole(ComputeConfig compute) { if (compute == null) { return; } + if (compute.nodePools() != null && compute.nodePools().stream().anyMatch(Objects::isNull)) { + throw new AwsException("InvalidParameterException", "nodePools must not contain null", 400); + } boolean hasNodePools = compute.nodePools() != null && !compute.nodePools().isEmpty(); boolean hasNodeRole = compute.nodeRoleArn() != null && !compute.nodeRoleArn().isEmpty(); if (hasNodePools && !hasNodeRole) { @@ -1065,9 +1079,9 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun Cluster cluster = requireClusterInRequestRegion(name); EksAddonService.requireActiveCluster(cluster); if (request == null || (request.resourcesVpcConfig() == null && request.logging() == null - && request.accessConfig() == null && request.upgradePolicy() == null)) { - throw new AwsException("InvalidParameterException", - "UpdateClusterConfig supports resourcesVpcConfig, logging, accessConfig and upgradePolicy only", 400); + && request.accessConfig() == null && request.upgradePolicy() == null && !request.changesAutoMode())) { + throw new AwsException("InvalidParameterException", "UpdateClusterConfig supports resourcesVpcConfig, " + + "logging, accessConfig, upgradePolicy and the EKS Auto Mode configuration only", 400); } String token = request.clientRequestToken(); if (token != null && !token.isBlank()) { @@ -1123,6 +1137,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun + "\" is not in standard support. Please update the cluster to a version in standard support to " + "change the supportType", 400); } + AutoMode nextAutoMode = request.changesAutoMode() ? requireAutoModeChange(cluster, request) : null; Boolean finalPublicAccess = publicAccess; Boolean finalPrivateAccess = privateAccess; @@ -1165,13 +1180,18 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun List.of(new UpdateParam("UpgradePolicy", json(policy))), null, updates.isEmpty() ? request : null)); } + if (nextAutoMode != null) { + updates.add(addons.recordUpdate(current, "AutoModeUpdate", applyAutoMode(current, nextAutoMode, request), null, + updates.isEmpty() ? request : null)); + } }); if (!saved[0]) { throw new AwsException("ResourceNotFoundException", "No cluster found for name: " + name, 404); } if (updates.isEmpty()) { throw new AwsException("InvalidParameterException", "UpdateClusterConfig supports resourcesVpcConfig, " - + "logging, accessConfig.authenticationMode and upgradePolicy.supportType only", 400); + + "logging, accessConfig.authenticationMode, upgradePolicy.supportType and the EKS Auto Mode " + + "configuration only", 400); } LOG.infov("Updated the configuration of EKS cluster {0}: {1}", cluster.getName(), updates.stream().map(Update::type).toList()); @@ -1192,7 +1212,98 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun && Objects.equals(a.getPublicAccessCidrs(), b.getPublicAccessCidrs()); return sameVpc && Objects.equals(existing.logging(), request.logging()) && Objects.equals(existing.accessConfig(), request.accessConfig()) - && Objects.equals(existing.upgradePolicy(), request.upgradePolicy()); + && Objects.equals(existing.upgradePolicy(), request.upgradePolicy()) + && Objects.equals(existing.computeConfig(), request.computeConfig()) + && Objects.equals(existing.storageConfig(), request.storageConfig()) + && Objects.equals(elasticLoadBalancing(existing.kubernetesNetworkConfig()), + elasticLoadBalancing(request.kubernetesNetworkConfig())); + } + + private static ElasticLoadBalancing elasticLoadBalancing(KubernetesNetworkConfig network) { + return network == null ? null : network.getElasticLoadBalancing(); + } + + /** The cluster's EKS Auto Mode configuration: its compute, block storage and load balancing capabilities. */ + private record AutoMode(ComputeConfig compute, StorageConfig storage, ElasticLoadBalancing loadBalancing) { + + boolean computeOn() { + return compute != null && Boolean.TRUE.equals(compute.enabled()); + } + + /** What it turns on, for telling whether a request changes it: off, or on with its pools and role. */ + List state() { + if (!computeOn()) { + return List.of(false); + } + return List.of(true, compute.nodePools() == null ? Set.of() : Set.copyOf(compute.nodePools()), + String.valueOf(compute.nodeRoleArn()), + storage != null && storage.blockStorage() != null + && Boolean.TRUE.equals(storage.blockStorage().enabled()), + loadBalancing != null && Boolean.TRUE.equals(loadBalancing.enabled())); + } + } + + private static AutoMode autoMode(Cluster cluster) { + return new AutoMode(cluster.getComputeConfig(), cluster.getStorageConfig(), + elasticLoadBalancing(cluster.getKubernetesNetworkConfig())); + } + + /** + * The cluster's EKS Auto Mode configuration once {@code request} applies, refusing the changes AWS refuses. A + * member the request omits keeps its stored value, so the three capabilities are checked together as they will + * be stored. Node pools and the node role are checked as the request names them, as {@code CreateCluster} + * checks them: AWS's own example turns off the built-in pools with {@code "nodePools": []} and no role. The + * node role can't change while the compute capability is on (botocore's ComputeConfigRequest: "This value + * cannot be changed after the compute capability of EKS Auto Mode is enabled"), so a request that omits it + * keeps it. A request that changes nothing is refused with the error EKS answers it. + */ + private static AutoMode requireAutoModeChange(Cluster cluster, UpdateClusterConfigRequest request) { + AutoMode current = autoMode(cluster); + ComputeConfig requested = request.computeConfig(); + ComputeConfig compute = current.compute(); + if (requested != null) { + requireNodePoolsWithRole(requested); + boolean staysOn = current.computeOn() && Boolean.TRUE.equals(requested.enabled()); + String role = requested.nodeRoleArn(); + if (staysOn && role != null && !role.isEmpty() && !role.equals(current.compute().nodeRoleArn())) { + throw new AwsException("InvalidParameterException", + "nodeRoleArn cannot be changed after the compute capability of EKS Auto Mode is enabled", 400); + } + compute = staysOn && (role == null || role.isEmpty()) + ? new ComputeConfig(requested.enabled(), requested.nodePools(), current.compute().nodeRoleArn()) + : requested; + } + ElasticLoadBalancing requestedLoadBalancing = elasticLoadBalancing(request.kubernetesNetworkConfig()); + AutoMode next = new AutoMode(compute, + request.storageConfig() != null ? request.storageConfig() : current.storage(), + requestedLoadBalancing != null ? requestedLoadBalancing : current.loadBalancing()); + requireCapabilitiesTogether(next.compute(), next.storage(), next.loadBalancing()); + if (current.state().equals(next.state())) { + throw new AwsException("InvalidRequestException", + "No changes needed for EKS Auto Mode configuration provided", 400); + } + return next; + } + + /** Stores {@code next}, and returns the Auto Mode members the request names as the update's parameters. */ + private static List applyAutoMode(Cluster cluster, AutoMode next, UpdateClusterConfigRequest request) { + cluster.setComputeConfig(next.compute()); + cluster.setStorageConfig(next.storage()); + if (cluster.getKubernetesNetworkConfig() != null) { + cluster.getKubernetesNetworkConfig().setElasticLoadBalancing(next.loadBalancing()); + } + List params = new ArrayList<>(); + if (request.computeConfig() != null) { + params.add(new UpdateParam("ComputeConfig", json(request.computeConfig()))); + } + if (request.storageConfig() != null) { + params.add(new UpdateParam("StorageConfig", json(request.storageConfig()))); + } + ElasticLoadBalancing loadBalancing = elasticLoadBalancing(request.kubernetesNetworkConfig()); + if (loadBalancing != null) { + params.add(new UpdateParam("KubernetesNetworkConfig", json(Map.of("elasticLoadBalancing", loadBalancing)))); + } + return params; } /** The cluster's current settings with the request applied on top, in the shape createCluster validates. */ diff --git a/src/main/java/io/floci/aws/services/eks/model/UpdateClusterConfigRequest.java b/src/main/java/io/floci/aws/services/eks/model/UpdateClusterConfigRequest.java index 59836de274..da4e156d61 100644 --- a/src/main/java/io/floci/aws/services/eks/model/UpdateClusterConfigRequest.java +++ b/src/main/java/io/floci/aws/services/eks/model/UpdateClusterConfigRequest.java @@ -5,6 +5,8 @@ import io.quarkus.runtime.annotations.RegisterForReflection; /** * The members of UpdateClusterConfig that floci applies. The REST controller refuses any other member. + * {@code computeConfig}, {@code storageConfig} and {@code kubernetesNetworkConfig} turn EKS Auto Mode on or off + * together, and of {@code kubernetesNetworkConfig} only {@code elasticLoadBalancing} is applied. */ @RegisterForReflection @JsonIgnoreProperties(ignoreUnknown = true) @@ -13,5 +15,21 @@ public record UpdateClusterConfigRequest( Logging logging, AccessConfig accessConfig, UpgradePolicy upgradePolicy, - String clientRequestToken -) {} + String clientRequestToken, + ComputeConfig computeConfig, + StorageConfig storageConfig, + KubernetesNetworkConfig kubernetesNetworkConfig +) { + + /** As above, with no EKS Auto Mode change. */ + public UpdateClusterConfigRequest(ResourcesVpcConfig resourcesVpcConfig, Logging logging, + AccessConfig accessConfig, UpgradePolicy upgradePolicy, + String clientRequestToken) { + this(resourcesVpcConfig, logging, accessConfig, upgradePolicy, clientRequestToken, null, null, null); + } + + /** Whether the request names any of the EKS Auto Mode members. */ + public boolean changesAutoMode() { + return computeConfig != null || storageConfig != null || kubernetesNetworkConfig != null; + } +} diff --git a/src/test/java/io/floci/aws/services/eks/EksAutoModeIntegrationTest.java b/src/test/java/io/floci/aws/services/eks/EksAutoModeIntegrationTest.java index 7399134b6d..365c964ef2 100644 --- a/src/test/java/io/floci/aws/services/eks/EksAutoModeIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/eks/EksAutoModeIntegrationTest.java @@ -3,11 +3,15 @@ package io.floci.aws.services.eks; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.ValidatableResponse; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import java.util.UUID; import static io.floci.aws.testing.EksRequests.eks; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; @QuarkusTest @@ -41,6 +45,198 @@ class EksAutoModeIntegrationTest { .body("__type", equalTo("ResourceNotFoundException")); } + @Test + void updateClusterConfigTurnsAutoModeOnForAnExistingClusterAsAnUpdateDescribeUpdateFinds() { + String name = "auto-on-" + UUID.randomUUID().toString().substring(0, 8); + eks(ACCOUNT, REGION).body(""" + {"name":"%s","roleArn":"arn:aws:iam::%s:role/eks-auto-cluster"}""".formatted(name, ACCOUNT)) + .post("/clusters").then().statusCode(200); + try { + String id = eks(ACCOUNT, REGION).body(autoMode(true, true, true, NODE_ROLE)) + .post("/clusters/" + name + "/update-config").then().statusCode(200) + .body("update.type", equalTo("AutoModeUpdate")) + .body("update.params.type", containsInAnyOrder("ComputeConfig", "StorageConfig", + "KubernetesNetworkConfig")) + .extract().path("update.id"); + eks(ACCOUNT, REGION).get("/clusters/" + name + "/updates/" + id).then().statusCode(200) + .body("update.type", equalTo("AutoModeUpdate")); + assertAutoModeEnabled(eks(ACCOUNT, REGION).get("/clusters/" + name).then()); + } finally { + eks(ACCOUNT, REGION).delete("/clusters/" + name).then().statusCode(200); + } + } + + @Test + void updateClusterConfigTurnsAutoModeOffAndChangesTheNodePools() { + String name = "auto-off-" + UUID.randomUUID().toString().substring(0, 8); + eks(ACCOUNT, REGION).body(cluster(name, true, true, true)).post("/clusters").then().statusCode(200); + try { + eks(ACCOUNT, REGION).body(""" + {"computeConfig":{"enabled":true,"nodePools":["general-purpose"],"nodeRoleArn":"%s"}, + "storageConfig":{"blockStorage":{"enabled":true}}, + "kubernetesNetworkConfig":{"elasticLoadBalancing":{"enabled":true}}}""".formatted(NODE_ROLE)) + .post("/clusters/" + name + "/update-config").then().statusCode(200); + eks(ACCOUNT, REGION).get("/clusters/" + name).then().statusCode(200) + .body("cluster.computeConfig.nodePools", contains("general-purpose")); + + eks(ACCOUNT, REGION).body(autoMode(false, false, false, null)) + .post("/clusters/" + name + "/update-config").then().statusCode(200) + .body("update.type", equalTo("AutoModeUpdate")); + eks(ACCOUNT, REGION).get("/clusters/" + name).then().statusCode(200) + .body("cluster.computeConfig.enabled", equalTo(false)) + .body("cluster.storageConfig.blockStorage.enabled", equalTo(false)) + .body("cluster.kubernetesNetworkConfig.elasticLoadBalancing.enabled", equalTo(false)); + } finally { + eks(ACCOUNT, REGION).delete("/clusters/" + name).then().statusCode(200); + } + } + + @ParameterizedTest + @CsvSource(delimiter = '|', value = { + // the capabilities enabled apart + "true|true|false|eks-auto-node|InvalidParameterException|For EKS Auto Mode, please ensure that all " + + "required configs, including computeConfig, kubernetesNetworkConfig, and blockStorage are all " + + "either fully enabled or fully disabled.", + // a different node role while the compute capability is on + "true|true|true|other-node|InvalidParameterException|nodeRoleArn cannot be changed after the compute " + + "capability of EKS Auto Mode is enabled", + // the configuration the cluster already has + "true|true|true|eks-auto-node|InvalidRequestException|No changes needed for EKS Auto Mode configuration " + + "provided" + }) + void updateClusterConfigRefusesTheAutoModeChangesAwsRefusesAndChangesNothing( + boolean compute, boolean blockStorage, boolean loadBalancing, String nodeRole, String type, String message) { + String name = "auto-refuse-" + UUID.randomUUID().toString().substring(0, 8); + eks(ACCOUNT, REGION).body(cluster(name, true, true, true)).post("/clusters").then().statusCode(200); + try { + eks(ACCOUNT, REGION).body(autoMode(compute, blockStorage, loadBalancing, + "arn:aws:iam::" + ACCOUNT + ":role/" + nodeRole)) + .post("/clusters/" + name + "/update-config").then().statusCode(400) + .body("__type", equalTo(type)) + .body("message", equalTo(message)); + assertAutoModeEnabled(eks(ACCOUNT, REGION).get("/clusters/" + name).then()); + } finally { + eks(ACCOUNT, REGION).delete("/clusters/" + name).then().statusCode(200); + } + } + + @Test + void turningAutoModeOffOnAClusterThatNeverHadItChangesNothing() { + String name = "auto-noop-" + UUID.randomUUID().toString().substring(0, 8); + eks(ACCOUNT, REGION).body(""" + {"name":"%s","roleArn":"arn:aws:iam::%s:role/eks-auto-cluster"}""".formatted(name, ACCOUNT)) + .post("/clusters").then().statusCode(200); + try { + eks(ACCOUNT, REGION).body(autoMode(false, false, false, null)) + .post("/clusters/" + name + "/update-config").then().statusCode(400) + .body("__type", equalTo("InvalidRequestException")) + .body("message", equalTo("No changes needed for EKS Auto Mode configuration provided")); + } finally { + eks(ACCOUNT, REGION).delete("/clusters/" + name).then().statusCode(200); + } + } + + @Test + void anAutoModeUpdateWithAnotherFamilyIsRefused() { + String name = "auto-two-" + UUID.randomUUID().toString().substring(0, 8); + eks(ACCOUNT, REGION).body(cluster(name, true, true, true)).post("/clusters").then().statusCode(200); + try { + eks(ACCOUNT, REGION).body(""" + {"computeConfig":{"enabled":false},"storageConfig":{"blockStorage":{"enabled":false}}, + "kubernetesNetworkConfig":{"elasticLoadBalancing":{"enabled":false}}, + "logging":{"clusterLogging":[{"types":["audit"],"enabled":true}]}}""") + .post("/clusters/" + name + "/update-config").then().statusCode(400) + .body("__type", equalTo("InvalidParameterException")) + .body("message", equalTo("Only one type of update can be allowed.")); + assertAutoModeEnabled(eks(ACCOUNT, REGION).get("/clusters/" + name).then()); + } finally { + eks(ACCOUNT, REGION).delete("/clusters/" + name).then().statusCode(200); + } + } + + @Test + void turningOffTheBuiltInNodePoolsWithoutANodeRoleKeepsTheRole() { + String name = "auto-pools-" + UUID.randomUUID().toString().substring(0, 8); + eks(ACCOUNT, REGION).body(cluster(name, true, true, true)).post("/clusters").then().statusCode(200); + try { + // AWS's own example (set-builtin-node-pools) turns both built-in pools off with no node role. + eks(ACCOUNT, REGION).body(""" + {"computeConfig":{"enabled":true,"nodePools":[]}, + "kubernetesNetworkConfig":{"elasticLoadBalancing":{"enabled":true}}, + "storageConfig":{"blockStorage":{"enabled":true}}}""") + .post("/clusters/" + name + "/update-config").then().statusCode(200) + .body("update.type", equalTo("AutoModeUpdate")); + eks(ACCOUNT, REGION).get("/clusters/" + name).then().statusCode(200) + .body("cluster.computeConfig.enabled", equalTo(true)) + .body("cluster.computeConfig.nodePools", empty()) + .body("cluster.computeConfig.nodeRoleArn", equalTo(NODE_ROLE)); + } finally { + eks(ACCOUNT, REGION).delete("/clusters/" + name).then().statusCode(200); + } + } + + @ParameterizedTest + @CsvSource(delimiter = '|', value = { + // turning compute off alone would leave block storage and load balancing on + "{\"computeConfig\":{\"enabled\":false}}|For EKS Auto Mode, please ensure that all required configs, " + + "including computeConfig, kubernetesNetworkConfig, and blockStorage are all either fully " + + "enabled or fully disabled.", + // a load balancing member Floci does not apply + "{\"kubernetesNetworkConfig\":{\"elasticLoadBalancing\":{\"enabled\":true,\"gatewayApi\":{}}}}" + + "|Floci does not support updating kubernetesNetworkConfig.elasticLoadBalancing.gatewayApi " + + "through UpdateClusterConfig yet", + // a node pool that is null + "{\"computeConfig\":{\"enabled\":true,\"nodePools\":[null],\"nodeRoleArn\":\"" + + "arn:aws:iam::864208642086:role/eks-auto-node\"}," + + "\"storageConfig\":{\"blockStorage\":{\"enabled\":true}}," + + "\"kubernetesNetworkConfig\":{\"elasticLoadBalancing\":{\"enabled\":true}}}" + + "|nodePools must not contain null" + }) + void anAutoModeUpdateFlociCannotApplyWholeIsRefusedAndChangesNothing(String body, String message) { + String name = "auto-whole-" + UUID.randomUUID().toString().substring(0, 8); + eks(ACCOUNT, REGION).body(cluster(name, true, true, true)).post("/clusters").then().statusCode(200); + try { + eks(ACCOUNT, REGION).body(body).post("/clusters/" + name + "/update-config").then().statusCode(400) + .body("__type", equalTo("InvalidParameterException")) + .body("message", equalTo(message)); + assertAutoModeEnabled(eks(ACCOUNT, REGION).get("/clusters/" + name).then()); + } finally { + eks(ACCOUNT, REGION).delete("/clusters/" + name).then().statusCode(200); + } + } + + @Test + void omittedAndEmptyNodePoolsAreTheSameConfiguration() { + String name = "auto-nopools-" + UUID.randomUUID().toString().substring(0, 8); + eks(ACCOUNT, REGION).body(""" + {"name":"%s","roleArn":"arn:aws:iam::%s:role/eks-auto-cluster", + "computeConfig":{"enabled":true}, + "storageConfig":{"blockStorage":{"enabled":true}}, + "kubernetesNetworkConfig":{"elasticLoadBalancing":{"enabled":true}}}""".formatted(name, ACCOUNT)) + .post("/clusters").then().statusCode(200); + try { + eks(ACCOUNT, REGION).body(""" + {"computeConfig":{"enabled":true,"nodePools":[]}, + "storageConfig":{"blockStorage":{"enabled":true}}, + "kubernetesNetworkConfig":{"elasticLoadBalancing":{"enabled":true}}}""") + .post("/clusters/" + name + "/update-config").then().statusCode(400) + .body("__type", equalTo("InvalidRequestException")) + .body("message", equalTo("No changes needed for EKS Auto Mode configuration provided")); + } finally { + eks(ACCOUNT, REGION).delete("/clusters/" + name).then().statusCode(200); + } + } + + private static String autoMode(boolean compute, boolean blockStorage, boolean loadBalancing, String nodeRole) { + String computeConfig = compute + ? "{\"enabled\":true,\"nodePools\":[\"general-purpose\",\"system\"],\"nodeRoleArn\":\"" + nodeRole + "\"}" + : "{\"enabled\":false}"; + return """ + {"computeConfig":%s,"storageConfig":{"blockStorage":{"enabled":%b}}, + "kubernetesNetworkConfig":{"elasticLoadBalancing":{"enabled":%b}}}""" + .formatted(computeConfig, blockStorage, loadBalancing); + } + private static void assertAutoModeEnabled(ValidatableResponse response) { response.statusCode(200) .body("cluster.computeConfig.enabled", equalTo(true))