mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(eks): implement cluster addon management (#4038)
* feat(eks): implement cluster addon management * fix(eks): address addon management review comments * fix(eks): handle uncataloged k8s versions and association validation ordering
This commit is contained in:
1 parent
49d28fb685
commit
6a3380d13a
22 files changed
+2357
-6
No files matched your search
@@ -22,6 +22,13 @@ EKS uses a standard REST API with JSON bodies: not the JSON 1.1 (`X-Amz-Target`)
|
||||
| `ListPodIdentityAssociations` | List pod identity associations in a cluster with optional filtering and pagination |
|
||||
| `UpdatePodIdentityAssociation` | Update the IAM role, target role, or session tags for a pod identity association |
|
||||
| `DeletePodIdentityAssociation` | Delete a pod identity association |
|
||||
| `CreateAddon` | Create an addon for an EKS cluster |
|
||||
| `DescribeAddon` | Describe an addon by cluster and addon name |
|
||||
| `ListAddons` | List addon names installed in a cluster with pagination |
|
||||
| `UpdateAddon` | Update addon configuration, version, or service account role |
|
||||
| `DescribeUpdate` | Describe an update for an addon |
|
||||
| `DeleteAddon` | Delete an addon from a cluster |
|
||||
| `DescribeAddonVersions` | Describe supported addon versions by Kubernetes version or addon name |
|
||||
| `CreateNodegroup` | Create node group metadata for a cluster |
|
||||
| `DescribeNodegroup` | Describe a node group by cluster and name |
|
||||
| `ListNodegroups` | List node group names for a cluster |
|
||||
@@ -92,6 +99,24 @@ Credentials delivery directly into pods is not yet supported:
|
||||
|
||||
Applications running inside pods cannot currently exchange tokens for temporary AWS credentials via the link-local endpoint. Use access entries, node credentials, or explicit credential configuration until the pod identity agent endpoint is added.
|
||||
|
||||
## Addon management
|
||||
|
||||
Floci supports the EKS cluster addon management plane for AWS SDKs and Terraform (`aws_eks_addon` resource).
|
||||
|
||||
### Supported operations
|
||||
|
||||
- **Creation**: `CreateAddon` creates an addon on an ACTIVE cluster. Supported addons include `vpc-cni`, `coredns`, `kube-proxy`, and `eks-pod-identity-agent`. If `addonVersion` is omitted, the default version compatible with the cluster Kubernetes version is resolved automatically. Referenced `serviceAccountRoleArn` must exist in IAM. Idempotency is supported via `clientRequestToken`.
|
||||
- **Retrieval**: `DescribeAddon` returns the complete addon resource shape, including ARN, cluster name, version, status (`ACTIVE`), health issues, tags, service account role ARN, configuration values, pod identity associations, owner, and publisher.
|
||||
- **Listing**: `ListAddons` lists installed addon names with pagination (`maxResults` and `nextToken`).
|
||||
- **Updating**: `UpdateAddon` updates the addon version, configuration values, service account role ARN, or resolve-conflicts strategy. It returns an `Update` tracking object and updates the addon metadata.
|
||||
- **Update tracking**: `DescribeUpdate` describes the status of an addon update (such as an in-place addon version update queried by Terraform).
|
||||
- **Deletion**: `DeleteAddon` marks the addon as `DELETING` and removes it from the cluster. Deleting a cluster automatically cleans up all associated addons.
|
||||
- **Supported versions**: `DescribeAddonVersions` queries the addon version catalog with optional filtering by `addonName` and `kubernetesVersion`, supporting pagination.
|
||||
|
||||
### Metadata recording only
|
||||
|
||||
Addons in Floci are recorded metadata only. Creating or updating an addon does not install or reconcile Kubernetes DaemonSets, Deployments, or custom resources inside the cluster container.
|
||||
|
||||
## Cluster security group
|
||||
|
||||
When an EKS cluster is created with a VPC (either specified directly or resolved from subnets), Floci provisions a dedicated EC2 cluster security group and populates its ID in `cluster.resourcesVpcConfig.clusterSecurityGroupId` on both `CreateCluster` and `DescribeCluster` responses.
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
package io.github.hectorvent.floci.services.eks;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.services.eks.model.AddonInfo;
|
||||
import io.github.hectorvent.floci.services.eks.model.AddonVersionInfo;
|
||||
import io.github.hectorvent.floci.services.eks.model.Compatibility;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@ApplicationScoped
|
||||
public class EksAddonCatalog {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(EksAddonCatalog.class);
|
||||
private static final String CATALOG_RESOURCE_NAME = "eks/addon-versions.json";
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private volatile List<AddonInfo> addons;
|
||||
|
||||
public EksAddonCatalog() {
|
||||
// Loaded lazily on first access.
|
||||
}
|
||||
|
||||
public EksAddonCatalog(List<AddonInfo> addons) {
|
||||
this.addons = addons != null ? List.copyOf(addons) : List.of();
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
record CatalogWrapper(List<AddonInfo> addons) {}
|
||||
|
||||
private List<AddonInfo> getAddons() {
|
||||
if (addons == null) {
|
||||
synchronized (this) {
|
||||
if (addons == null) {
|
||||
addons = loadCatalog();
|
||||
}
|
||||
}
|
||||
}
|
||||
return addons;
|
||||
}
|
||||
|
||||
private List<AddonInfo> loadCatalog() {
|
||||
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(CATALOG_RESOURCE_NAME)) {
|
||||
if (is == null) {
|
||||
LOG.warnv("EKS addon versions catalog resource not found: {0}", CATALOG_RESOURCE_NAME);
|
||||
return List.of();
|
||||
}
|
||||
CatalogWrapper wrapper = MAPPER.readValue(is, CatalogWrapper.class);
|
||||
return wrapper.addons() != null ? List.copyOf(wrapper.addons()) : List.of();
|
||||
} catch (IOException e) {
|
||||
LOG.errorv(e, "Failed to load EKS addon versions catalog from {0}", CATALOG_RESOURCE_NAME);
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
public List<AddonInfo> allAddons() {
|
||||
return getAddons();
|
||||
}
|
||||
|
||||
public Optional<AddonInfo> findAddon(String addonName) {
|
||||
if (addonName == null || addonName.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String normalized = addonName.trim();
|
||||
return getAddons().stream()
|
||||
.filter(a -> a.addonName().equalsIgnoreCase(normalized))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public boolean isKnownAddon(String addonName) {
|
||||
return findAddon(addonName).isPresent();
|
||||
}
|
||||
|
||||
public boolean isClusterVersionInCatalog(String kubernetesVersion) {
|
||||
if (kubernetesVersion == null || kubernetesVersion.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
String k8s = normalizeK8sVersion(kubernetesVersion);
|
||||
return getAddons().stream()
|
||||
.flatMap(a -> a.addonVersions().stream())
|
||||
.filter(v -> v.compatibilities() != null)
|
||||
.flatMap(v -> v.compatibilities().stream())
|
||||
.anyMatch(c -> k8s.equals(c.clusterVersion()));
|
||||
}
|
||||
|
||||
public boolean isVersionSupported(String addonName, String addonVersion) {
|
||||
return isVersionSupported(addonName, addonVersion, null);
|
||||
}
|
||||
|
||||
public boolean isVersionSupported(String addonName, String addonVersion, String kubernetesVersion) {
|
||||
if (addonName == null || addonName.isBlank() || addonVersion == null || addonVersion.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
String k8s = kubernetesVersion != null && isClusterVersionInCatalog(kubernetesVersion)
|
||||
? normalizeK8sVersion(kubernetesVersion) : null;
|
||||
return findAddon(addonName)
|
||||
.map(AddonInfo::addonVersions)
|
||||
.orElse(List.of())
|
||||
.stream()
|
||||
.filter(v -> v.addonVersion().equalsIgnoreCase(addonVersion.trim()))
|
||||
.anyMatch(v -> k8s == null || isCompatible(v, k8s, false));
|
||||
}
|
||||
|
||||
public Optional<String> resolveDefaultVersion(String addonName, String kubernetesVersion) {
|
||||
List<AddonVersionInfo> versions = findAddon(addonName)
|
||||
.map(AddonInfo::addonVersions)
|
||||
.orElse(List.of());
|
||||
if (versions.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
String k8s = kubernetesVersion != null && !kubernetesVersion.isBlank()
|
||||
? normalizeK8sVersion(kubernetesVersion) : null;
|
||||
if (k8s != null) {
|
||||
Optional<String> def = versions.stream()
|
||||
.filter(v -> isCompatible(v, k8s, true))
|
||||
.map(AddonVersionInfo::addonVersion)
|
||||
.findFirst();
|
||||
if (def.isPresent()) {
|
||||
return def;
|
||||
}
|
||||
Optional<String> any = versions.stream()
|
||||
.filter(v -> isCompatible(v, k8s, false))
|
||||
.map(AddonVersionInfo::addonVersion)
|
||||
.findFirst();
|
||||
if (any.isPresent()) {
|
||||
return any;
|
||||
}
|
||||
}
|
||||
|
||||
return versions.stream()
|
||||
.filter(v -> isCompatible(v, null, true))
|
||||
.map(AddonVersionInfo::addonVersion)
|
||||
.findFirst()
|
||||
.or(() -> Optional.of(versions.getFirst().addonVersion()));
|
||||
}
|
||||
|
||||
public List<AddonInfo> describeVersions(String addonName, String kubernetesVersion,
|
||||
List<String> publishers, List<String> types, List<String> owners) {
|
||||
String k8s = kubernetesVersion != null && !kubernetesVersion.isBlank()
|
||||
? normalizeK8sVersion(kubernetesVersion) : null;
|
||||
return getAddons().stream()
|
||||
.filter(a -> addonName == null || addonName.isBlank() || a.addonName().equalsIgnoreCase(addonName.trim()))
|
||||
.filter(a -> publishers == null || publishers.isEmpty() || publishers.contains(a.publisher()))
|
||||
.filter(a -> types == null || types.isEmpty() || types.contains(a.type()))
|
||||
.filter(a -> owners == null || owners.isEmpty() || owners.contains(a.owner()))
|
||||
.map(a -> k8s == null ? a : filterByK8s(a, k8s))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static AddonInfo filterByK8s(AddonInfo addon, String k8s) {
|
||||
List<AddonVersionInfo> filtered = addon.addonVersions().stream()
|
||||
.filter(v -> isCompatible(v, k8s, false))
|
||||
.toList();
|
||||
return filtered.isEmpty() ? null
|
||||
: new AddonInfo(addon.addonName(), addon.type(), filtered, addon.publisher(), addon.owner());
|
||||
}
|
||||
|
||||
private static boolean isCompatible(AddonVersionInfo versionInfo, String k8s, boolean defaultOnly) {
|
||||
if (versionInfo.compatibilities() == null) {
|
||||
return false;
|
||||
}
|
||||
return versionInfo.compatibilities().stream().anyMatch(c ->
|
||||
(!defaultOnly || Boolean.TRUE.equals(c.defaultVersion()))
|
||||
&& (k8s == null || k8s.equals(c.clusterVersion())));
|
||||
}
|
||||
|
||||
private static String normalizeK8sVersion(String version) {
|
||||
if (version == null) {
|
||||
return "";
|
||||
}
|
||||
String v = version.trim();
|
||||
if (v.startsWith("v")) {
|
||||
v = v.substring(1);
|
||||
}
|
||||
String[] parts = v.split("\\.");
|
||||
return parts.length >= 2 ? parts[0] + "." + parts[1] : v;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,528 @@
|
||||
package io.github.hectorvent.floci.services.eks;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.eks.model.Addon;
|
||||
import io.github.hectorvent.floci.services.eks.model.AddonHealth;
|
||||
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.Cluster;
|
||||
import io.github.hectorvent.floci.services.eks.model.ClusterStatus;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateAddonRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreatePodIdentityAssociationRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.PodIdentityAssociation;
|
||||
import io.github.hectorvent.floci.services.eks.model.Update;
|
||||
import io.github.hectorvent.floci.services.eks.model.UpdateAddonRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.UpdateParam;
|
||||
import io.github.hectorvent.floci.services.iam.IamService;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ApplicationScoped
|
||||
public class EksAddonService {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(EksAddonService.class);
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
private static final int DEFAULT_PAGE_SIZE = 100;
|
||||
private static final int MAX_PAGE_SIZE = 100;
|
||||
|
||||
private final StorageBackend<String, StoredAddon> storage;
|
||||
private final StorageBackend<String, StoredUpdate> updatesStorage;
|
||||
private final EksAddonCatalog catalog;
|
||||
private final IamService iam;
|
||||
private final EksPodIdentityAssociationService podIdentityAssociations;
|
||||
|
||||
@Inject
|
||||
public EksAddonService(StorageFactory storageFactory, EksAddonCatalog catalog,
|
||||
IamService iam, EksPodIdentityAssociationService podIdentityAssociations) {
|
||||
this(storageFactory.create("eks", "eks-addons.json",
|
||||
new TypeReference<Map<String, StoredAddon>>() {}),
|
||||
storageFactory.create("eks", "eks-updates.json",
|
||||
new TypeReference<Map<String, StoredUpdate>>() {}),
|
||||
catalog, iam, podIdentityAssociations);
|
||||
}
|
||||
|
||||
EksAddonService(StorageBackend<String, StoredAddon> storage,
|
||||
StorageBackend<String, StoredUpdate> updatesStorage,
|
||||
EksAddonCatalog catalog,
|
||||
IamService iam,
|
||||
EksPodIdentityAssociationService podIdentityAssociations) {
|
||||
this.storage = storage;
|
||||
this.updatesStorage = updatesStorage;
|
||||
this.catalog = catalog;
|
||||
this.iam = iam;
|
||||
this.podIdentityAssociations = podIdentityAssociations;
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
public record StoredAddon(Addon addon, String clientRequestToken) {}
|
||||
|
||||
@RegisterForReflection
|
||||
public record StoredUpdate(Update update, String addonName) {}
|
||||
|
||||
@RegisterForReflection
|
||||
public record AddonNamesPage(List<String> addons, String nextToken) {}
|
||||
|
||||
@RegisterForReflection
|
||||
public record AddonVersionsPage(List<AddonInfo> addons, String nextToken) {}
|
||||
|
||||
public synchronized Addon create(Cluster cluster, CreateAddonRequest request) {
|
||||
requireActiveCluster(cluster);
|
||||
if (request == null || request.addonName() == null || request.addonName().isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "addonName is required", 400);
|
||||
}
|
||||
|
||||
String addonName = request.addonName().trim();
|
||||
if (!catalog.isKnownAddon(addonName)) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Addon name '" + addonName + "' is not valid", 400);
|
||||
}
|
||||
|
||||
String storageKey = prefix(cluster) + addonName.toLowerCase(Locale.ROOT);
|
||||
Optional<StoredAddon> existing = storage.get(storageKey);
|
||||
if (existing.isPresent()) {
|
||||
StoredAddon stored = existing.get();
|
||||
if (request.clientRequestToken() != null && !request.clientRequestToken().isBlank()
|
||||
&& request.clientRequestToken().equals(stored.clientRequestToken())) {
|
||||
if (parametersMatch(stored.addon(), request)) {
|
||||
return stored.addon();
|
||||
}
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"clientRequestToken was already used with different parameters", 400);
|
||||
}
|
||||
throw new AwsException("ResourceInUseException", "Addon already exists: " + addonName, 409);
|
||||
}
|
||||
|
||||
String version = (request.addonVersion() != null && !request.addonVersion().isBlank())
|
||||
? request.addonVersion().trim()
|
||||
: catalog.resolveDefaultVersion(addonName, cluster.getVersion()).orElse(null);
|
||||
if (version == null || !catalog.isVersionSupported(addonName, version, cluster.getVersion())) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Addon version specified is not supported", 400);
|
||||
}
|
||||
|
||||
if (request.serviceAccountRoleArn() != null && !request.serviceAccountRoleArn().isBlank()) {
|
||||
validateRoleArn(cluster, request.serviceAccountRoleArn(), "serviceAccountRoleArn");
|
||||
}
|
||||
|
||||
if (request.resolveConflicts() != null && !request.resolveConflicts().isBlank()) {
|
||||
validateResolveConflicts(request.resolveConflicts());
|
||||
}
|
||||
|
||||
Map<String, String> tags = request.tags() != null ? request.tags() : Map.of();
|
||||
validateTags(tags);
|
||||
|
||||
List<String> associationArns = createOrLinkPodIdentityAssociations(cluster, addonName, request.podIdentityAssociations());
|
||||
|
||||
double now = Instant.now().toEpochMilli() / 1000.0;
|
||||
String addonArn = generateAddonArn(cluster, addonName);
|
||||
Optional<AddonInfo> addonInfo = catalog.findAddon(addonName);
|
||||
String owner = addonInfo.map(AddonInfo::owner).orElse("aws");
|
||||
String publisher = addonInfo.map(AddonInfo::publisher).orElse("eks");
|
||||
|
||||
Addon addon = new Addon(
|
||||
addonArn,
|
||||
addonName,
|
||||
version,
|
||||
cluster.getName(),
|
||||
"ACTIVE",
|
||||
new AddonHealth(List.of()),
|
||||
now,
|
||||
now,
|
||||
request.serviceAccountRoleArn(),
|
||||
request.configurationValues(),
|
||||
Map.copyOf(tags),
|
||||
List.copyOf(associationArns),
|
||||
owner,
|
||||
publisher
|
||||
);
|
||||
|
||||
storage.put(storageKey, new StoredAddon(addon, request.clientRequestToken()));
|
||||
LOG.infov("Created EKS addon {0} on cluster {1} with version {2}", addonName, cluster.getName(), version);
|
||||
return addon;
|
||||
}
|
||||
|
||||
public Addon describe(Cluster cluster, String addonName) {
|
||||
requireActiveCluster(cluster);
|
||||
if (addonName == null || addonName.isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "addonName is required", 400);
|
||||
}
|
||||
|
||||
String storageKey = prefix(cluster) + addonName.trim().toLowerCase(Locale.ROOT);
|
||||
StoredAddon stored = storage.get(storageKey)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"No addon: " + addonName + " found for cluster: " + cluster.getName(), 404));
|
||||
return stored.addon();
|
||||
}
|
||||
|
||||
public AddonNamesPage list(Cluster cluster, Integer maxResults, String nextToken) {
|
||||
requireActiveCluster(cluster);
|
||||
String p = prefix(cluster);
|
||||
List<String> addonNames = storage.scan(key -> key.startsWith(p)).stream()
|
||||
.map(stored -> stored.addon().addonName())
|
||||
.sorted()
|
||||
.toList();
|
||||
|
||||
PaginatedResult<String> result = Pagination.paginate(
|
||||
addonNames,
|
||||
Function.identity(),
|
||||
maxResults,
|
||||
nextToken,
|
||||
DEFAULT_PAGE_SIZE,
|
||||
MAX_PAGE_SIZE,
|
||||
"InvalidParameterException"
|
||||
);
|
||||
return new AddonNamesPage(result.items(), result.nextToken());
|
||||
}
|
||||
|
||||
public synchronized Update update(Cluster cluster, String addonName, UpdateAddonRequest request) {
|
||||
requireActiveCluster(cluster);
|
||||
if (addonName == null || addonName.isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "addonName is required", 400);
|
||||
}
|
||||
|
||||
String storageKey = prefix(cluster) + addonName.trim().toLowerCase(Locale.ROOT);
|
||||
StoredAddon stored = storage.get(storageKey)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"No addon: " + addonName + " found for cluster: " + cluster.getName(), 404));
|
||||
|
||||
Addon current = stored.addon();
|
||||
String newVersion = current.addonVersion();
|
||||
List<UpdateParam> params = new ArrayList<>();
|
||||
|
||||
if (request != null) {
|
||||
if (request.addonVersion() != null && !request.addonVersion().isBlank()) {
|
||||
String requestedVersion = request.addonVersion().trim();
|
||||
if (!catalog.isVersionSupported(addonName, requestedVersion, cluster.getVersion())) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Addon version specified is not supported", 400);
|
||||
}
|
||||
newVersion = requestedVersion;
|
||||
params.add(new UpdateParam("Version", newVersion));
|
||||
}
|
||||
|
||||
if (request.serviceAccountRoleArn() != null) {
|
||||
if (!request.serviceAccountRoleArn().isBlank()) {
|
||||
validateRoleArn(cluster, request.serviceAccountRoleArn(), "serviceAccountRoleArn");
|
||||
}
|
||||
params.add(new UpdateParam("ServiceAccountRoleArn", request.serviceAccountRoleArn()));
|
||||
}
|
||||
|
||||
if (request.resolveConflicts() != null && !request.resolveConflicts().isBlank()) {
|
||||
validateResolveConflicts(request.resolveConflicts());
|
||||
params.add(new UpdateParam("ResolveConflicts", request.resolveConflicts()));
|
||||
}
|
||||
|
||||
if (request.configurationValues() != null) {
|
||||
params.add(new UpdateParam("ConfigurationValues", request.configurationValues()));
|
||||
}
|
||||
}
|
||||
|
||||
String updatedRoleArn = request != null && request.serviceAccountRoleArn() != null
|
||||
? (request.serviceAccountRoleArn().isBlank() ? null : request.serviceAccountRoleArn())
|
||||
: current.serviceAccountRoleArn();
|
||||
String updatedConfig = request != null && request.configurationValues() != null
|
||||
? request.configurationValues()
|
||||
: current.configurationValues();
|
||||
|
||||
List<String> updatedAssociations = current.podIdentityAssociations();
|
||||
if (request != null && request.podIdentityAssociations() != null) {
|
||||
validatePodIdentityAssociations(cluster, request.podIdentityAssociations());
|
||||
if (podIdentityAssociations != null && current.podIdentityAssociations() != null) {
|
||||
for (String arn : current.podIdentityAssociations()) {
|
||||
deleteAssociationSilently(cluster, arn);
|
||||
}
|
||||
}
|
||||
updatedAssociations = createOrLinkPodIdentityAssociations(cluster, addonName, request.podIdentityAssociations());
|
||||
params.add(new UpdateParam("PodIdentityAssociations", serializeAssociations(request.podIdentityAssociations())));
|
||||
}
|
||||
|
||||
double now = Instant.now().toEpochMilli() / 1000.0;
|
||||
Addon updatedAddon = new Addon(
|
||||
current.addonArn(),
|
||||
current.addonName(),
|
||||
newVersion,
|
||||
current.clusterName(),
|
||||
"ACTIVE",
|
||||
current.health(),
|
||||
current.createdAt(),
|
||||
now,
|
||||
updatedRoleArn,
|
||||
updatedConfig,
|
||||
current.tags(),
|
||||
updatedAssociations,
|
||||
current.owner(),
|
||||
current.publisher()
|
||||
);
|
||||
|
||||
String token = request != null && request.clientRequestToken() != null
|
||||
? request.clientRequestToken() : stored.clientRequestToken();
|
||||
storage.put(storageKey, new StoredAddon(updatedAddon, token));
|
||||
LOG.infov("Updated EKS addon {0} on cluster {1}", addonName, cluster.getName());
|
||||
|
||||
Update update = new Update(
|
||||
UUID.randomUUID().toString(),
|
||||
"Successful",
|
||||
"AddonUpdate",
|
||||
params,
|
||||
now,
|
||||
List.of()
|
||||
);
|
||||
updatesStorage.put(prefix(cluster) + update.id(), new StoredUpdate(update, addonName));
|
||||
return update;
|
||||
}
|
||||
|
||||
public synchronized Addon delete(Cluster cluster, String addonName, boolean preserve) {
|
||||
requireActiveCluster(cluster);
|
||||
if (addonName == null || addonName.isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "addonName is required", 400);
|
||||
}
|
||||
|
||||
String storageKey = prefix(cluster) + addonName.trim().toLowerCase(Locale.ROOT);
|
||||
StoredAddon stored = storage.get(storageKey)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"No addon: " + addonName + " found for cluster: " + cluster.getName(), 404));
|
||||
|
||||
storage.delete(storageKey);
|
||||
if (preserve) {
|
||||
LOG.infov("Deleted EKS addon {0} on cluster {1} (preserve=true)", addonName, cluster.getName());
|
||||
} else {
|
||||
if (podIdentityAssociations != null && stored.addon().podIdentityAssociations() != null) {
|
||||
for (String arn : stored.addon().podIdentityAssociations()) {
|
||||
deleteAssociationSilently(cluster, arn);
|
||||
}
|
||||
}
|
||||
LOG.infov("Deleted EKS addon {0} on cluster {1} (preserve=false)", addonName, cluster.getName());
|
||||
}
|
||||
|
||||
Addon current = stored.addon();
|
||||
return new Addon(
|
||||
current.addonArn(),
|
||||
current.addonName(),
|
||||
current.addonVersion(),
|
||||
current.clusterName(),
|
||||
"DELETING",
|
||||
current.health(),
|
||||
current.createdAt(),
|
||||
Instant.now().toEpochMilli() / 1000.0,
|
||||
current.serviceAccountRoleArn(),
|
||||
current.configurationValues(),
|
||||
current.tags(),
|
||||
current.podIdentityAssociations(),
|
||||
current.owner(),
|
||||
current.publisher()
|
||||
);
|
||||
}
|
||||
|
||||
public synchronized void deleteClusterAddons(Cluster cluster) {
|
||||
if (cluster != null) {
|
||||
String p = prefix(cluster);
|
||||
storage.keys().stream().filter(k -> k.startsWith(p)).toList().forEach(storage::delete);
|
||||
updatesStorage.keys().stream().filter(k -> k.startsWith(p)).toList().forEach(updatesStorage::delete);
|
||||
LOG.infov("Purged all addons and updates for cluster {0}", cluster.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public Update describeUpdate(Cluster cluster, String updateId, String addonName) {
|
||||
requireActiveCluster(cluster);
|
||||
if (updateId == null || updateId.isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", "updateId is required", 400);
|
||||
}
|
||||
StoredUpdate stored = updatesStorage.get(prefix(cluster) + updateId)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"No update: " + updateId + " found for cluster: " + cluster.getName(), 404));
|
||||
if (addonName != null && !addonName.isBlank()
|
||||
&& stored.addonName() != null && !stored.addonName().equalsIgnoreCase(addonName.trim())) {
|
||||
throw new AwsException("ResourceNotFoundException",
|
||||
"No update: " + updateId + " found for addon: " + addonName, 404);
|
||||
}
|
||||
return stored.update();
|
||||
}
|
||||
|
||||
public AddonVersionsPage describeAddonVersions(String addonName, String kubernetesVersion,
|
||||
Integer maxResults, String nextToken,
|
||||
List<String> publishers, List<String> types, List<String> owners) {
|
||||
List<AddonInfo> filtered = catalog.describeVersions(addonName, kubernetesVersion, publishers, types, owners);
|
||||
PaginatedResult<AddonInfo> result = Pagination.paginate(
|
||||
filtered,
|
||||
AddonInfo::addonName,
|
||||
maxResults,
|
||||
nextToken,
|
||||
DEFAULT_PAGE_SIZE,
|
||||
MAX_PAGE_SIZE,
|
||||
"InvalidParameterException"
|
||||
);
|
||||
return new AddonVersionsPage(result.items(), result.nextToken());
|
||||
}
|
||||
|
||||
private void validatePodIdentityAssociations(Cluster cluster, List<AddonPodIdentityAssociation> associations) {
|
||||
if (associations == null || associations.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (AddonPodIdentityAssociation assoc : associations) {
|
||||
if (assoc.roleArn() == null || assoc.roleArn().isBlank()
|
||||
|| assoc.serviceAccount() == null || assoc.serviceAccount().isBlank()) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"roleArn and serviceAccount are required for podIdentityAssociations", 400);
|
||||
}
|
||||
validateRoleArn(cluster, assoc.roleArn(), "roleArn");
|
||||
}
|
||||
}
|
||||
|
||||
private static String serializeAssociations(List<AddonPodIdentityAssociation> associations) {
|
||||
if (associations == null) {
|
||||
return "[]";
|
||||
}
|
||||
try {
|
||||
return MAPPER.writeValueAsString(associations);
|
||||
} catch (JsonProcessingException e) {
|
||||
return "[]";
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> createOrLinkPodIdentityAssociations(Cluster cluster,
|
||||
String addonName,
|
||||
List<AddonPodIdentityAssociation> associations) {
|
||||
if (associations == null || associations.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
validatePodIdentityAssociations(cluster, associations);
|
||||
List<String> arns = new ArrayList<>();
|
||||
String namespace = resolveAddonNamespace(addonName);
|
||||
for (AddonPodIdentityAssociation assoc : associations) {
|
||||
if (podIdentityAssociations != null) {
|
||||
CreatePodIdentityAssociationRequest req = new CreatePodIdentityAssociationRequest(
|
||||
cluster.getName(),
|
||||
namespace,
|
||||
assoc.serviceAccount(),
|
||||
assoc.roleArn(),
|
||||
null,
|
||||
Map.of(),
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
PodIdentityAssociation created = podIdentityAssociations.create(cluster, req);
|
||||
arns.add(created.associationArn());
|
||||
} else {
|
||||
String[] clusterArn = cluster.getArn().split(":", 6);
|
||||
String assocId = "a-" + UUID.randomUUID().toString().replace("-", "").substring(0, 17);
|
||||
String arn = "arn:" + clusterArn[1] + ":eks:" + clusterArn[3] + ":"
|
||||
+ clusterArn[4] + ":podidentityassociation/" + cluster.getName() + "/" + assocId;
|
||||
arns.add(arn);
|
||||
}
|
||||
}
|
||||
return arns;
|
||||
}
|
||||
|
||||
private void deleteAssociationSilently(Cluster cluster, String associationArn) {
|
||||
if (associationArn == null || associationArn.isBlank() || podIdentityAssociations == null) {
|
||||
return;
|
||||
}
|
||||
String associationId = associationArn.substring(associationArn.lastIndexOf('/') + 1);
|
||||
try {
|
||||
podIdentityAssociations.delete(cluster, associationId);
|
||||
} catch (AwsException e) {
|
||||
LOG.debugf("Ignored error deleting pod identity association %s: %s", associationId, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static String resolveAddonNamespace(String addonName) {
|
||||
return "kube-system";
|
||||
}
|
||||
|
||||
private static String prefix(Cluster cluster) {
|
||||
return cluster.getArn() + "/" + Objects.toString(cluster.getCreatedAt()) + "/";
|
||||
}
|
||||
|
||||
private static String generateAddonArn(Cluster cluster, String addonName) {
|
||||
String[] clusterArn = cluster.getArn().split(":", 6);
|
||||
return "arn:" + clusterArn[1] + ":eks:" + clusterArn[3] + ":"
|
||||
+ clusterArn[4] + ":addon/" + cluster.getName() + "/" + addonName + "/" + UUID.randomUUID();
|
||||
}
|
||||
|
||||
private static void requireActiveCluster(Cluster cluster) {
|
||||
if (cluster == null) {
|
||||
throw new AwsException("ResourceNotFoundException", "Cluster not found", 404);
|
||||
}
|
||||
if (cluster.getStatus() != ClusterStatus.ACTIVE) {
|
||||
throw new AwsException("InvalidRequestException",
|
||||
"Cluster must be ACTIVE, but was " + cluster.getStatus(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateRoleArn(Cluster cluster, String roleArn, String fieldName) {
|
||||
if (roleArn == null || roleArn.isBlank()) {
|
||||
throw new AwsException("InvalidParameterException", fieldName + " is required", 400);
|
||||
}
|
||||
String[] arn = roleArn.split(":", 6);
|
||||
String[] clusterArn = cluster.getArn().split(":", 6);
|
||||
if (arn.length != 6 || !"arn".equals(arn[0]) || !arn[1].equals(clusterArn[1])
|
||||
|| !"iam".equals(arn[2]) || !arn[3].isEmpty() || !arn[4].matches("[0-9]{12}")
|
||||
|| !arn[5].startsWith("role/") || arn[5].startsWith("role/aws-service-role/")
|
||||
|| roleArn.endsWith("/")) {
|
||||
throw new AwsException("InvalidParameterException", fieldName + " must identify an IAM role", 400);
|
||||
}
|
||||
if (iam != null) {
|
||||
String roleName = roleArn.substring(roleArn.lastIndexOf('/') + 1);
|
||||
iam.findRole(arn[4], roleName)
|
||||
.filter(role -> roleArn.equals(role.getArn()))
|
||||
.orElseThrow(() -> new AwsException("InvalidParameterException", "Role not found: " + roleArn, 400));
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateResolveConflicts(String resolveConflicts) {
|
||||
String upper = resolveConflicts.toUpperCase(Locale.ROOT);
|
||||
if (!"OVERWRITE".equals(upper) && !"NONE".equals(upper) && !"PRESERVE".equals(upper)) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Unsupported resolveConflicts value: " + resolveConflicts, 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateTags(Map<String, String> tags) {
|
||||
if (tags == null) {
|
||||
return;
|
||||
}
|
||||
if (tags.size() > 50) {
|
||||
throw new AwsException("InvalidParameterException", "Too many tags: maximum is 50", 400);
|
||||
}
|
||||
for (Map.Entry<String, String> entry : tags.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
if (key == null || key.isBlank() || key.length() > 128) {
|
||||
throw new AwsException("InvalidParameterException", "Invalid tag key: " + key, 400);
|
||||
}
|
||||
if (value == null || value.length() > 256) {
|
||||
throw new AwsException("InvalidParameterException", "Invalid tag value: " + value, 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean parametersMatch(Addon existing, CreateAddonRequest request) {
|
||||
Map<String, String> existingTags = existing.tags() != null ? existing.tags() : Map.of();
|
||||
Map<String, String> requestTags = request.tags() != null ? request.tags() : Map.of();
|
||||
return Objects.equals(existing.serviceAccountRoleArn(), request.serviceAccountRoleArn())
|
||||
&& Objects.equals(existing.configurationValues(), request.configurationValues())
|
||||
&& (request.addonVersion() == null || request.addonVersion().isBlank()
|
||||
|| Objects.equals(existing.addonVersion(), request.addonVersion()))
|
||||
&& Objects.equals(existingTags, requestTags);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package io.github.hectorvent.floci.services.eks;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.services.eks.model.Addon;
|
||||
import io.github.hectorvent.floci.services.eks.model.Cluster;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateAccessEntryRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateAddonRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateClusterRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateFargateProfileRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateNodeGroupRequest;
|
||||
@@ -10,6 +12,8 @@ import io.github.hectorvent.floci.services.eks.model.CreatePodIdentityAssociatio
|
||||
import io.github.hectorvent.floci.services.eks.model.FargateProfile;
|
||||
import io.github.hectorvent.floci.services.eks.model.Nodegroup;
|
||||
import io.github.hectorvent.floci.services.eks.model.PodIdentityAssociation;
|
||||
import io.github.hectorvent.floci.services.eks.model.Update;
|
||||
import io.github.hectorvent.floci.services.eks.model.UpdateAddonRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.UpdatePodIdentityAssociationRequest;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
@@ -41,13 +45,16 @@ public class EksController {
|
||||
private final EksService eksService;
|
||||
private final EksAccessEntryService accessEntries;
|
||||
private final EksPodIdentityAssociationService podIdentityAssociations;
|
||||
private final EksAddonService addons;
|
||||
|
||||
@Inject
|
||||
public EksController(EksService eksService, EksAccessEntryService accessEntries,
|
||||
EksPodIdentityAssociationService podIdentityAssociations) {
|
||||
EksPodIdentityAssociationService podIdentityAssociations,
|
||||
EksAddonService addons) {
|
||||
this.eksService = eksService;
|
||||
this.accessEntries = accessEntries;
|
||||
this.podIdentityAssociations = podIdentityAssociations;
|
||||
this.addons = addons;
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -175,11 +182,88 @@ public class EksController {
|
||||
return Response.ok(Map.of()).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/clusters/{name}/addons")
|
||||
public Response createAddon(@PathParam("name") String name, CreateAddonRequest request) {
|
||||
Cluster cluster = eksService.describeCluster(name);
|
||||
Addon addon = addons.create(cluster, request);
|
||||
return Response.ok(Map.of("addon", addon)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/addons")
|
||||
public Response listAddons(@PathParam("name") String name) {
|
||||
eksService.describeCluster(name);
|
||||
return Response.ok(Map.of("addons", List.of())).build();
|
||||
public Response listAddons(@PathParam("name") String name,
|
||||
@QueryParam("maxResults") String maxResults,
|
||||
@QueryParam("nextToken") String nextToken) {
|
||||
Cluster cluster = eksService.describeCluster(name);
|
||||
EksAddonService.AddonNamesPage page = addons.list(cluster,
|
||||
Pagination.parseMaxResults(maxResults, "InvalidParameterException"), nextToken);
|
||||
return Response.ok(page.nextToken() == null
|
||||
? Map.of("addons", page.addons())
|
||||
: Map.of("addons", page.addons(), "nextToken", page.nextToken())).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/addons/{addonName}")
|
||||
public Response describeAddon(@PathParam("name") String name,
|
||||
@PathParam("addonName") String addonName) {
|
||||
Cluster cluster = eksService.describeCluster(name);
|
||||
Addon addon = addons.describe(cluster, addonName);
|
||||
return Response.ok(Map.of("addon", addon)).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/clusters/{name}/addons/{addonName}/update")
|
||||
public Response updateAddon(@PathParam("name") String name,
|
||||
@PathParam("addonName") String addonName,
|
||||
UpdateAddonRequest request) {
|
||||
Cluster cluster = eksService.describeCluster(name);
|
||||
Update update = addons.update(cluster, addonName, request);
|
||||
return Response.ok(Map.of("update", update)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/updates/{updateId}")
|
||||
public Response describeUpdate(@PathParam("name") String name,
|
||||
@PathParam("updateId") String updateId,
|
||||
@QueryParam("addonName") String addonName,
|
||||
@QueryParam("nodegroupName") String nodegroupName) {
|
||||
Cluster cluster = eksService.describeCluster(name);
|
||||
Update update = addons.describeUpdate(cluster, updateId, addonName);
|
||||
return Response.ok(Map.of("update", update)).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/clusters/{name}/addons/{addonName}")
|
||||
public Response deleteAddon(@PathParam("name") String name,
|
||||
@PathParam("addonName") String addonName,
|
||||
@QueryParam("preserve") Boolean preserve) {
|
||||
Cluster cluster = eksService.describeCluster(name);
|
||||
Addon addon = addons.delete(cluster, addonName, Boolean.TRUE.equals(preserve));
|
||||
return Response.ok(Map.of("addon", addon)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/addons/supported-versions")
|
||||
public Response describeAddonVersions(@QueryParam("addonName") String addonName,
|
||||
@QueryParam("kubernetesVersion") String kubernetesVersion,
|
||||
@QueryParam("maxResults") String maxResults,
|
||||
@QueryParam("nextToken") String nextToken,
|
||||
@QueryParam("publishers") List<String> publishers,
|
||||
@QueryParam("types") List<String> types,
|
||||
@QueryParam("owners") List<String> owners) {
|
||||
EksAddonService.AddonVersionsPage page = addons.describeAddonVersions(
|
||||
addonName,
|
||||
kubernetesVersion,
|
||||
Pagination.parseMaxResults(maxResults, "InvalidParameterException"),
|
||||
nextToken,
|
||||
publishers,
|
||||
types,
|
||||
owners
|
||||
);
|
||||
return Response.ok(page.nextToken() == null
|
||||
? Map.of("addons", page.addons())
|
||||
: Map.of("addons", page.addons(), "nextToken", page.nextToken())).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
|
||||
@@ -93,13 +93,15 @@ public class EksService implements TagHandler, ResourceProvider {
|
||||
private final EksOidcService oidcService;
|
||||
private final EksAccessEntryService accessEntries;
|
||||
private final EksPodIdentityAssociationService podIdentityAssociations;
|
||||
private final EksAddonService addons;
|
||||
private final ScheduledExecutorService poller = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
@Inject
|
||||
public EksService(StorageFactory storageFactory, EmulatorConfig config,
|
||||
RegionResolver regionResolver, EksClusterManager clusterManager, Ec2Service ec2Service,
|
||||
EksOidcService oidcService, EksAccessEntryService accessEntries,
|
||||
EksPodIdentityAssociationService podIdentityAssociations) {
|
||||
EksPodIdentityAssociationService podIdentityAssociations,
|
||||
EksAddonService addons) {
|
||||
this.storage = storageFactory.create("eks", "eks-clusters.json",
|
||||
new TypeReference<Map<String, Cluster>>() {
|
||||
});
|
||||
@@ -116,13 +118,22 @@ public class EksService implements TagHandler, ResourceProvider {
|
||||
this.oidcService = oidcService;
|
||||
this.accessEntries = accessEntries;
|
||||
this.podIdentityAssociations = podIdentityAssociations;
|
||||
this.addons = addons;
|
||||
}
|
||||
|
||||
public EksService(StorageFactory storageFactory, EmulatorConfig config,
|
||||
RegionResolver regionResolver, EksClusterManager clusterManager, Ec2Service ec2Service,
|
||||
EksOidcService oidcService, EksAccessEntryService accessEntries,
|
||||
EksPodIdentityAssociationService podIdentityAssociations) {
|
||||
this(storageFactory, config, regionResolver, clusterManager, ec2Service,
|
||||
oidcService, accessEntries, podIdentityAssociations, null);
|
||||
}
|
||||
|
||||
public EksService(StorageFactory storageFactory, EmulatorConfig config,
|
||||
RegionResolver regionResolver, EksClusterManager clusterManager, Ec2Service ec2Service,
|
||||
EksOidcService oidcService, EksAccessEntryService accessEntries) {
|
||||
this(storageFactory, config, regionResolver, clusterManager, ec2Service,
|
||||
oidcService, accessEntries, null);
|
||||
oidcService, accessEntries, null, null);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@@ -564,6 +575,9 @@ public class EksService implements TagHandler, ResourceProvider {
|
||||
if (podIdentityAssociations != null) {
|
||||
podIdentityAssociations.deleteClusterAssociations(cluster);
|
||||
}
|
||||
if (addons != null) {
|
||||
addons.deleteClusterAddons(cluster);
|
||||
}
|
||||
storage.delete(name);
|
||||
oidcService.deleteKey(name);
|
||||
return cluster;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record Addon(
|
||||
String addonArn,
|
||||
String addonName,
|
||||
String addonVersion,
|
||||
String clusterName,
|
||||
String status,
|
||||
AddonHealth health,
|
||||
double createdAt,
|
||||
double modifiedAt,
|
||||
String serviceAccountRoleArn,
|
||||
String configurationValues,
|
||||
Map<String, String> tags,
|
||||
List<String> podIdentityAssociations,
|
||||
String owner,
|
||||
String publisher
|
||||
) {}
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record AddonHealth(
|
||||
List<AddonIssue> issues
|
||||
) {}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record AddonInfo(
|
||||
String addonName,
|
||||
String type,
|
||||
List<AddonVersionInfo> addonVersions,
|
||||
String publisher,
|
||||
String owner
|
||||
) {}
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record AddonIssue(
|
||||
String code,
|
||||
String message,
|
||||
List<String> resourceIds
|
||||
) {}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record AddonPodIdentityAssociation(
|
||||
String roleArn,
|
||||
String serviceAccount
|
||||
) {}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record AddonVersionInfo(
|
||||
String addonVersion,
|
||||
List<String> architecture,
|
||||
List<Compatibility> compatibilities,
|
||||
Boolean requiresConfiguration,
|
||||
Boolean requiresIamPermissions
|
||||
) {}
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record Compatibility(
|
||||
String clusterVersion,
|
||||
List<String> platformVersions,
|
||||
Boolean defaultVersion
|
||||
) {}
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record CreateAddonRequest(
|
||||
String addonName,
|
||||
String addonVersion,
|
||||
String serviceAccountRoleArn,
|
||||
String resolveConflicts,
|
||||
String clientRequestToken,
|
||||
String configurationValues,
|
||||
Map<String, String> tags,
|
||||
List<AddonPodIdentityAssociation> podIdentityAssociations
|
||||
) {}
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ErrorDetail(
|
||||
String errorCode,
|
||||
String errorMessage,
|
||||
List<String> resourceIds
|
||||
) {}
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record Update(
|
||||
String id,
|
||||
String status,
|
||||
String type,
|
||||
List<UpdateParam> params,
|
||||
double createdAt,
|
||||
List<ErrorDetail> errors
|
||||
) {}
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record UpdateAddonRequest(
|
||||
String addonVersion,
|
||||
String serviceAccountRoleArn,
|
||||
String resolveConflicts,
|
||||
String clientRequestToken,
|
||||
String configurationValues,
|
||||
List<AddonPodIdentityAssociation> podIdentityAssociations
|
||||
) {}
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.github.hectorvent.floci.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record UpdateParam(
|
||||
String type,
|
||||
String value
|
||||
) {}
|
||||
@@ -57,6 +57,7 @@ quarkus:
|
||||
- ui/*.html
|
||||
- ec2/*.yaml
|
||||
- sagemaker/*.yaml
|
||||
- eks/*.json
|
||||
- i18n/*.properties
|
||||
- org/apache/velocity/runtime/defaults/*.properties
|
||||
# DriverManager finds the JDBC drivers through ServiceLoader, and the MySQL
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
{
|
||||
"addons": [
|
||||
{
|
||||
"addonName": "vpc-cni",
|
||||
"type": "networking",
|
||||
"owner": "aws",
|
||||
"publisher": "eks",
|
||||
"addonVersions": [
|
||||
{
|
||||
"addonVersion": "v1.18.5-eksbuild.1",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.32",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.31",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.30",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": false
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": true
|
||||
},
|
||||
{
|
||||
"addonVersion": "v1.18.1-eksbuild.1",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.30",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.29",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": true
|
||||
},
|
||||
{
|
||||
"addonVersion": "v1.16.0-eksbuild.1",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.28",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"addonName": "coredns",
|
||||
"type": "networking",
|
||||
"owner": "aws",
|
||||
"publisher": "eks",
|
||||
"addonVersions": [
|
||||
{
|
||||
"addonVersion": "v1.11.3-eksbuild.1",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.32",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.31",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": false
|
||||
},
|
||||
{
|
||||
"addonVersion": "v1.11.1-eksbuild.4",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.30",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.29",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": false
|
||||
},
|
||||
{
|
||||
"addonVersion": "v1.10.1-eksbuild.7",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.28",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"addonName": "kube-proxy",
|
||||
"type": "networking",
|
||||
"owner": "aws",
|
||||
"publisher": "eks",
|
||||
"addonVersions": [
|
||||
{
|
||||
"addonVersion": "v1.32.0-eksbuild.1",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.32",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": false
|
||||
},
|
||||
{
|
||||
"addonVersion": "v1.31.0-eksbuild.1",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.31",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": false
|
||||
},
|
||||
{
|
||||
"addonVersion": "v1.30.0-eksbuild.3",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.30",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": false
|
||||
},
|
||||
{
|
||||
"addonVersion": "v1.29.3-eksbuild.2",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.29",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": false
|
||||
},
|
||||
{
|
||||
"addonVersion": "v1.28.8-eksbuild.2",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.28",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"addonName": "eks-pod-identity-agent",
|
||||
"type": "security",
|
||||
"owner": "aws",
|
||||
"publisher": "eks",
|
||||
"addonVersions": [
|
||||
{
|
||||
"addonVersion": "v1.3.0-eksbuild.1",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.32",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.31",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.30",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.29",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.28",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": true
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": false
|
||||
},
|
||||
{
|
||||
"addonVersion": "v1.2.0-eksbuild.1",
|
||||
"architecture": ["amd64", "arm64"],
|
||||
"compatibilities": [
|
||||
{
|
||||
"clusterVersion": "1.30",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": false
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.29",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": false
|
||||
},
|
||||
{
|
||||
"clusterVersion": "1.28",
|
||||
"platformVersions": ["*"],
|
||||
"defaultVersion": false
|
||||
}
|
||||
],
|
||||
"requiresConfiguration": false,
|
||||
"requiresIamPermissions": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
package io.github.hectorvent.floci.services.eks;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@QuarkusTest
|
||||
class EksAddonIntegrationTest {
|
||||
|
||||
@Test
|
||||
void addonLifecycleRoundTrip() {
|
||||
String account = "123456789012";
|
||||
String name = "addon-it-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String roleName = "role-" + name;
|
||||
String roleArn = "arn:aws:iam::" + account + ":role/" + roleName;
|
||||
String basePath = "/clusters/" + name + "/addons";
|
||||
|
||||
createRole(account, roleName);
|
||||
createCluster(account, name, "1.30");
|
||||
|
||||
try {
|
||||
// 1. Create addon
|
||||
Map<String, Object> createReq = Map.of(
|
||||
"addonName", "vpc-cni",
|
||||
"addonVersion", "v1.18.1-eksbuild.1",
|
||||
"serviceAccountRoleArn", roleArn,
|
||||
"configurationValues", "{\"env\":{\"ENABLE_PREFIX_DELEGATION\":\"true\"}}",
|
||||
"clientRequestToken", "token-addon-1",
|
||||
"tags", Map.of("environment", "test")
|
||||
);
|
||||
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(createReq)
|
||||
.post(basePath)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("addon.clusterName", equalTo(name))
|
||||
.body("addon.addonName", equalTo("vpc-cni"))
|
||||
.body("addon.addonVersion", equalTo("v1.18.1-eksbuild.1"))
|
||||
.body("addon.status", equalTo("ACTIVE"))
|
||||
.body("addon.serviceAccountRoleArn", equalTo(roleArn))
|
||||
.body("addon.configurationValues", equalTo("{\"env\":{\"ENABLE_PREFIX_DELEGATION\":\"true\"}}"))
|
||||
.body("addon.tags.environment", equalTo("test"))
|
||||
.body("addon.health.issues", empty())
|
||||
.body("addon.podIdentityAssociations", empty())
|
||||
.body("addon.owner", equalTo("aws"))
|
||||
.body("addon.publisher", equalTo("eks"))
|
||||
.body("addon.addonArn", startsWith("arn:aws:eks:us-east-1:" + account + ":addon/" + name + "/vpc-cni/"))
|
||||
.body("addon.createdAt", instanceOf(Number.class))
|
||||
.body("addon.modifiedAt", instanceOf(Number.class));
|
||||
|
||||
// 2. Idempotent retry with same parameters and token
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(createReq)
|
||||
.post(basePath)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("addon.addonName", equalTo("vpc-cni"));
|
||||
|
||||
// 3. Conflicting request with same token fails
|
||||
Map<String, Object> conflictReq = Map.of(
|
||||
"addonName", "vpc-cni",
|
||||
"addonVersion", "v1.18.1-eksbuild.1",
|
||||
"clientRequestToken", "token-addon-1",
|
||||
"tags", Map.of("environment", "production")
|
||||
);
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(conflictReq)
|
||||
.post(basePath)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
|
||||
// 4. Duplicate creation with different token fails (409)
|
||||
Map<String, Object> duplicateReq = Map.of(
|
||||
"addonName", "vpc-cni",
|
||||
"clientRequestToken", "token-addon-2"
|
||||
);
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(duplicateReq)
|
||||
.post(basePath)
|
||||
.then()
|
||||
.statusCode(409)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("__type", equalTo("ResourceInUseException"));
|
||||
|
||||
// 5. Describe addon
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.get(basePath + "/vpc-cni")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("addon.addonName", equalTo("vpc-cni"))
|
||||
.body("addon.status", equalTo("ACTIVE"))
|
||||
.body("addon.addonVersion", equalTo("v1.18.1-eksbuild.1"));
|
||||
|
||||
// 6. Update addon
|
||||
String updatedRoleName = "updated-" + roleName;
|
||||
String updatedRoleArn = "arn:aws:iam::" + account + ":role/" + updatedRoleName;
|
||||
createRole(account, updatedRoleName);
|
||||
|
||||
Map<String, Object> updateReq = Map.of(
|
||||
"addonVersion", "v1.18.5-eksbuild.1",
|
||||
"serviceAccountRoleArn", updatedRoleArn,
|
||||
"configurationValues", "{\"env\":{\"ENABLE_PREFIX_DELEGATION\":\"false\"}}"
|
||||
);
|
||||
String updateId = given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(updateReq)
|
||||
.post(basePath + "/vpc-cni/update")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("update.status", equalTo("Successful"))
|
||||
.body("update.type", equalTo("AddonUpdate"))
|
||||
.body("update.id", notNullValue())
|
||||
.extract().path("update.id");
|
||||
|
||||
// Verify DescribeUpdate (called by Terraform aws_eks_addon waiter)
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.queryParam("addonName", "vpc-cni")
|
||||
.get("/clusters/" + name + "/updates/" + updateId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("update.id", equalTo(updateId))
|
||||
.body("update.status", equalTo("Successful"))
|
||||
.body("update.type", equalTo("AddonUpdate"));
|
||||
|
||||
// Verify describe shows updated values
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.get(basePath + "/vpc-cni")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("addon.addonVersion", equalTo("v1.18.5-eksbuild.1"))
|
||||
.body("addon.serviceAccountRoleArn", equalTo(updatedRoleArn))
|
||||
.body("addon.configurationValues", equalTo("{\"env\":{\"ENABLE_PREFIX_DELEGATION\":\"false\"}}"));
|
||||
|
||||
// 7. List addons
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.get(basePath)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("addons", hasSize(1))
|
||||
.body("addons[0]", equalTo("vpc-cni"));
|
||||
|
||||
// 8. Delete addon
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.delete(basePath + "/vpc-cni")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("addon.addonName", equalTo("vpc-cni"))
|
||||
.body("addon.status", equalTo("DELETING"));
|
||||
|
||||
// 9. Describe after delete returns 404
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.get(basePath + "/vpc-cni")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
} finally {
|
||||
deleteCluster(account, name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeAddonVersionsEndpoints() {
|
||||
String account = "123456789012";
|
||||
|
||||
// Query all supported versions
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.get("/addons/supported-versions")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("addons", hasSize(greaterThanOrEqualTo(4)))
|
||||
.body("addons.addonName", hasItems("vpc-cni", "coredns", "kube-proxy", "eks-pod-identity-agent"));
|
||||
|
||||
// Query with addonName filter
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.queryParam("addonName", "vpc-cni")
|
||||
.get("/addons/supported-versions")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("addons", hasSize(1))
|
||||
.body("addons[0].addonName", equalTo("vpc-cni"))
|
||||
.body("addons[0].addonVersions", not(empty()));
|
||||
|
||||
// Query with kubernetesVersion filter
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.queryParam("addonName", "vpc-cni")
|
||||
.queryParam("kubernetesVersion", "1.29")
|
||||
.get("/addons/supported-versions")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("addons", hasSize(1))
|
||||
.body("addons[0].addonName", equalTo("vpc-cni"))
|
||||
.body("addons[0].addonVersions.addonVersion", hasItem("v1.18.1-eksbuild.1"));
|
||||
|
||||
// Unknown addon name returns empty list 200
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.queryParam("addonName", "non-existent-addon")
|
||||
.get("/addons/supported-versions")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("addons", empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addonPodIdentityAssociationLifecycleIntegration() {
|
||||
String account = "123456789012";
|
||||
String name = "addon-pia-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String roleName = "role-" + name;
|
||||
String roleArn = "arn:aws:iam::" + account + ":role/" + roleName;
|
||||
String basePath = "/clusters/" + name + "/addons";
|
||||
|
||||
createRole(account, roleName);
|
||||
createCluster(account, name, "1.29");
|
||||
|
||||
try {
|
||||
// Create addon with pod identity association
|
||||
Map<String, Object> createReq = Map.of(
|
||||
"addonName", "vpc-cni",
|
||||
"podIdentityAssociations", List.of(
|
||||
Map.of("serviceAccount", "aws-node", "roleArn", roleArn)
|
||||
)
|
||||
);
|
||||
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(createReq)
|
||||
.post(basePath)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("addon.podIdentityAssociations", hasSize(1));
|
||||
|
||||
// Verify the association was created under kube-system namespace
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.get("/clusters/" + name + "/pod-identity-associations")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("associations", hasSize(1))
|
||||
.body("associations[0].namespace", equalTo("kube-system"))
|
||||
.body("associations[0].serviceAccount", equalTo("aws-node"));
|
||||
|
||||
// Delete addon with preserve=false (default) -> deletes association
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.delete(basePath + "/vpc-cni")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.get("/clusters/" + name + "/pod-identity-associations")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("associations", empty());
|
||||
|
||||
// Re-creating addon with same association succeeds (no ResourceInUseException)
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(createReq)
|
||||
.post(basePath)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("addon.addonName", equalTo("vpc-cni"));
|
||||
} finally {
|
||||
deleteCluster(account, name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void addonOnClusterVersionOutsideCatalogRangeIntegration() {
|
||||
String account = "123456789012";
|
||||
String name = "addon-k8s-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String basePath = "/clusters/" + name + "/addons";
|
||||
|
||||
createCluster(account, name, "1.35");
|
||||
try {
|
||||
// Create with no version resolves default version on cluster outside catalog range
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(Map.of("addonName", "vpc-cni"))
|
||||
.post(basePath)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("addon.addonName", equalTo("vpc-cni"))
|
||||
.body("addon.status", equalTo("ACTIVE"))
|
||||
.body("addon.addonVersion", notNullValue());
|
||||
|
||||
// In-place update with catalog version succeeds
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(Map.of("addonVersion", "v1.18.1-eksbuild.1"))
|
||||
.post(basePath + "/vpc-cni/update")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("update.status", equalTo("Successful"));
|
||||
|
||||
// In-place update with unknown version fails
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(Map.of("addonVersion", "v99.0.0"))
|
||||
.post(basePath + "/vpc-cni/update")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
} finally {
|
||||
deleteCluster(account, name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterDeletionCleansAddons() {
|
||||
String account = "123456789012";
|
||||
String name = "addon-clean-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String basePath = "/clusters/" + name + "/addons";
|
||||
|
||||
createCluster(account, name, "1.29");
|
||||
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(Map.of("addonName", "vpc-cni"))
|
||||
.post(basePath)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Delete cluster
|
||||
deleteCluster(account, name);
|
||||
|
||||
// Recreate cluster with same name
|
||||
createCluster(account, name, "1.29");
|
||||
try {
|
||||
// Addons must be empty on recreated cluster
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.get(basePath)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("addons", empty());
|
||||
} finally {
|
||||
deleteCluster(account, name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void routeCollisionsAndMissingCluster() {
|
||||
String account = "123456789012";
|
||||
|
||||
// Missing cluster returns 404 JSON, not S3 NoSuchBucket XML
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.get("/clusters/nonexistent-cluster/addons")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
// Unknown addon creation parameter error
|
||||
String name = "addon-err-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
createCluster(account, name, "1.29");
|
||||
try {
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(Map.of("addonName", "unknown-addon"))
|
||||
.post("/clusters/" + name + "/addons")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.contentType(containsString("application/json"))
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
} finally {
|
||||
deleteCluster(account, name);
|
||||
}
|
||||
}
|
||||
|
||||
private static String auth(String account, String service) {
|
||||
return "AWS4-HMAC-SHA256 Credential=" + account
|
||||
+ "/20260920/us-east-1/" + service + "/aws4_request, SignedHeaders=host, Signature=fake";
|
||||
}
|
||||
|
||||
private static void createRole(String account, String roleName) {
|
||||
given().header("Authorization", auth(account, "iam"))
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateRole")
|
||||
.formParam("RoleName", roleName)
|
||||
.formParam("Path", "/")
|
||||
.formParam("AssumeRolePolicyDocument", "{}")
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static void createCluster(String account, String name, String version) {
|
||||
Map<String, Object> req = Map.of(
|
||||
"name", name,
|
||||
"roleArn", "arn:aws:iam::" + account + ":role/eks-role",
|
||||
"version", version,
|
||||
"accessConfig", Map.of(
|
||||
"authenticationMode", "API",
|
||||
"bootstrapClusterCreatorAdminPermissions", false
|
||||
)
|
||||
);
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.contentType("application/json")
|
||||
.body(req)
|
||||
.post("/clusters")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static void deleteCluster(String account, String name) {
|
||||
given().header("Authorization", auth(account, "eks"))
|
||||
.delete("/clusters/" + name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,596 @@
|
||||
package io.github.hectorvent.floci.services.eks;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
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.Cluster;
|
||||
import io.github.hectorvent.floci.services.eks.model.ClusterStatus;
|
||||
import io.github.hectorvent.floci.services.eks.model.CreateAddonRequest;
|
||||
import io.github.hectorvent.floci.services.eks.model.Update;
|
||||
import io.github.hectorvent.floci.services.eks.model.UpdateAddonRequest;
|
||||
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.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class EksAddonServiceTest {
|
||||
|
||||
private static final String ACCOUNT = "123456789012";
|
||||
private static final String ROLE = "arn:aws:iam::" + ACCOUNT + ":role/addon-role";
|
||||
|
||||
@Test
|
||||
void createAndDescribeAddon() throws Exception {
|
||||
Fixture fixture = fixture();
|
||||
CreateAddonRequest request = new CreateAddonRequest(
|
||||
"vpc-cni",
|
||||
"v1.18.1-eksbuild.1",
|
||||
ROLE,
|
||||
"OVERWRITE",
|
||||
"token-1",
|
||||
"{\"env\":{\"foo\":\"bar\"}}",
|
||||
Map.of("env", "prod"),
|
||||
null
|
||||
);
|
||||
|
||||
Addon created = fixture.service.create(fixture.cluster, request);
|
||||
|
||||
assertEquals("vpc-cni", created.addonName());
|
||||
assertEquals("test-cluster", created.clusterName());
|
||||
assertEquals("v1.18.1-eksbuild.1", created.addonVersion());
|
||||
assertEquals("ACTIVE", created.status());
|
||||
assertNotNull(created.addonArn());
|
||||
assertTrue(created.addonArn().startsWith("arn:aws:eks:us-east-1:123456789012:addon/test-cluster/vpc-cni/"));
|
||||
assertEquals(ROLE, created.serviceAccountRoleArn());
|
||||
assertEquals("{\"env\":{\"foo\":\"bar\"}}", created.configurationValues());
|
||||
assertEquals(Map.of("env", "prod"), created.tags());
|
||||
assertNotNull(created.health());
|
||||
assertTrue(created.health().issues().isEmpty());
|
||||
assertEquals("aws", created.owner());
|
||||
assertEquals("eks", created.publisher());
|
||||
assertTrue(created.createdAt() > 0);
|
||||
assertEquals(created.createdAt(), created.modifiedAt());
|
||||
|
||||
// Serialization roundtrip
|
||||
EksAddonService.StoredAddon stored = fixture.storage.scan(k -> true).getFirst();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
EksAddonService.StoredAddon restored = mapper.readValue(
|
||||
mapper.writeValueAsBytes(stored), EksAddonService.StoredAddon.class);
|
||||
assertEquals(stored, restored);
|
||||
|
||||
// Describe returns the same addon
|
||||
Addon described = fixture.service.describe(fixture.cluster, "vpc-cni");
|
||||
assertEquals(created, described);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createResolvesDefaultVersionWhenOmitted() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.29");
|
||||
|
||||
CreateAddonRequest request = new CreateAddonRequest(
|
||||
"vpc-cni",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
Addon created = fixture.service.create(fixture.cluster, request);
|
||||
assertEquals("v1.18.1-eksbuild.1", created.addonVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsUnknownAddonAndUnsupportedVersion() {
|
||||
Fixture fixture = fixture();
|
||||
|
||||
CreateAddonRequest unknownAddon = new CreateAddonRequest(
|
||||
"unknown-plugin",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
AwsException ex1 = assertThrows(AwsException.class, () ->
|
||||
fixture.service.create(fixture.cluster, unknownAddon));
|
||||
assertEquals("InvalidParameterException", ex1.getErrorCode());
|
||||
assertEquals(400, ex1.getHttpStatus());
|
||||
assertTrue(ex1.getMessage().contains("unknown-plugin"));
|
||||
|
||||
CreateAddonRequest badVersion = new CreateAddonRequest(
|
||||
"vpc-cni",
|
||||
"v99.99.99",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
AwsException ex2 = assertThrows(AwsException.class, () ->
|
||||
fixture.service.create(fixture.cluster, badVersion));
|
||||
assertEquals("InvalidParameterException", ex2.getErrorCode());
|
||||
assertEquals(400, ex2.getHttpStatus());
|
||||
assertTrue(ex2.getMessage().contains("Addon version specified is not supported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void retriesAreIdempotentButConflictingRequestsAndDuplicatesFail() {
|
||||
Fixture fixture = fixture();
|
||||
CreateAddonRequest request = new CreateAddonRequest(
|
||||
"coredns",
|
||||
"v1.11.1-eksbuild.4",
|
||||
null,
|
||||
null,
|
||||
"retry-token",
|
||||
null,
|
||||
Map.of("k", "v"),
|
||||
null
|
||||
);
|
||||
|
||||
Addon first = fixture.service.create(fixture.cluster, request);
|
||||
Addon retry = fixture.service.create(fixture.cluster, request);
|
||||
assertEquals(first, retry);
|
||||
|
||||
// Same token with different parameters throws InvalidParameterException
|
||||
CreateAddonRequest conflict = new CreateAddonRequest(
|
||||
"coredns",
|
||||
"v1.11.1-eksbuild.4",
|
||||
ROLE,
|
||||
null,
|
||||
"retry-token",
|
||||
null,
|
||||
Map.of("k", "v"),
|
||||
null
|
||||
);
|
||||
AwsException exConflict = assertThrows(AwsException.class, () ->
|
||||
fixture.service.create(fixture.cluster, conflict));
|
||||
assertEquals("InvalidParameterException", exConflict.getErrorCode());
|
||||
assertEquals(400, exConflict.getHttpStatus());
|
||||
|
||||
// Duplicate addon with different token throws ResourceInUseException (409)
|
||||
CreateAddonRequest duplicate = new CreateAddonRequest(
|
||||
"coredns",
|
||||
"v1.11.1-eksbuild.4",
|
||||
null,
|
||||
null,
|
||||
"different-token",
|
||||
null,
|
||||
Map.of(),
|
||||
null
|
||||
);
|
||||
AwsException exDup = assertThrows(AwsException.class, () ->
|
||||
fixture.service.create(fixture.cluster, duplicate));
|
||||
assertEquals("ResourceInUseException", exDup.getErrorCode());
|
||||
assertEquals(409, exDup.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAddonValidationsAndModifiedAt() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.30");
|
||||
CreateAddonRequest createReq = new CreateAddonRequest(
|
||||
"vpc-cni",
|
||||
"v1.18.1-eksbuild.1",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
Addon created = fixture.service.create(fixture.cluster, createReq);
|
||||
|
||||
// Update version to another supported version
|
||||
UpdateAddonRequest updateReq = new UpdateAddonRequest(
|
||||
"v1.18.5-eksbuild.1",
|
||||
ROLE,
|
||||
"OVERWRITE",
|
||||
"up-token",
|
||||
"{\"some\":\"config\"}",
|
||||
null
|
||||
);
|
||||
Update update = fixture.service.update(fixture.cluster, "vpc-cni", updateReq);
|
||||
assertEquals("Successful", update.status());
|
||||
assertEquals("AddonUpdate", update.type());
|
||||
assertNotNull(update.id());
|
||||
assertTrue(update.errors().isEmpty());
|
||||
|
||||
Addon updated = fixture.service.describe(fixture.cluster, "vpc-cni");
|
||||
assertEquals("v1.18.5-eksbuild.1", updated.addonVersion());
|
||||
assertEquals(ROLE, updated.serviceAccountRoleArn());
|
||||
assertEquals("{\"some\":\"config\"}", updated.configurationValues());
|
||||
assertTrue(updated.modifiedAt() >= created.createdAt());
|
||||
|
||||
// Update with unsupported version fails
|
||||
UpdateAddonRequest badUpdate = new UpdateAddonRequest("v0.0.0", null, null, null, null, null);
|
||||
AwsException exBad = assertThrows(AwsException.class, () ->
|
||||
fixture.service.update(fixture.cluster, "vpc-cni", badUpdate));
|
||||
assertEquals("InvalidParameterException", exBad.getErrorCode());
|
||||
|
||||
// Update non-existent addon fails
|
||||
assertThrows(AwsException.class, () ->
|
||||
fixture.service.update(fixture.cluster, "kube-proxy", updateReq));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAddonReturnsDeletedAndRemovesFromStore() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.29");
|
||||
CreateAddonRequest request = new CreateAddonRequest("kube-proxy", null, null, null, null, null, null, null);
|
||||
Addon created = fixture.service.create(fixture.cluster, request);
|
||||
|
||||
Addon deleted = fixture.service.delete(fixture.cluster, "kube-proxy", false);
|
||||
assertEquals("DELETING", deleted.status());
|
||||
assertEquals("kube-proxy", deleted.addonName());
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
fixture.service.describe(fixture.cluster, "kube-proxy"));
|
||||
assertEquals("ResourceNotFoundException", ex.getErrorCode());
|
||||
assertEquals(404, ex.getHttpStatus());
|
||||
|
||||
assertThrows(AwsException.class, () ->
|
||||
fixture.service.delete(fixture.cluster, "kube-proxy", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listAddonsWithPagination() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.29");
|
||||
|
||||
fixture.service.create(fixture.cluster, new CreateAddonRequest("vpc-cni", null, null, null, null, null, null, null));
|
||||
fixture.service.create(fixture.cluster, new CreateAddonRequest("coredns", null, null, null, null, null, null, null));
|
||||
fixture.service.create(fixture.cluster, new CreateAddonRequest("kube-proxy", null, null, null, null, null, null, null));
|
||||
|
||||
// List all
|
||||
EksAddonService.AddonNamesPage allPage = fixture.service.list(fixture.cluster, null, null);
|
||||
assertEquals(3, allPage.addons().size());
|
||||
assertEquals(List.of("coredns", "kube-proxy", "vpc-cni"), allPage.addons());
|
||||
assertNull(allPage.nextToken());
|
||||
|
||||
// Paginate limit 1
|
||||
EksAddonService.AddonNamesPage p1 = fixture.service.list(fixture.cluster, 1, null);
|
||||
assertEquals(1, p1.addons().size());
|
||||
assertEquals("coredns", p1.addons().getFirst());
|
||||
assertNotNull(p1.nextToken());
|
||||
|
||||
EksAddonService.AddonNamesPage p2 = fixture.service.list(fixture.cluster, 1, p1.nextToken());
|
||||
assertEquals(1, p2.addons().size());
|
||||
assertEquals("kube-proxy", p2.addons().getFirst());
|
||||
assertNotNull(p2.nextToken());
|
||||
|
||||
EksAddonService.AddonNamesPage p3 = fixture.service.list(fixture.cluster, 1, p2.nextToken());
|
||||
assertEquals(1, p3.addons().size());
|
||||
assertEquals("vpc-cni", p3.addons().getFirst());
|
||||
assertNull(p3.nextToken());
|
||||
|
||||
// Invalid maxResults
|
||||
assertThrows(AwsException.class, () -> fixture.service.list(fixture.cluster, 0, null));
|
||||
assertThrows(AwsException.class, () -> fixture.service.list(fixture.cluster, 101, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterDeletionCleansAddonsAndRecreationCannotInheritThem() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.29");
|
||||
fixture.service.create(fixture.cluster, new CreateAddonRequest("vpc-cni", null, null, null, null, null, null, null));
|
||||
|
||||
assertEquals(1, fixture.service.list(fixture.cluster, null, null).addons().size());
|
||||
|
||||
fixture.service.deleteClusterAddons(fixture.cluster);
|
||||
assertTrue(fixture.storage.scan(k -> true).isEmpty());
|
||||
|
||||
// Recreated cluster with new createdAt cannot inherit old addons or pagination tokens
|
||||
fixture.service.create(fixture.cluster, new CreateAddonRequest("vpc-cni", null, null, null, null, null, null, null));
|
||||
fixture.service.create(fixture.cluster, new CreateAddonRequest("coredns", null, null, null, null, null, null, null));
|
||||
EksAddonService.AddonNamesPage pageBefore = fixture.service.list(fixture.cluster, 1, null);
|
||||
assertNotNull(pageBefore.nextToken());
|
||||
|
||||
fixture.cluster.setCreatedAt(fixture.cluster.getCreatedAt().plusSeconds(10));
|
||||
assertTrue(fixture.service.list(fixture.cluster, null, null).addons().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void inactiveClusterRejectsOperations() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setStatus(ClusterStatus.CREATING);
|
||||
|
||||
CreateAddonRequest request = new CreateAddonRequest("vpc-cni", null, null, null, null, null, null, null);
|
||||
assertThrows(AwsException.class, () -> fixture.service.create(fixture.cluster, request));
|
||||
assertThrows(AwsException.class, () -> fixture.service.describe(fixture.cluster, "vpc-cni"));
|
||||
assertThrows(AwsException.class, () -> fixture.service.list(fixture.cluster, null, null));
|
||||
assertThrows(AwsException.class, () -> fixture.service.update(fixture.cluster, "vpc-cni", null));
|
||||
assertThrows(AwsException.class, () -> fixture.service.delete(fixture.cluster, "vpc-cni", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeUpdateAndNotFound() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.29");
|
||||
fixture.service.create(fixture.cluster, new CreateAddonRequest("vpc-cni", null, null, null, null, null, null, null));
|
||||
|
||||
Update update = fixture.service.update(fixture.cluster, "vpc-cni",
|
||||
new UpdateAddonRequest("v1.18.1-eksbuild.1", null, null, null, null, null));
|
||||
assertNotNull(update.id());
|
||||
assertEquals("Successful", update.status());
|
||||
assertEquals("AddonUpdate", update.type());
|
||||
|
||||
// Describe without addonName filter
|
||||
Update fetched = fixture.service.describeUpdate(fixture.cluster, update.id(), null);
|
||||
assertEquals(update.id(), fetched.id());
|
||||
assertEquals("Successful", fetched.status());
|
||||
|
||||
// Describe with matching addonName filter
|
||||
Update fetchedFiltered = fixture.service.describeUpdate(fixture.cluster, update.id(), "vpc-cni");
|
||||
assertEquals(update.id(), fetchedFiltered.id());
|
||||
|
||||
// Describe with mismatched addonName filter
|
||||
AwsException exMismatch = assertThrows(AwsException.class, () ->
|
||||
fixture.service.describeUpdate(fixture.cluster, update.id(), "coredns"));
|
||||
assertEquals("ResourceNotFoundException", exMismatch.getErrorCode());
|
||||
assertEquals(404, exMismatch.getHttpStatus());
|
||||
|
||||
// Describe nonexistent updateId
|
||||
AwsException exNotFound = assertThrows(AwsException.class, () ->
|
||||
fixture.service.describeUpdate(fixture.cluster, "missing-update-id", null));
|
||||
assertEquals("ResourceNotFoundException", exNotFound.getErrorCode());
|
||||
assertEquals(404, exNotFound.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void podIdentityAssociationsLifecycle() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.29");
|
||||
|
||||
AddonPodIdentityAssociation assoc1 = new AddonPodIdentityAssociation(ROLE, "aws-node");
|
||||
CreateAddonRequest request = new CreateAddonRequest(
|
||||
"vpc-cni", null, null, null, null, null, null, List.of(assoc1));
|
||||
|
||||
Addon created = fixture.service.create(fixture.cluster, request);
|
||||
assertEquals(1, created.podIdentityAssociations().size());
|
||||
String assocArn = created.podIdentityAssociations().getFirst();
|
||||
|
||||
// Verify association was created in kube-system namespace
|
||||
EksPodIdentityAssociationService.Page page = fixture.podIdentityAssociations.list(
|
||||
fixture.cluster, "kube-system", "aws-node", null, null);
|
||||
assertEquals(1, page.associations().size());
|
||||
assertEquals(assocArn, page.associations().getFirst().associationArn());
|
||||
|
||||
// Update with same or new association succeeds without duplicate error
|
||||
Update update = fixture.service.update(fixture.cluster, "vpc-cni",
|
||||
new UpdateAddonRequest(null, null, null, null, null, List.of(assoc1)));
|
||||
assertNotNull(update.id());
|
||||
// Verify UpdateParam for PodIdentityAssociations is JSON string, not Java toString()
|
||||
assertTrue(update.params().stream().anyMatch(p ->
|
||||
"PodIdentityAssociations".equals(p.type())
|
||||
&& p.value().contains("\"roleArn\"")
|
||||
&& !p.value().startsWith("AddonPodIdentityAssociation[")
|
||||
));
|
||||
|
||||
// Re-read addon and verify association still present in kube-system
|
||||
Addon updated = fixture.service.describe(fixture.cluster, "vpc-cni");
|
||||
assertEquals(1, updated.podIdentityAssociations().size());
|
||||
|
||||
// Update with invalid association fails validation BEFORE deleting existing associations
|
||||
AddonPodIdentityAssociation invalidAssoc = new AddonPodIdentityAssociation(
|
||||
"arn:aws:iam::" + ACCOUNT + ":role/non-existent-role", "aws-node");
|
||||
AwsException exInvalidUpdate = assertThrows(AwsException.class, () ->
|
||||
fixture.service.update(fixture.cluster, "vpc-cni",
|
||||
new UpdateAddonRequest(null, null, null, null, null, List.of(invalidAssoc))));
|
||||
assertEquals("InvalidParameterException", exInvalidUpdate.getErrorCode());
|
||||
// Verify existing association was NOT deleted
|
||||
Addon afterFailedUpdate = fixture.service.describe(fixture.cluster, "vpc-cni");
|
||||
assertEquals(1, afterFailedUpdate.podIdentityAssociations().size());
|
||||
EksPodIdentityAssociationService.Page stillThere = fixture.podIdentityAssociations.list(
|
||||
fixture.cluster, "kube-system", "aws-node", null, null);
|
||||
assertEquals(1, stillThere.associations().size());
|
||||
|
||||
// Delete with preserve=false removes association from cluster
|
||||
fixture.service.delete(fixture.cluster, "vpc-cni", false);
|
||||
EksPodIdentityAssociationService.Page afterDelete = fixture.podIdentityAssociations.list(
|
||||
fixture.cluster, "kube-system", "aws-node", null, null);
|
||||
assertTrue(afterDelete.associations().isEmpty());
|
||||
|
||||
// Re-creating addon with the same association now succeeds because old one was deleted
|
||||
Addon recreated = fixture.service.create(fixture.cluster, request);
|
||||
assertEquals(1, recreated.podIdentityAssociations().size());
|
||||
|
||||
// Delete with preserve=true keeps the association in cluster
|
||||
fixture.service.delete(fixture.cluster, "vpc-cni", true);
|
||||
EksPodIdentityAssociationService.Page afterPreserveDelete = fixture.podIdentityAssociations.list(
|
||||
fixture.cluster, "kube-system", "aws-node", null, null);
|
||||
assertEquals(1, afterPreserveDelete.associations().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitVersionMustBeCompatibleWithClusterKubernetesVersion() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.29");
|
||||
|
||||
// v1.16.0-eksbuild.1 is only compatible with k8s 1.28
|
||||
CreateAddonRequest reqIncompatible = new CreateAddonRequest(
|
||||
"vpc-cni", "v1.16.0-eksbuild.1", null, null, null, null, null, null);
|
||||
AwsException exCreate = assertThrows(AwsException.class, () ->
|
||||
fixture.service.create(fixture.cluster, reqIncompatible));
|
||||
assertEquals("InvalidParameterException", exCreate.getErrorCode());
|
||||
assertEquals(400, exCreate.getHttpStatus());
|
||||
|
||||
// Compatible version works
|
||||
CreateAddonRequest reqCompatible = new CreateAddonRequest(
|
||||
"vpc-cni", "v1.18.1-eksbuild.1", null, null, null, null, null, null);
|
||||
Addon created = fixture.service.create(fixture.cluster, reqCompatible);
|
||||
assertEquals("v1.18.1-eksbuild.1", created.addonVersion());
|
||||
|
||||
// Updating to incompatible version fails
|
||||
UpdateAddonRequest updateIncompatible = new UpdateAddonRequest(
|
||||
"v1.16.0-eksbuild.1", null, null, null, null, null);
|
||||
AwsException exUpdate = assertThrows(AwsException.class, () ->
|
||||
fixture.service.update(fixture.cluster, "vpc-cni", updateIncompatible));
|
||||
assertEquals("InvalidParameterException", exUpdate.getErrorCode());
|
||||
assertEquals(400, exUpdate.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterVersionOutsideCatalogRangeAllowsCatalogVersionsAndResolvesDefault() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.35");
|
||||
|
||||
// Create with no version resolves a default version from the catalog without error
|
||||
CreateAddonRequest reqDefault = new CreateAddonRequest(
|
||||
"vpc-cni", null, null, null, null, null, null, null);
|
||||
Addon created = fixture.service.create(fixture.cluster, reqDefault);
|
||||
assertNotNull(created.addonVersion());
|
||||
assertEquals("ACTIVE", created.status());
|
||||
|
||||
// Update with another valid catalog version succeeds
|
||||
Update update = fixture.service.update(fixture.cluster, "vpc-cni",
|
||||
new UpdateAddonRequest("v1.18.1-eksbuild.1", null, null, null, null, null));
|
||||
assertNotNull(update.id());
|
||||
Addon updated = fixture.service.describe(fixture.cluster, "vpc-cni");
|
||||
assertEquals("v1.18.1-eksbuild.1", updated.addonVersion());
|
||||
|
||||
// Updating with a version NOT in catalog at all still fails
|
||||
UpdateAddonRequest updateBad = new UpdateAddonRequest(
|
||||
"v99.0.0", null, null, null, null, null);
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
fixture.service.update(fixture.cluster, "vpc-cni", updateBad));
|
||||
assertEquals("InvalidParameterException", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterVersion132SupportedInCatalog() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.32");
|
||||
|
||||
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());
|
||||
|
||||
// Incompatible version (v1.16.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);
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
fixture.service.create(fixture.cluster, reqIncompatible));
|
||||
assertEquals("InvalidParameterException", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeAddonVersionsWithFilteringAndPagination() {
|
||||
Fixture fixture = fixture();
|
||||
|
||||
// All addons
|
||||
EksAddonService.AddonVersionsPage all = fixture.service.describeAddonVersions(
|
||||
null, null, null, null, null, null, null);
|
||||
assertTrue(all.addons().size() >= 4);
|
||||
|
||||
// Filter by addonName
|
||||
EksAddonService.AddonVersionsPage vpcCniOnly = fixture.service.describeAddonVersions(
|
||||
"vpc-cni", null, null, null, null, null, null);
|
||||
assertEquals(1, vpcCniOnly.addons().size());
|
||||
assertEquals("vpc-cni", vpcCniOnly.addons().getFirst().addonName());
|
||||
|
||||
// Filter by kubernetesVersion
|
||||
EksAddonService.AddonVersionsPage k8s128 = fixture.service.describeAddonVersions(
|
||||
"vpc-cni", "1.28", null, null, null, null, null);
|
||||
assertEquals(1, k8s128.addons().size());
|
||||
AddonInfo info128 = k8s128.addons().getFirst();
|
||||
assertTrue(info128.addonVersions().stream()
|
||||
.anyMatch(v -> "v1.16.0-eksbuild.1".equals(v.addonVersion())));
|
||||
|
||||
// Unknown addon returns empty list
|
||||
EksAddonService.AddonVersionsPage empty = fixture.service.describeAddonVersions(
|
||||
"unknown-addon", null, null, null, null, null, null);
|
||||
assertTrue(empty.addons().isEmpty());
|
||||
|
||||
// Pagination
|
||||
EksAddonService.AddonVersionsPage page1 = fixture.service.describeAddonVersions(
|
||||
null, null, 2, null, null, null, null);
|
||||
assertEquals(2, page1.addons().size());
|
||||
assertNotNull(page1.nextToken());
|
||||
|
||||
EksAddonService.AddonVersionsPage page2 = fixture.service.describeAddonVersions(
|
||||
null, null, 2, page1.nextToken(), null, null, null);
|
||||
assertTrue(page2.addons().size() >= 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void roleArnAndTagValidations() {
|
||||
Fixture fixture = fixture();
|
||||
fixture.cluster.setVersion("1.29");
|
||||
|
||||
// Bad role ARN format
|
||||
CreateAddonRequest badRoleArn = new CreateAddonRequest(
|
||||
"vpc-cni", null, "invalid-arn", null, null, null, null, null);
|
||||
AwsException exRole = assertThrows(AwsException.class, () ->
|
||||
fixture.service.create(fixture.cluster, badRoleArn));
|
||||
assertEquals("InvalidParameterException", exRole.getErrorCode());
|
||||
|
||||
// Non-existent role
|
||||
when(fixture.iam.findRole("123456789012", "missing-role")).thenReturn(Optional.empty());
|
||||
CreateAddonRequest missingRole = new CreateAddonRequest(
|
||||
"vpc-cni", null, "arn:aws:iam::123456789012:role/missing-role", null, null, null, null, null);
|
||||
AwsException exMiss = assertThrows(AwsException.class, () ->
|
||||
fixture.service.create(fixture.cluster, missingRole));
|
||||
assertEquals("InvalidParameterException", exMiss.getErrorCode());
|
||||
assertTrue(exMiss.getMessage().contains("Role not found"));
|
||||
|
||||
// Too many tags (>50)
|
||||
Map<String, String> tooManyTags = new HashMap<>();
|
||||
for (int i = 0; i < 51; i++) {
|
||||
tooManyTags.put("key" + i, "val" + i);
|
||||
}
|
||||
CreateAddonRequest tagOver = new CreateAddonRequest(
|
||||
"vpc-cni", null, null, null, null, null, tooManyTags, null);
|
||||
AwsException exTags = assertThrows(AwsException.class, () ->
|
||||
fixture.service.create(fixture.cluster, tagOver));
|
||||
assertEquals("InvalidParameterException", exTags.getErrorCode());
|
||||
assertTrue(exTags.getMessage().contains("Too many tags"));
|
||||
}
|
||||
|
||||
private static Fixture fixture() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setName("test-cluster");
|
||||
cluster.setArn("arn:aws:eks:us-east-1:123456789012:cluster/test-cluster");
|
||||
cluster.setCreatedAt(Instant.parse("2026-09-20T12:00:00Z"));
|
||||
cluster.setStatus(ClusterStatus.ACTIVE);
|
||||
|
||||
IamService iam = mock(IamService.class);
|
||||
IamRole role = new IamRole("AROA-addon", "addon-role", "/", ROLE, "{}");
|
||||
when(iam.findRole("123456789012", "addon-role")).thenReturn(Optional.of(role));
|
||||
|
||||
EksAddonCatalog catalog = new EksAddonCatalog();
|
||||
InMemoryStorage<String, EksAddonService.StoredAddon> storage = new InMemoryStorage<>();
|
||||
InMemoryStorage<String, EksAddonService.StoredUpdate> updatesStorage = new InMemoryStorage<>();
|
||||
InMemoryStorage<String, EksPodIdentityAssociationService.StoredAssociation> assocStorage = new InMemoryStorage<>();
|
||||
EksPodIdentityAssociationService podIdentityAssociations = new EksPodIdentityAssociationService(assocStorage, iam);
|
||||
EksAddonService service = new EksAddonService(storage, updatesStorage, catalog, iam, podIdentityAssociations);
|
||||
|
||||
return new Fixture(cluster, iam, role, storage, updatesStorage, catalog, podIdentityAssociations, service);
|
||||
}
|
||||
|
||||
private record Fixture(Cluster cluster, IamService iam, IamRole role,
|
||||
InMemoryStorage<String, EksAddonService.StoredAddon> storage,
|
||||
InMemoryStorage<String, EksAddonService.StoredUpdate> updatesStorage,
|
||||
EksAddonCatalog catalog,
|
||||
EksPodIdentityAssociationService podIdentityAssociations,
|
||||
EksAddonService service) {}
|
||||
}
|
||||
@@ -740,6 +740,31 @@ class EksServiceTest {
|
||||
assertTrue(eksService.listClusters().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteClusterDeletesAddons() {
|
||||
StorageFactory storageFactory = new StorageFactory(null, null) {
|
||||
@Override
|
||||
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
|
||||
TypeReference<Map<String, V>> typeReference) {
|
||||
return AccountAwareStorageBackend.inMemory("000000000000");
|
||||
}
|
||||
};
|
||||
|
||||
EksAddonService mockAddons = mock(EksAddonService.class);
|
||||
EksService service = new EksService(storageFactory, testConfig(),
|
||||
new RegionResolver("us-east-1", "000000000000"), null, null,
|
||||
new EksOidcService(storageFactory, new ObjectMapper()), mock(EksAccessEntryService.class),
|
||||
mock(EksPodIdentityAssociationService.class), mockAddons);
|
||||
|
||||
CreateClusterRequest req = new CreateClusterRequest();
|
||||
req.setName("addons-cluster-to-delete");
|
||||
req.setRoleArn("arn:aws:iam::000000000000:role/eks-role");
|
||||
service.createCluster(req);
|
||||
|
||||
service.deleteCluster("addons-cluster-to-delete");
|
||||
verify(mockAddons).deleteClusterAddons(any(Cluster.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void taggingOperations() {
|
||||
CreateClusterRequest req = new CreateClusterRequest();
|
||||
|
||||
Reference in new issue
Block a user