mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
1542c641a6
commit
b4f4b386da
5 files changed
+160
-4
No files matched your search
@@ -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"));
|
||||
|
||||
+33
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user