mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): update an EKS nodegroup in place unless the engine says it must be replaced (#8734)
An AWS::EKS::Nodegroup update no longer creates another nodegroup. One that changes no create-only property keeps its name and ARN, and its stack-managed tags are reconciled while tags added outside the stack stay; a failed update puts them back. A change to a property the registry marks create-only replaces the nodegroup and deletes the old one once the update commits. EksService cannot apply the other mutable properties, so the cluster and the nodegroup accept any change the engine reports beyond Tags with a warning. The nodegroup is created with its template tags, and a rolled-back replacement puts back the tag-key records of the entity it restores. Part of #6606
This commit is contained in:
1 parent
a086572321
commit
9c9792a019
8 files changed
+284
-57
No files matched your search
@@ -114,6 +114,10 @@ class CfnReplacementIntegrationTest {
|
||||
"True", true, "repl-sng-b");
|
||||
|
||||
private static final String EKS_CLUSTER = "\"RoleArn\": \"arn:aws:iam::000000000000:role/repl-eks\", ";
|
||||
private static final String EKS_NODEGROUP_CLUSTER = "\"Cluster\": {\"Type\": \"AWS::EKS::Cluster\","
|
||||
+ " \"Properties\": {\"RoleArn\": \"arn:aws:iam::000000000000:role/repl-eks\"}}";
|
||||
private static final String EKS_NODEGROUP = "\"ClusterName\": {\"Ref\": \"Cluster\"},"
|
||||
+ " \"Subnets\": [\"subnet-aaaa1111\"], ";
|
||||
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\","
|
||||
@@ -252,6 +256,16 @@ class CfnReplacementIntegrationTest {
|
||||
"\"RoleArn\": \"arn:aws:iam::000000000000:role/repl-eks-@V@\"",
|
||||
"\"RoleArn\": \"arn:aws:iam::000000000000:role/repl-eks-@V@\"",
|
||||
"True", false, null),
|
||||
createOnlyRow("EKS nodegroup Tags", EKS_NODEGROUP_CLUSTER, "", "AWS::EKS::Nodegroup",
|
||||
EKS_NODEGROUP + "\"NodeRole\": \"arn:aws:iam::000000000000:role/repl-ng\","
|
||||
+ " \"Tags\": [{\"Key\": \"team\", \"Value\": \"@V@\"}]",
|
||||
EKS_NODEGROUP + "\"NodeRole\": \"arn:aws:iam::000000000000:role/repl-ng\","
|
||||
+ " \"Tags\": [{\"Key\": \"team\", \"Value\": \"@V@\"}]",
|
||||
"False", false, null),
|
||||
createOnlyRow("EKS nodegroup NodeRole", EKS_NODEGROUP_CLUSTER, "", "AWS::EKS::Nodegroup",
|
||||
EKS_NODEGROUP + "\"NodeRole\": \"arn:aws:iam::000000000000:role/repl-ng-@V@\"",
|
||||
EKS_NODEGROUP + "\"NodeRole\": \"arn:aws:iam::000000000000:role/repl-ng-@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"),
|
||||
|
||||
+76
@@ -3,10 +3,14 @@ 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 io.restassured.path.json.JsonPath;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.cloudformation.CloudFormationClient;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
@@ -15,6 +19,7 @@ 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;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
/**
|
||||
* End-to-end check that CloudFormation provisions EKS resources for real (into EksService) rather
|
||||
@@ -130,6 +135,77 @@ class CloudFormationEksIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnnamedNodegroupKeepsItsArnAndReconcilesStackTagsWhenOnlyTagsChange() {
|
||||
String stack = "cfn-eksng-upd-" + Long.toString(System.nanoTime(), 36);
|
||||
try (CloudFormationClient client = AwsTestClients.create(
|
||||
CloudFormationClient.builder(), "test", Region.US_EAST_1)) {
|
||||
CfnStackWaits.createStack(client, stack, nodegroup("one", "{\"Key\": \"old\", \"Value\": \"x\"}"),
|
||||
"CREATE_COMPLETE");
|
||||
String base = "/clusters/" + physicalId(client, stack, "Cluster") + "/node-groups";
|
||||
List<String> names = given().get(base).jsonPath().getList("nodegroups");
|
||||
assertEquals(1, names.size());
|
||||
String arn = given().get(base + "/" + names.getFirst()).jsonPath().getString("nodegroup.nodegroupArn");
|
||||
given().contentType("application/json").body(Map.of("tags", Map.of("ext", "1")))
|
||||
.post("/tags/" + arn).then().statusCode(200);
|
||||
|
||||
createUpdateChangeSet(client, stack, "tags", nodegroup("two", ""));
|
||||
executeAndAwaitUpdate(client, stack, "tags");
|
||||
|
||||
assertEquals(names, given().get(base).jsonPath().getList("nodegroups"));
|
||||
JsonPath after = given().get(base + "/" + names.getFirst()).jsonPath();
|
||||
assertEquals(arn, after.getString("nodegroup.nodegroupArn"));
|
||||
assertEquals("two", after.getString("nodegroup.tags.team"));
|
||||
assertEquals("1", after.getString("nodegroup.tags.ext"));
|
||||
assertNull(after.getString("nodegroup.tags.old"));
|
||||
} finally {
|
||||
CfnStackWaits.deleteStack(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aDroppedTagIsGoneFromTheOriginalNodegroupAfterAReplacementRolledBack() {
|
||||
String stack = "cfn-eksng-rb-" + Long.toString(System.nanoTime(), 36);
|
||||
try (CloudFormationClient client = AwsTestClients.create(
|
||||
CloudFormationClient.builder(), "test", Region.US_EAST_1)) {
|
||||
CfnStackWaits.createStack(client, stack, rollbackStack("a", "env", "dev", false), "CREATE_COMPLETE");
|
||||
String base = "/clusters/" + physicalId(client, stack, "Cluster") + "/node-groups";
|
||||
List<String> names = given().get(base).jsonPath().getList("nodegroups");
|
||||
|
||||
CfnStackWaits.updateStack(client, stack, rollbackStack("b", "team", "a", true),
|
||||
"UPDATE_ROLLBACK_COMPLETE");
|
||||
assertEquals(names, given().get(base).jsonPath().getList("nodegroups"));
|
||||
|
||||
CfnStackWaits.updateStack(client, stack, rollbackStack("a", null, null, false), "UPDATE_COMPLETE");
|
||||
assertEquals(names, given().get(base).jsonPath().getList("nodegroups"));
|
||||
assertNull(given().get(base + "/" + names.getFirst()).jsonPath().getString("nodegroup.tags.env"));
|
||||
} finally {
|
||||
CfnStackWaits.deleteStack(stack);
|
||||
}
|
||||
}
|
||||
|
||||
private static String rollbackStack(String roleSuffix, String tagKey, String tagValue, boolean laterFails) {
|
||||
String tags = tagKey == null ? "" : ", \"Tags\": [{\"Key\": \"" + tagKey
|
||||
+ "\", \"Value\": \"" + tagValue + "\"}]";
|
||||
String cluster = "\"Cluster\": {\"Type\": \"AWS::EKS::Cluster\", \"Properties\": {\"RoleArn\":"
|
||||
+ " \"arn:aws:iam::000000000000:role/eks-cluster-role\"" + tags + "}}";
|
||||
String template = subjectStack(cluster, "", "AWS::EKS::Nodegroup", "\"ClusterName\": {\"Ref\": \"Cluster\"},"
|
||||
+ " \"NodeRole\": \"arn:aws:iam::000000000000:role/eks-node-role-" + roleSuffix + "\","
|
||||
+ " \"Subnets\": [\"subnet-aaaa1111\"]" + tags);
|
||||
return laterFails
|
||||
? template.substring(0, template.length() - 2) + CfnStackWaits.failingResourceAfter("Subject") + "}}"
|
||||
: template;
|
||||
}
|
||||
|
||||
private static String nodegroup(String team, String extraTag) {
|
||||
String cluster = "\"Cluster\": {\"Type\": \"AWS::EKS::Cluster\", \"Properties\": {\"RoleArn\":"
|
||||
+ " \"arn:aws:iam::000000000000:role/eks-cluster-role\"}}";
|
||||
return subjectStack(cluster, "", "AWS::EKS::Nodegroup", "\"ClusterName\": {\"Ref\": \"Cluster\"},"
|
||||
+ " \"NodeRole\": \"arn:aws:iam::000000000000:role/eks-node-role\","
|
||||
+ " \"Subnets\": [\"subnet-aaaa1111\"], \"Tags\": [{\"Key\": \"team\", \"Value\": \""
|
||||
+ team + "\"}" + (extraTag.isEmpty() ? "" : ", " + extraTag) + "]");
|
||||
}
|
||||
|
||||
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 + "\"}]");
|
||||
|
||||
Reference in new issue
Block a user