mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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.
This commit is contained in:
1 parent
a7d3108134
commit
16c2505a25
4 files changed
+356
-12
No files matched your search
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user