fix(eks): persist explicit version flag across restarts (#4101)

* fix(eks): persist explicit version flag across restarts

* fix(eks): omit explicit version flag from API responses
This commit is contained in:
Simone Primarosa authored and GitHub committed 2026-09-21 16:29:54 -04:00
1 parent 1542c641a6
commit b4f4b386da
5 files changed
+160 -4

No files matched your search

@@ -61,7 +61,7 @@ public class EksController {
@Path("/clusters")
public Response createCluster(CreateClusterRequest request) {
Cluster cluster = eksService.createCluster(request);
return Response.ok(Map.of("cluster", cluster)).build();
return Response.ok(Map.of("cluster", toClusterResponse(cluster))).build();
}
@GET
@@ -75,14 +75,29 @@ public class EksController {
@Path("/clusters/{name}")
public Response describeCluster(@PathParam("name") String name) {
Cluster cluster = eksService.describeCluster(name);
return Response.ok(Map.of("cluster", cluster)).build();
return Response.ok(Map.of("cluster", toClusterResponse(cluster))).build();
}
@DELETE
@Path("/clusters/{name}")
public Response deleteCluster(@PathParam("name") String name) {
Cluster cluster = eksService.deleteCluster(name);
return Response.ok(Map.of("cluster", cluster)).build();
return Response.ok(Map.of("cluster", toClusterResponse(cluster))).build();
}
/**
* Sanitizes the cluster model before emitting it as an AWS API response.
* explicitVersion is internal Floci metadata used for container image resolution
* across restarts and must not be included on the wire. Clearing it on a copy
* causes Jackson to omit the property due to @JsonInclude(NON_DEFAULT).
*/
private Cluster toClusterResponse(Cluster cluster) {
if (cluster == null || !cluster.isExplicitVersion()) {
return cluster;
}
Cluster response = cluster.copy();
response.setExplicitVersion(false);
return response;
}
// Keep these concrete EKS resource paths declared explicitly so they outrank
@@ -77,7 +77,15 @@ public class Cluster {
@JsonIgnore
private String podCidr;
@JsonIgnore
/**
* Internal flag indicating whether the Kubernetes version was explicitly requested by
* the caller (true) or defaulted (false). Persisted to storage so that clusters explicitly
* pinned to the default version (e.g. 1.29) resolve to their pinned image across restarts
* rather than falling back to the unversioned default image. Omitted from AWS API responses
* by toClusterResponse in EksController.
*/
@JsonProperty("explicitVersion")
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
private boolean explicitVersion;
/**
@@ -160,4 +168,32 @@ public class Cluster {
public boolean isExplicitVersion() { return explicitVersion; }
public void setExplicitVersion(boolean explicitVersion) { this.explicitVersion = explicitVersion; }
public Cluster copy() {
Cluster c = new Cluster();
c.name = this.name;
c.arn = this.arn;
c.createdAt = this.createdAt;
c.version = this.version;
c.endpoint = this.endpoint;
c.roleArn = this.roleArn;
c.resourcesVpcConfig = this.resourcesVpcConfig;
c.kubernetesNetworkConfig = this.kubernetesNetworkConfig;
c.logging = this.logging;
c.encryptionConfig = this.encryptionConfig;
c.status = this.status;
c.certificateAuthority = this.certificateAuthority;
c.identity = this.identity;
c.platformVersion = this.platformVersion;
c.tags = this.tags;
c.containerId = this.containerId;
c.accountId = this.accountId;
c.internalEndpoint = this.internalEndpoint;
c.hostPort = this.hostPort;
c.podCidr = this.podCidr;
c.explicitVersion = this.explicitVersion;
c.dockerName = this.dockerName;
c.accessConfig = this.accessConfig;
return c;
}
}
@@ -1297,6 +1297,37 @@ class EksClusterManagerTest {
assertEquals("rancher/k3s:v1.29.14-k3s1", manager.resolveClusterImage(cluster));
}
@Test
void resolveClusterImagePreservesExplicitVersionAcrossSerializationRoundTrip() throws Exception {
ObjectMapper mapper = new ObjectMapper();
// Cluster with explicit version 1.29 (matching default version string)
Cluster explicit129 = new Cluster();
explicit129.setName("explicit-129");
explicit129.setVersion("1.29");
explicit129.setExplicitVersion(true);
String jsonExplicit = mapper.writeValueAsString(explicit129);
assertTrue(jsonExplicit.contains("\"explicitVersion\":true"));
Cluster reloadedExplicit = mapper.readValue(jsonExplicit, Cluster.class);
assertTrue(reloadedExplicit.isExplicitVersion());
assertEquals("rancher/k3s:v1.29.14-k3s1", manager.resolveClusterImage(reloadedExplicit));
// Cluster without explicit version
Cluster unversioned = new Cluster();
unversioned.setName("unversioned");
unversioned.setVersion("1.29");
unversioned.setExplicitVersion(false);
String jsonUnversioned = mapper.writeValueAsString(unversioned);
assertFalse(jsonUnversioned.contains("explicitVersion"));
Cluster reloadedUnversioned = mapper.readValue(jsonUnversioned, Cluster.class);
assertFalse(reloadedUnversioned.isExplicitVersion());
assertEquals("rancher/k3s:latest", manager.resolveClusterImage(reloadedUnversioned));
}
@Test
void resolveClusterImageUsesConfiguredImageTemplate() {
when(eks.imageTemplate()).thenReturn(Optional.of("internal.registry.io/k3s:v%s-custom"));
@@ -9,7 +9,9 @@ import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
@QuarkusTest
@@ -182,4 +184,35 @@ class EksEncryptionLoggingIntegrationTest {
.then().statusCode(400)
.body("message", equalTo("Invalid k8s resource and provider for encryption"));
}
@Test
@Order(10)
void describeClusterDoesNotCarryExplicitVersion() {
String clusterName = "it-explicit-version-wire-test";
String payload = "{"
+ "\"name\":\"" + clusterName + "\","
+ "\"roleArn\":\"arn:aws:iam::000000000000:role/eks-role\","
+ "\"version\":\"1.29\""
+ "}";
given().contentType(JSON)
.body(payload)
.when().post("/clusters")
.then().statusCode(200)
.body("cluster.name", equalTo(clusterName))
.body("cluster.version", equalTo("1.29"))
.body("cluster", not(hasKey("explicitVersion")));
given().contentType(JSON)
.when().get("/clusters/" + clusterName)
.then().statusCode(200)
.body("cluster.name", equalTo(clusterName))
.body("cluster.version", equalTo("1.29"))
.body("cluster", not(hasKey("explicitVersion")));
given().contentType(JSON)
.when().delete("/clusters/" + clusterName)
.then().statusCode(200)
.body("cluster", not(hasKey("explicitVersion")));
}
}
@@ -1815,6 +1815,47 @@ class EksServiceTest {
assertFalse(created.isExplicitVersion());
}
@Test
void explicitVersionPreservedAcrossRestart() throws Exception {
CreateClusterRequest explicitReq = createTestClusterRequest("explicit-129-cluster");
explicitReq.setVersion("1.29");
Cluster createdExplicit = eksService.createCluster(explicitReq);
assertTrue(createdExplicit.isExplicitVersion());
CreateClusterRequest defaultReq = createTestClusterRequest("default-129-cluster");
defaultReq.setVersion(null);
Cluster createdDefault = eksService.createCluster(defaultReq);
assertFalse(createdDefault.isExplicitVersion());
ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
Cluster reloadedExplicit = mapper.readValue(mapper.writeValueAsString(createdExplicit), Cluster.class);
assertTrue(reloadedExplicit.isExplicitVersion());
assertEquals("1.29", reloadedExplicit.getVersion());
Cluster reloadedDefault = mapper.readValue(mapper.writeValueAsString(createdDefault), Cluster.class);
assertFalse(reloadedDefault.isExplicitVersion());
assertEquals("1.29", reloadedDefault.getVersion());
}
@Test
void clusterCopyClearsExplicitVersionForWireResponse() throws Exception {
CreateClusterRequest explicitReq = createTestClusterRequest("wire-explicit-cluster");
explicitReq.setVersion("1.29");
Cluster explicitCluster = eksService.createCluster(explicitReq);
assertTrue(explicitCluster.isExplicitVersion());
Cluster responseCopy = explicitCluster.copy();
responseCopy.setExplicitVersion(false);
assertFalse(responseCopy.isExplicitVersion());
assertEquals("wire-explicit-cluster", responseCopy.getName());
assertEquals("1.29", responseCopy.getVersion());
ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
String json = mapper.writeValueAsString(responseCopy);
assertFalse(json.contains("explicitVersion"));
assertTrue(json.contains("\"version\":\"1.29\""));
}
@Test
void createClusterWithInvalidVersionFormatThrowsInvalidParameterException() {
CreateClusterRequest req1 = createTestClusterRequest("v-prefix-cluster");