fix(cloudformation): update an EKS cluster in place unless the engine says it must be replaced (#8730)

An AWS::EKS::Cluster update used to create another cluster every time, so an unnamed cluster left the old one behind and a named one failed. The cluster now keeps its name on an update the engine does not mark as a replacement, and the tags the last deployment wrote are reconciled from a recorded key list, leaving tags added outside the stack alone. A change to a create-only property (Name, RoleArn, EncryptionConfig, BootstrapSelfManagedAddons, OutpostConfig, AccessConfig.BootstrapClusterCreatorAdminPermissions or the network family and CIDR) replaces the cluster and deletes the old one once the update commits, and a failed update puts the tags or the prior cluster back. A Version change is accepted with a warning and not applied. EventBridge's tag reconcile now shares CfnRollback.reconcileTags.

Part of #6606
This commit is contained in:
Oleksandr Nikolaichuk authored and GitHub committed 2026-11-17 09:07:49 -04:00
1 parent 1a26ef4f73
commit a221e18838
10 files changed
+279 -19

No files matched your search

@@ -113,6 +113,7 @@ class CfnReplacementIntegrationTest {
CLUSTER + "\"CacheNodeType\": \"cache.t3.micro\", \"CacheSubnetGroupName\": {\"Ref\": \"SubnetGroup\"}",
"True", true, "repl-sng-b");
private static final String EKS_CLUSTER = "\"RoleArn\": \"arn:aws:iam::000000000000:role/repl-eks\", ";
private static final String SQS_TYPE = "AWS::SQS::Queue";
private static final String S3_TYPE = "AWS::S3::Bucket";
private static final String DDB_KEYS = "\"BillingMode\": \"PAY_PER_REQUEST\","
@@ -243,6 +244,14 @@ class CfnReplacementIntegrationTest {
"\"TopicArn\": {\"Ref\": \"TopicB\"}, \"Protocol\": \"sqs\","
+ " \"Endpoint\": \"arn:aws:sqs:us-east-1:000000000000:repl-sub\"",
"True", false, null),
createOnlyRow("EKS cluster Tags", "", "", "AWS::EKS::Cluster",
EKS_CLUSTER + "\"Tags\": [{\"Key\": \"team\", \"Value\": \"@V@\"}]",
EKS_CLUSTER + "\"Tags\": [{\"Key\": \"team\", \"Value\": \"@V@\"}]",
"False", false, null),
createOnlyRow("EKS cluster RoleArn", "", "", "AWS::EKS::Cluster",
"\"RoleArn\": \"arn:aws:iam::000000000000:role/repl-eks-@V@\"",
"\"RoleArn\": \"arn:aws:iam::000000000000:role/repl-eks-@V@\"",
"True", false, null),
new Row("deployed parameter renamed, same value",
locationStack(stringParameter("NameA", HOSTED), "", REF_A, "d"),
locationStack(stringParameter("NameB", HOSTED), "", REF_B, "e"),
@@ -1,11 +1,20 @@
package io.floci.aws.services.cloudformation;
import io.floci.aws.testing.AwsTestClients;
import io.floci.aws.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.cloudformation.CloudFormationClient;
import static io.floci.aws.services.cloudformation.CfnStackTestSupport.createUpdateChangeSet;
import static io.floci.aws.services.cloudformation.CfnStackTestSupport.executeAndAwaitUpdate;
import static io.floci.aws.services.cloudformation.CfnStackTestSupport.physicalId;
import static io.floci.aws.services.cloudformation.CfnStackTestSupport.subjectStack;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
/**
* End-to-end check that CloudFormation provisions EKS resources for real (into EksService) rather
@@ -95,4 +104,34 @@ class CloudFormationEksIntegrationTest {
.statusCode(200)
.body(containsString(nodegroupName));
}
@Test
void anUnnamedClusterIsUpdatedInPlaceAndReplacedOnlyWhenItsRoleChanges() {
String stack = "cfn-eks-upd-" + Long.toString(System.nanoTime(), 36);
try (CloudFormationClient client = AwsTestClients.create(
CloudFormationClient.builder(), "test", Region.US_EAST_1)) {
CfnStackWaits.createStack(client, stack, cluster("role-a", "one"), "CREATE_COMPLETE");
String first = physicalId(client, stack, "Subject");
int count = given().get("/clusters").jsonPath().getList("clusters").size();
createUpdateChangeSet(client, stack, "tags", cluster("role-a", "two"));
executeAndAwaitUpdate(client, stack, "tags");
assertEquals(first, physicalId(client, stack, "Subject"));
assertEquals(count, given().get("/clusters").jsonPath().getList("clusters").size());
assertEquals("two", given().get("/clusters/" + first).jsonPath().getString("cluster.tags.team"));
createUpdateChangeSet(client, stack, "role", cluster("role-b", "two"));
executeAndAwaitUpdate(client, stack, "role");
assertNotEquals(first, physicalId(client, stack, "Subject"));
given().get("/clusters/" + first).then().statusCode(404);
assertEquals(count, given().get("/clusters").jsonPath().getList("clusters").size());
} finally {
CfnStackWaits.deleteStack(stack);
}
}
private static String cluster(String role, String team) {
return subjectStack("", "", "AWS::EKS::Cluster", "\"RoleArn\": \"arn:aws:iam::000000000000:role/" + role
+ "\", \"Tags\": [{\"Key\": \"team\", \"Value\": \"" + team + "\"}]");
}
}
@@ -60,7 +60,8 @@ class EksCfnProvisionerTest {
"""), ctx());
assertEquals("prod", r.getPhysicalId());
assertEquals(Set.of("Arn", "Endpoint", "CertificateAuthorityData", "OpenIdConnectIssuerUrl"),
assertEquals(Set.of("Arn", "Endpoint", "CertificateAuthorityData", "OpenIdConnectIssuerUrl",
"__FlociEksClusterTagKeys"),
r.getAttributes().keySet());
assertEquals("arn:aws:eks:us-east-1:000000000000:cluster/prod", r.getAttributes().get("Arn"));
assertEquals("LS0tLS1CRUdJTg==", r.getAttributes().get("CertificateAuthorityData"));