mirror of
https://github.com/floci-io/floci.git
synced 2026-11-29 08:31:53 -05:00
fix(eks): accept a cluster's unchanged ipFamily and serviceIpv4Cidr in UpdateClusterConfig (#9715)
UpdateClusterConfig refused every kubernetesNetworkConfig member other than elasticLoadBalancing, so turning EKS Auto Mode on through the Terraform AWS provider failed: its update carries the cluster's current ipFamily and serviceIpv4Cidr beside elasticLoadBalancing. The cluster's own values are now accepted unchanged, ipFamily in any case. Another value for either is still refused, as EKS sets both only when it creates a cluster and Floci doesn't change them.
This commit is contained in:
1 parent
2e707b4b4b
commit
3909e10e2e
4 files changed
+113
-6
No files matched your search
@@ -429,9 +429,10 @@ neither is accepted, as AWS accepts it for Auto Mode without its built-in node p
|
||||
`UpdateClusterConfig` turns Auto Mode on or off for an existing cluster and changes its node pools, taking
|
||||
`computeConfig`, `storageConfig` and `kubernetesNetworkConfig.elasticLoadBalancing` together as one update, which
|
||||
it records as an `AutoModeUpdate`. A member the request leaves out keeps its stored value, and while compute stays
|
||||
on, a `computeConfig` without `nodeRoleArn` keeps the cluster's role, which can't change while it is on. A request
|
||||
that changes nothing is refused with `InvalidRequestException` ("No changes needed for EKS Auto Mode
|
||||
configuration provided").
|
||||
on, a `computeConfig` without `nodeRoleArn` keeps the cluster's role, which can't change while it is on. The
|
||||
`kubernetesNetworkConfig` may also carry the cluster's current `ipFamily` and `serviceIpv4Cidr`, as the Terraform
|
||||
AWS provider sends them; another value for either is refused, as Floci doesn't change them. A request that changes
|
||||
nothing is refused with `InvalidRequestException` ("No changes needed for EKS Auto Mode configuration provided").
|
||||
|
||||
In CloudFormation, `AWS::EKS::Cluster` creates its cluster with `ComputeConfig`, `StorageConfig` and
|
||||
`KubernetesNetworkConfig.ElasticLoadBalancing`, and an update changes them in place through `UpdateClusterConfig`:
|
||||
|
||||
@@ -17,6 +17,7 @@ import io.floci.aws.services.eks.model.CreateFargateProfileRequest;
|
||||
import io.floci.aws.services.eks.model.CreateNodeGroupRequest;
|
||||
import io.floci.aws.services.eks.model.CreatePodIdentityAssociationRequest;
|
||||
import io.floci.aws.services.eks.model.FargateProfile;
|
||||
import io.floci.aws.services.eks.model.KubernetesNetworkConfig;
|
||||
import io.floci.aws.services.eks.model.Nodegroup;
|
||||
import io.floci.aws.services.eks.model.PodIdentityAssociation;
|
||||
import io.floci.aws.services.eks.model.Update;
|
||||
@@ -377,7 +378,10 @@ public class EksController {
|
||||
}
|
||||
JsonNode network = body.path("kubernetesNetworkConfig");
|
||||
for (String member : (Iterable<String>) network::fieldNames) {
|
||||
if (!"elasticLoadBalancing".equals(member)) {
|
||||
// The Terraform AWS provider sends the cluster's current ipFamily and serviceIpv4Cidr with
|
||||
// elasticLoadBalancing, as EKS accepts them unchanged; only a change is one Floci doesn't apply.
|
||||
if (!"elasticLoadBalancing".equals(member)
|
||||
&& !unchangedNetworkMember(name, member, network.get(member))) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Floci does not support updating kubernetesNetworkConfig." + member
|
||||
+ " through UpdateClusterConfig yet", 400);
|
||||
@@ -404,6 +408,25 @@ public class EksController {
|
||||
return Response.ok(Map.of("update", eksService.updateClusterConfig(name, request).get(0))).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an UpdateClusterConfig {@code kubernetesNetworkConfig} member other than {@code elasticLoadBalancing}
|
||||
* names the cluster's current value: {@code ipFamily} (case aside) or {@code serviceIpv4Cidr}.
|
||||
*/
|
||||
private boolean unchangedNetworkMember(String name, String member, JsonNode value) {
|
||||
if (!value.isTextual()) {
|
||||
return false;
|
||||
}
|
||||
KubernetesNetworkConfig current = eksService.requireClusterInRequestRegion(name).getKubernetesNetworkConfig();
|
||||
if (current == null) {
|
||||
return false;
|
||||
}
|
||||
return switch (member) {
|
||||
case "ipFamily" -> value.asText().equalsIgnoreCase(current.getIpFamily());
|
||||
case "serviceIpv4Cidr" -> value.asText().equals(current.getServiceIpv4Cidr());
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/updates/{updateId}")
|
||||
public Response describeUpdate(@PathParam("name") String name,
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package io.floci.aws.services.eks;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
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 software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.eks.EksClient;
|
||||
import software.amazon.awssdk.services.eks.model.Cluster;
|
||||
import software.amazon.awssdk.services.eks.model.IpFamily;
|
||||
import software.amazon.awssdk.services.eks.model.UpdateType;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.floci.aws.testing.EksRequests.eks;
|
||||
@@ -13,6 +21,7 @@ import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@QuarkusTest
|
||||
class EksAutoModeIntegrationTest {
|
||||
@@ -21,6 +30,9 @@ class EksAutoModeIntegrationTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String NODE_ROLE = "arn:aws:iam::" + ACCOUNT + ":role/eks-auto-node";
|
||||
|
||||
@TestHTTPResource("/")
|
||||
URI endpoint;
|
||||
|
||||
@Test
|
||||
void anAutoModeClusterCreatesAndDescribesItsConfiguration() {
|
||||
String name = "auto-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
@@ -175,6 +187,76 @@ class EksAutoModeIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto Mode turned on as the Terraform AWS provider turns it on: its kubernetesNetworkConfig carries the
|
||||
* cluster's current ipFamily and serviceIpv4Cidr with elasticLoadBalancing, as EKS accepts. Another
|
||||
* serviceIpv4Cidr is still refused, as Floci doesn't apply it.
|
||||
*/
|
||||
@Test
|
||||
void autoModeTurnsOnWithTheClustersUnchangedIpFamilyAndServiceCidr() {
|
||||
String name = "auto-tf-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
eks(ACCOUNT, REGION).body(cluster(name, false, false, false)).post("/clusters").then().statusCode(200);
|
||||
try {
|
||||
String cidr = eks(ACCOUNT, REGION).get("/clusters/" + name).then().statusCode(200)
|
||||
.extract().path("cluster.kubernetesNetworkConfig.serviceIpv4Cidr");
|
||||
String update = """
|
||||
{"computeConfig":{"enabled":true,"nodePools":["general-purpose","system"],"nodeRoleArn":"%s"},
|
||||
"kubernetesNetworkConfig":{"elasticLoadBalancing":{"enabled":true},"ipFamily":"ipv4",
|
||||
"serviceIpv4Cidr":"%s"},
|
||||
"storageConfig":{"blockStorage":{"enabled":true}}}""";
|
||||
|
||||
eks(ACCOUNT, REGION).body(update.formatted(NODE_ROLE, "10.99.0.0/16"))
|
||||
.post("/clusters/" + name + "/update-config").then().statusCode(400)
|
||||
.body("message", equalTo("Floci does not support updating "
|
||||
+ "kubernetesNetworkConfig.serviceIpv4Cidr through UpdateClusterConfig yet"));
|
||||
|
||||
eks(ACCOUNT, REGION).body(update.formatted(NODE_ROLE, cidr))
|
||||
.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.kubernetesNetworkConfig.elasticLoadBalancing.enabled", equalTo(true))
|
||||
.body("cluster.kubernetesNetworkConfig.ipFamily", equalTo("ipv4"))
|
||||
.body("cluster.kubernetesNetworkConfig.serviceIpv4Cidr", equalTo(cidr));
|
||||
} finally {
|
||||
eks(ACCOUNT, REGION).delete("/clusters/" + name).then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The same update through the AWS SDK, as a client sends it: its {@code KubernetesNetworkConfigRequest} carries the
|
||||
* cluster's own {@code ipFamily} and {@code serviceIpv4Cidr} beside {@code elasticLoadBalancing}.
|
||||
*/
|
||||
@Test
|
||||
void autoModeTurnsOnThroughTheSdkWithTheClustersUnchangedNetworkConfig() {
|
||||
String name = "auto-sdk-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
try (EksClient eks = AwsTestClients.create(EksClient.builder(), ACCOUNT, Region.US_EAST_1, endpoint)) {
|
||||
eks.createCluster(r -> r.name(name).roleArn("arn:aws:iam::" + ACCOUNT + ":role/eks-auto-cluster"));
|
||||
try {
|
||||
Cluster before = eks.describeCluster(r -> r.name(name)).cluster();
|
||||
|
||||
UpdateType type = eks.updateClusterConfig(r -> r.name(name)
|
||||
.computeConfig(c -> c.enabled(true).nodePools("general-purpose", "system").nodeRoleArn(NODE_ROLE))
|
||||
.storageConfig(c -> c.blockStorage(b -> b.enabled(true)))
|
||||
.kubernetesNetworkConfig(n -> n.elasticLoadBalancing(e -> e.enabled(true))
|
||||
.ipFamily(before.kubernetesNetworkConfig().ipFamily())
|
||||
.serviceIpv4Cidr(before.kubernetesNetworkConfig().serviceIpv4Cidr())))
|
||||
.update().type();
|
||||
|
||||
assertEquals(UpdateType.AUTO_MODE_UPDATE, type);
|
||||
Cluster after = eks.describeCluster(r -> r.name(name)).cluster();
|
||||
assertEquals(true, after.computeConfig().enabled());
|
||||
assertEquals(true, after.storageConfig().blockStorage().enabled());
|
||||
assertEquals(true, after.kubernetesNetworkConfig().elasticLoadBalancing().enabled());
|
||||
assertEquals(IpFamily.IPV4, after.kubernetesNetworkConfig().ipFamily());
|
||||
assertEquals(before.kubernetesNetworkConfig().serviceIpv4Cidr(),
|
||||
after.kubernetesNetworkConfig().serviceIpv4Cidr());
|
||||
} finally {
|
||||
eks.deleteCluster(r -> r.name(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '|', value = {
|
||||
// turning compute off alone would leave block storage and load balancing on
|
||||
|
||||
@@ -276,8 +276,9 @@ class EksEncryptionLoggingIntegrationTest {
|
||||
"{\"upgradePolicy\":{}}|400|InvalidParameterException|null",
|
||||
// a number where the model has a boolean, as createCluster refuses it
|
||||
"{\"resourcesVpcConfig\":{\"endpointPublicAccess\":1}}|400|SerializationException|null",
|
||||
// members UpdateClusterConfig does not support here
|
||||
"{\"kubernetesNetworkConfig\":{\"ipFamily\":\"ipv4\"}}|400|InvalidParameterException|null",
|
||||
// members UpdateClusterConfig does not support here: another ipFamily (the cluster's own is accepted
|
||||
// unchanged, as the Terraform AWS provider sends it)
|
||||
"{\"kubernetesNetworkConfig\":{\"ipFamily\":\"ipv6\"}}|400|InvalidParameterException|null",
|
||||
"{\"deletionProtection\":true}|400|InvalidParameterException|null",
|
||||
"{\"deletionProtection\":true,\"logging\":{\"clusterLogging\":[{\"types\":[\"audit\"],\"enabled\":true}]}}"
|
||||
+ "|400|InvalidParameterException|null",
|
||||
|
||||
Reference in new issue
Block a user