feat(eks): vendor AWS's add-on version catalog for every supported Kubernetes version (#6735)

This commit is contained in:
Robin Baeckman authored and GitHub committed 2026-10-30 07:21:01 -04:00
1 parent 804b503a33
commit 07f2d62c17
9 files changed
+1045 -383

No files matched your search

@@ -288,7 +288,8 @@ class EksAddonIntegrationTest {
String name = "addon-k8s-" + UUID.randomUUID().toString().substring(0, 8);
String basePath = "/clusters/" + name + "/addons";
createCluster(account, name, "1.35");
// Newer than every version the catalog and the k3s map cover; this test runs EKS in mock mode.
createCluster(account, name, "1.40");
try {
// Create with no version resolves default version on cluster outside catalog range
given().header("Authorization", auth(account, "eks"))
@@ -396,7 +397,7 @@ class EksAddonIntegrationTest {
createCluster(account, name, "1.30");
try {
// 1. Create aws-ebs-csi-driver addon without specifying version (resolves default v1.31.0-eksbuild.1)
// 1. Create aws-ebs-csi-driver addon without specifying version (resolves the catalog's 1.30 default)
Map<String, Object> createReq = Map.of(
"addonName", "aws-ebs-csi-driver",
"serviceAccountRoleArn", roleArn
@@ -411,7 +412,7 @@ class EksAddonIntegrationTest {
.contentType(containsString("application/json"))
.body("addon.clusterName", equalTo(name))
.body("addon.addonName", equalTo("aws-ebs-csi-driver"))
.body("addon.addonVersion", equalTo("v1.31.0-eksbuild.1"))
.body("addon.addonVersion", equalTo(EksAddonServiceTest.catalogDefault("aws-ebs-csi-driver", "1.30")))
.body("addon.status", equalTo("ACTIVE"))
.body("addon.owner", equalTo("aws"))
.body("addon.publisher", equalTo("eks"))
@@ -424,7 +425,7 @@ class EksAddonIntegrationTest {
.statusCode(200)
.contentType(containsString("application/json"))
.body("addon.addonName", equalTo("aws-ebs-csi-driver"))
.body("addon.addonVersion", equalTo("v1.31.0-eksbuild.1"))
.body("addon.addonVersion", equalTo(EksAddonServiceTest.catalogDefault("aws-ebs-csi-driver", "1.30")))
.body("addon.status", equalTo("ACTIVE"));
// 3. Filter describe-addon-versions by addonName
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.eks;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
@@ -7,6 +8,7 @@ import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.services.eks.model.Addon;
import io.github.hectorvent.floci.services.eks.model.AddonInfo;
import io.github.hectorvent.floci.services.eks.model.AddonPodIdentityAssociation;
import io.github.hectorvent.floci.services.eks.model.AddonVersionInfo;
import io.github.hectorvent.floci.services.eks.model.Cluster;
import io.github.hectorvent.floci.services.eks.model.ClusterStatus;
import io.github.hectorvent.floci.services.eks.model.CreateAddonRequest;
@@ -16,11 +18,17 @@ import io.github.hectorvent.floci.services.iam.IamService;
import io.github.hectorvent.floci.services.iam.model.IamRole;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@@ -91,7 +99,7 @@ class EksAddonServiceTest {
);
Addon created = fixture.service.create(fixture.cluster, request);
assertEquals("v1.18.1-eksbuild.1", created.addonVersion());
assertEquals(catalogDefault("vpc-cni", "1.29"), created.addonVersion());
}
@Test
@@ -424,9 +432,9 @@ class EksAddonServiceTest {
Fixture fixture = fixture();
fixture.cluster.setVersion("1.29");
// v1.16.0-eksbuild.1 is only compatible with k8s 1.28
// v1.14.0-eksbuild.3 is only compatible with k8s 1.28
CreateAddonRequest reqIncompatible = new CreateAddonRequest(
"vpc-cni", "v1.16.0-eksbuild.1", null, null, null, null, null, null);
"vpc-cni", "v1.14.0-eksbuild.3", null, null, null, null, null, null);
AwsException exCreate = assertThrows(AwsException.class, () ->
fixture.service.create(fixture.cluster, reqIncompatible));
assertEquals("InvalidParameterException", exCreate.getErrorCode());
@@ -440,7 +448,7 @@ class EksAddonServiceTest {
// Updating to incompatible version fails
UpdateAddonRequest updateIncompatible = new UpdateAddonRequest(
"v1.16.0-eksbuild.1", null, null, null, null, null);
"v1.14.0-eksbuild.3", null, null, null, null, null);
AwsException exUpdate = assertThrows(AwsException.class, () ->
fixture.service.update(fixture.cluster, "vpc-cni", updateIncompatible));
assertEquals("InvalidParameterException", exUpdate.getErrorCode());
@@ -450,7 +458,7 @@ class EksAddonServiceTest {
@Test
void clusterVersionOutsideCatalogRangeAllowsCatalogVersionsAndResolvesDefault() {
Fixture fixture = fixture();
fixture.cluster.setVersion("1.35");
fixture.cluster.setVersion("1.40");
// Create with no version resolves a default version from the catalog without error
CreateAddonRequest reqDefault = new CreateAddonRequest(
@@ -483,17 +491,49 @@ class EksAddonServiceTest {
CreateAddonRequest reqKubeProxy = new CreateAddonRequest(
"kube-proxy", null, null, null, null, null, null, null);
Addon created = fixture.service.create(fixture.cluster, reqKubeProxy);
assertEquals("v1.32.0-eksbuild.1", created.addonVersion());
assertEquals(catalogDefault("kube-proxy", "1.32"), created.addonVersion());
// Incompatible version (v1.16.0 only compatible with 1.28) is rejected
// Incompatible version (v1.14.0 only compatible with 1.28) is rejected
CreateAddonRequest reqIncompatible = new CreateAddonRequest(
"vpc-cni", "v1.16.0-eksbuild.1", null, null, null, null, null, null);
"vpc-cni", "v1.14.0-eksbuild.3", null, null, null, null, null, null);
AwsException ex = assertThrows(AwsException.class, () ->
fixture.service.create(fixture.cluster, reqIncompatible));
assertEquals("InvalidParameterException", ex.getErrorCode());
assertEquals(400, ex.getHttpStatus());
}
@Test
void everySupportedKubernetesVersionResolvesEveryAddonAndAcceptsItsOldestBuild() {
Fixture fixture = fixture();
for (String clusterVersion : catalogClusterVersions()) {
for (String addon : List.of("vpc-cni", "coredns", "kube-proxy", "eks-pod-identity-agent",
"aws-ebs-csi-driver", "amazon-cloudwatch-observability")) {
assertEquals(Optional.of(catalogDefault(addon, clusterVersion)),
fixture.catalog.resolveDefaultVersion(addon, clusterVersion), addon + " " + clusterVersion);
String oldest = catalogCompatible(addon, clusterVersion).getLast();
assertTrue(fixture.catalog.isVersionSupported(addon, oldest, clusterVersion), addon + " " + oldest);
}
}
// Infrastructure pins older builds, as paynet does on 1.34 with coredns v1.13.2-eksbuild.10.
fixture.cluster.setVersion("1.34");
String pinned = catalogCompatible("coredns", "1.34").getLast();
assertEquals(pinned, fixture.service.create(fixture.cluster, new CreateAddonRequest(
"coredns", pinned, null, null, null, null, null, null)).addonVersion());
}
@Test
void versionFilteredAnswerKeepsOnlyThatVersionsCompatibility() {
Fixture fixture = fixture();
AddonInfo coredns = fixture.service.describeAddonVersions(
"coredns", "1.34", null, null, null, null, null).addons().getFirst();
assertTrue(coredns.addonVersions().stream().flatMap(v -> v.compatibilities().stream())
.allMatch(c -> "1.34".equals(c.clusterVersion())));
// The first entry flagged default is 1.34's default, not a newer release that is 1.35's.
assertEquals(catalogDefault("coredns", "1.34"), coredns.addonVersions().stream()
.filter(v -> v.compatibilities().stream().anyMatch(c -> Boolean.TRUE.equals(c.defaultVersion())))
.findFirst().orElseThrow().addonVersion());
}
@Test
void describeAddonVersionsWithFilteringAndPagination() {
Fixture fixture = fixture();
@@ -572,17 +612,9 @@ class EksAddonServiceTest {
Fixture fixture = fixture();
// The default version resolves for each cluster version the catalog covers
Map<String, String> expectedDefaults = Map.of(
"1.28", "v1.26.1-eksbuild.1",
"1.29", "v1.28.0-eksbuild.1",
"1.30", "v1.31.0-eksbuild.1",
"1.31", "v1.35.0-eksbuild.1",
"1.32", "v1.38.1-eksbuild.1"
);
for (Map.Entry<String, String> entry : expectedDefaults.entrySet()) {
fixture.cluster.setVersion(entry.getKey());
assertEquals(Optional.of(entry.getValue()),
fixture.catalog.resolveDefaultVersion("aws-ebs-csi-driver", entry.getKey()));
for (String clusterVersion : catalogClusterVersions()) {
assertEquals(Optional.of(catalogDefault("aws-ebs-csi-driver", clusterVersion)),
fixture.catalog.resolveDefaultVersion("aws-ebs-csi-driver", clusterVersion), clusterVersion);
}
// CreateAddon for aws-ebs-csi-driver succeeds and DescribeAddon returns it
@@ -591,7 +623,7 @@ class EksAddonServiceTest {
"aws-ebs-csi-driver", null, ROLE, null, null, null, null, null);
Addon created = fixture.service.create(fixture.cluster, req);
assertEquals("aws-ebs-csi-driver", created.addonName());
assertEquals("v1.31.0-eksbuild.1", created.addonVersion());
assertEquals(catalogDefault("aws-ebs-csi-driver", "1.30"), created.addonVersion());
assertEquals("ACTIVE", created.status());
assertEquals("aws", created.owner());
assertEquals("eks", created.publisher());
@@ -608,14 +640,18 @@ class EksAddonServiceTest {
assertEquals("storage", addonInfo.type());
assertEquals("aws", addonInfo.owner());
assertEquals("eks", addonInfo.publisher());
assertEquals(5, addonInfo.addonVersions().size());
assertTrue(addonInfo.addonVersions().size() > 1);
// Filtering by addon name and cluster version works
EksAddonService.AddonVersionsPage byCluster = fixture.service.describeAddonVersions(
"aws-ebs-csi-driver", "1.32", null, null, null, null, null);
assertEquals(1, byCluster.addons().size());
assertEquals(1, byCluster.addons().getFirst().addonVersions().size());
assertEquals("v1.38.1-eksbuild.1", byCluster.addons().getFirst().addonVersions().getFirst().addonVersion());
List<AddonVersionInfo> for132 = byCluster.addons().getFirst().addonVersions();
assertTrue(for132.stream().allMatch(v -> v.compatibilities().stream()
.allMatch(c -> "1.32".equals(c.clusterVersion()))));
assertEquals(List.of(catalogDefault("aws-ebs-csi-driver", "1.32")), for132.stream()
.filter(v -> Boolean.TRUE.equals(v.compatibilities().getFirst().defaultVersion()))
.map(AddonVersionInfo::addonVersion).toList());
// The four existing addons are unchanged
for (String existing : List.of("vpc-cni", "coredns", "kube-proxy", "eks-pod-identity-agent")) {
@@ -634,6 +670,51 @@ class EksAddonServiceTest {
assertTrue(ex.getMessage().contains("unsupported-addon"));
}
// Expectations read the vendored catalog directly, so a regeneration does not rewrite these tests.
private static JsonNode catalogAddon(String addon) {
try (InputStream in = EksAddonServiceTest.class.getResourceAsStream("/eks/addon-versions.json")) {
for (JsonNode node : new ObjectMapper().readTree(in).path("addons")) {
if (addon.equals(node.path("addonName").asText())) {
return node;
}
}
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
throw new AssertionError("no " + addon + " in the vendored catalog");
}
private static List<String> catalogCompatible(String addon, String clusterVersion) {
List<String> versions = new ArrayList<>();
for (JsonNode version : catalogAddon(addon).path("addonVersions")) {
for (JsonNode compatibility : version.path("compatibilities")) {
if (clusterVersion.equals(compatibility.path("clusterVersion").asText())) {
versions.add(version.path("addonVersion").asText());
}
}
}
return versions;
}
static String catalogDefault(String addon, String clusterVersion) {
List<String> defaults = new ArrayList<>();
for (JsonNode version : catalogAddon(addon).path("addonVersions")) {
for (JsonNode compatibility : version.path("compatibilities")) {
if (clusterVersion.equals(compatibility.path("clusterVersion").asText())
&& compatibility.path("defaultVersion").asBoolean()) {
defaults.add(version.path("addonVersion").asText());
}
}
}
assertEquals(1, defaults.size(), addon + " defaults for " + clusterVersion);
return defaults.getFirst();
}
// Every version a cluster can run, so a version added to the k3s map without a catalog sync fails here.
private static Set<String> catalogClusterVersions() {
return new TreeSet<>(EksClusterManager.SUPPORTED_K8S_VERSIONS.keySet());
}
private static Fixture fixture() {
Cluster cluster = new Cluster();
cluster.setName("test-cluster");