feat(eks): store the cluster upgrade policy and update it through UpdateClusterConfig (#9253)

CreateCluster dropped upgradePolicy, DescribeCluster never returned
one, and UpdateClusterConfig refused the member, so Terraform's
aws_eks_cluster with upgrade_policy showed a diff on every plan that
no apply could fix.

CreateCluster now stores upgradePolicy.supportType, EXTENDED when the
request names none, as EKS gives new clusters extended support, and
DescribeCluster returns it. A cluster stored before reports EXTENDED
as well. UpdateClusterConfig takes upgradePolicy as an update type of
its own and answers with a Successful UpgradePolicyUpdate whose
UpgradePolicy parameter holds the policy as JSON, as AWS records it.
A repeated clientRequestToken is matched against it like the other
families, and an unknown support type is refused with
InvalidParameterException.

STANDARD is refused, in AWS's words, for a version past its end of
standard support: on CreateCluster, and on UpdateClusterConfig, which
turns extended support on at any time but off only in standard
support. The end of standard support of each version Floci serves
comes from the Amazon EKS Kubernetes release calendar. A cluster that
named no version counts as in standard support, as the version AWS
gives it is.

AWS::EKS::Cluster creates the cluster with its UpgradePolicy and
updates it in place. A dropped UpgradePolicy returns the cluster to
EXTENDED, a stack rollback restores the policy, and a cluster a stack
created before this gets the policy its template declares on the
stack's next update.

Closes #5640
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-23 08:07:04 -04:00
1 parent 8a9fa27575
commit b521ee513c
17 files changed
+491 -30

No files matched your search

+1 -1
View File
@@ -219,7 +219,7 @@ cross-resource references.
| ECR | `Repository` |
| ECS | `Cluster`, `TaskDefinition`, `Service`, `CapacityProvider`, `ClusterCapacityProviderAssociations` |
| EFS | `FileSystem` (metadata only, there is no NFS data plane), `MountTarget` (`SecurityGroups` update in place, every other property replaces), `AccessPoint` (`AccessPointTags` update in place, every other property replaces) |
| EKS | `Cluster` (created with `Name`, `Version`, `RoleArn`, `Tags`, `EncryptionConfig`, `ResourcesVpcConfig`, `Logging`, `AccessConfig` and `KubernetesNetworkConfig.IpFamily` and `ServiceIpv4Cidr`, a replacement included; a change to `EncryptionConfig`, `IpFamily` or `ServiceIpv4Cidr` replaces the cluster with the new value applied; `ElasticLoadBalancing`, `ServiceIpv6Cidr` and `ResourcesVpcConfig.ControlPlaneEgressMode` are accepted and ignored; updated in place for `Tags`, keeping tags added outside the stack, for `Logging`, for `AccessConfig.AuthenticationMode` (a mode cannot be moved back, so a stack update that does so fails, and a stack rollback restores it) and for `ResourcesVpcConfig` endpoint access and `PublicAccessCidrs`; a change to `Name`, `RoleArn`, `EncryptionConfig`, `BootstrapSelfManagedAddons`, `OutpostConfig`, `AccessConfig.BootstrapClusterCreatorAdminPermissions`, `KubernetesNetworkConfig.IpFamily` or `KubernetesNetworkConfig.ServiceIpv4Cidr` replaces the cluster, as the registry marks them create-only, and deletes the old one once the update commits; a change to `Version` is accepted with a warning and not applied, as the emulator has no `UpdateClusterVersion`; a change to the subnets or security groups of `ResourcesVpcConfig` fails the resource, as the emulator's `UpdateClusterConfig` does not change them), `Nodegroup` (created with `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets` and `Tags`; updated in place for `Tags`, keeping tags added outside the stack; a change to `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets`, `AmiType`, `CapacityType`, `DiskSize`, `InstanceTypes` or `RemoteAccess` replaces the nodegroup, as the registry marks them create-only, and deletes the old one once the update commits; `ScalingConfig`, `Labels`, `Taints`, `UpdateConfig`, `Version`, `ReleaseVersion`, `ForceUpdateEnabled`, `LaunchTemplate`, `NodeRepairConfig` and `WarmPoolConfig` are accepted and not applied, whether changed or dropped, with a warning, as the emulator cannot update a nodegroup in place) |
| EKS | `Cluster` (created with `Name`, `Version`, `RoleArn`, `Tags`, `EncryptionConfig`, `ResourcesVpcConfig`, `Logging`, `AccessConfig`, `UpgradePolicy` and `KubernetesNetworkConfig.IpFamily` and `ServiceIpv4Cidr`, a replacement included; a change to `EncryptionConfig`, `IpFamily` or `ServiceIpv4Cidr` replaces the cluster with the new value applied; `ElasticLoadBalancing`, `ServiceIpv6Cidr` and `ResourcesVpcConfig.ControlPlaneEgressMode` are accepted and ignored; updated in place for `Tags`, keeping tags added outside the stack, for `Logging`, for `AccessConfig.AuthenticationMode` (a mode cannot be moved back, so a stack update that does so fails, and a stack rollback restores it), for `UpgradePolicy` (a dropped one returns the cluster to `EXTENDED`) and for `ResourcesVpcConfig` endpoint access and `PublicAccessCidrs`; a change to `Name`, `RoleArn`, `EncryptionConfig`, `BootstrapSelfManagedAddons`, `OutpostConfig`, `AccessConfig.BootstrapClusterCreatorAdminPermissions`, `KubernetesNetworkConfig.IpFamily` or `KubernetesNetworkConfig.ServiceIpv4Cidr` replaces the cluster, as the registry marks them create-only, and deletes the old one once the update commits; a change to `Version` is accepted with a warning and not applied, as the emulator has no `UpdateClusterVersion`; a change to the subnets or security groups of `ResourcesVpcConfig` fails the resource, as the emulator's `UpdateClusterConfig` does not change them), `Nodegroup` (created with `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets` and `Tags`; updated in place for `Tags`, keeping tags added outside the stack; a change to `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets`, `AmiType`, `CapacityType`, `DiskSize`, `InstanceTypes` or `RemoteAccess` replaces the nodegroup, as the registry marks them create-only, and deletes the old one once the update commits; `ScalingConfig`, `Labels`, `Taints`, `UpdateConfig`, `Version`, `ReleaseVersion`, `ForceUpdateEnabled`, `LaunchTemplate`, `NodeRepairConfig` and `WarmPoolConfig` are accepted and not applied, whether changed or dropped, with a warning, as the emulator cannot update a nodegroup in place) |
| EMR | `Cluster` (created through `RunJobFlow`, once it is waiting or running, its master, core and task groups or fleets as `RunJobFlow`'s `InstanceGroups` or `InstanceFleets`; `AdditionalInfo` and `Instances`' `HadoopVersion` are accepted with a warning and not stored; task groups and fleets need unique names; a template that sets the read-only `Id` or `MasterPublicDNS` is refused; updated in place for `AutoTerminationPolicy`, `ManagedScalingPolicy`, `StepConcurrencyLevel`, `VisibleToAllUsers`, `Tags` (keeping tags added outside the stack), `TerminationProtected`, `UnhealthyNodeReplacement`, a core or task group's `InstanceCount` and `AutoScalingPolicy` and a core or task fleet's target capacities, a dropped one taking its default; any other change, within `Instances` included, replaces the cluster and terminates the old one once the update commits; a termination-protected cluster refuses the delete), `InstanceGroupConfig` (a `TASK` group, the one role the reference allows, added through `AddInstanceGroups`; `InstanceCount` and `AutoScalingPolicy` update in place, and a create-only change adds a new group; the delete removes its policy and shrinks it to nothing, as a group cannot be removed from its cluster), `InstanceFleetConfig` (a `TASK` fleet, the one type the reference allows, added through `AddInstanceFleet`; `TargetOnDemandCapacity`, `TargetSpotCapacity`, `InstanceTypeConfigs` and `ResizeSpecifications` update in place through `ModifyInstanceFleet`, and a create-only change adds a new fleet; a rollback puts them back, but not an instance type the update added, which every later `ModifyInstanceFleet` must include, nor resize specifications where the fleet had none, which no request can clear, and dropped configs or resize specifications are kept for the same reason; the delete shrinks the fleet to nothing, as a fleet cannot be removed from its cluster), `Step` (added through `AddJobFlowSteps`, `LogUri` and `EncryptionKeyArn` as its `StepMonitoringConfiguration`; every property is create-only, so a change adds a new step, and a step stays in its cluster's history when deleted, as the schema's delete handler calls nothing), `SecurityConfiguration` (created with `Name`, generated when the template gives none, and the `SecurityConfiguration` JSON, as an object or its text; both are create-only, so any change replaces it and deletes the old one once the update commits, and a change that keeps a template's own `Name` is refused, as for every custom-named resource), `Studio` (created with every property; a template that sets the read-only `Arn`, `StudioId` or `Url` is refused; updated in place through `UpdateStudio` for `Name`, `Description`, `SubnetIds` and `DefaultS3Location`, a dropped setting kept as it is, and for `Tags`, keeping tags added outside the stack; a change to `IdpAuthUrl` or `IdpRelayStateParameterName` is accepted with a warning and not applied, as no Studio API changes them; a rollback puts back the name, description, location and tags, but not subnets an update added, which `UpdateStudio` cannot take away; a change to a create-only property replaces the Studio and deletes the old one once the update commits), `StudioSessionMapping` (`Ref` is `StudioId|IdentityType|IdentityName`, the schema's primary identifier; `SessionPolicyArn` updates in place, and a change to any of the three others replaces the mapping) |
| EMR on EKS | `VirtualCluster` (created with `Name`, `ContainerProvider`, `SecurityConfigurationId`, `SessionEnabled` and `Tags`; a template that sets the read-only `Arn` or `Id` is refused; updated in place for `Tags` alone, which end as the template lists them, any other but an `aws:` one removed; a change to any other property replaces the virtual cluster, as the registry marks them create-only, and terminates the old one once the update commits; an update of a virtual cluster that is terminated or gone fails) |
| EMR Serverless | `Application` (created with every property, `Name` and `Type` included; updated in place through `UpdateApplication` for the settings a template changes, a dropped setting kept as it is but for `InitialCapacity`, which is cleared, and for `Tags`, which end as the template lists them, any other removed; a change to `Name` or `Type` replaces the application and deletes the old one once the update commits; neither an update nor a delete stops a `STARTED` application, so one it refuses fails the resource, as on AWS) |
+30 -2
View File
@@ -39,6 +39,7 @@ or list operations. Resource tags are not retained for post-deletion policy cond
|---|---|
| `CreateCluster` | Create a new EKS cluster |
| `DescribeCluster` | Describe a cluster by name |
| `UpdateClusterConfig` | Update a cluster's endpoint access, logging, authentication mode or upgrade policy |
| `ListClusters` | List cluster names with pagination (`maxResults` 1-100 and `nextToken`) |
| `DeleteCluster` | Delete a cluster |
| `CreateAccessEntry` | Create STANDARD or EC2_LINUX access-entry metadata |
@@ -57,7 +58,7 @@ or list operations. Resource tags are not retained for post-deletion policy cond
| `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 |
| `DescribeUpdate` | Describe an update for an addon or a cluster's configuration |
| `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 |
@@ -351,6 +352,33 @@ EKS clusters support configuring KMS envelope encryption for secrets and control
- **Component streams deviation**: AWS EKS provisions separate log streams for each component (`kube-apiserver-*`, `kube-apiserver-audit-*`, `kube-controller-manager-*`, `kube-scheduler-*`, `authenticator-*`). Because Floci runs clusters on k3s, which embeds the Kubernetes API server, controller manager, and scheduler within a single process, control plane container logs are delivered to the single `kube-apiserver-<hash>` stream when `api` is enabled, and API server audit logs are delivered to `kube-apiserver-audit-<hash>` when `audit` is enabled. Other control plane log types (`authenticator`, `controllerManager`, `scheduler`) do not provision separate streams.
- **Authenticator logs**: Authenticator webhook authentication events are logged directly by Floci.
## Upgrade policy
`CreateCluster` accepts `upgradePolicy.supportType`, `STANDARD` or `EXTENDED`, and `CreateCluster` and
`DescribeCluster` return it. A cluster created without one reports `EXTENDED`, the policy AWS gives new clusters, and
so does a cluster Floci stored before it kept the policy, as AWS gave existing clusters extended support as well.
`UpdateClusterConfig` changes it, alone in its request as EKS requires, and answers with a `Successful`
`UpgradePolicyUpdate` whose `UpgradePolicy` parameter holds the policy as JSON, `{"supportType":"STANDARD"}`, as AWS
records it. Any other support type is refused with `InvalidParameterException`.
`STANDARD` is refused for a version past its end of standard support, as on AWS. Floci keeps the Amazon EKS
Kubernetes release calendar's end of standard support for each version it serves, and treats a newer version as in
standard support. Both refusals are `InvalidParameterException`:
- `CreateCluster`: "The requested Kubernetes version "1.30" is only supported under extended support. Please change
the supportType to extended support to create the cluster."
- `UpdateClusterConfig`: "The Kubernetes version "1.30" is not in standard support. Please update the cluster to a
version in standard support to change the supportType"
`EXTENDED` is accepted on any version. A cluster created without a version is treated as in standard support, since
the version AWS gives such a cluster is, although Floci reports 1.29 for it. Floci does not upgrade a `STANDARD`
cluster when its version reaches the end of standard support, and it records an update that names the policy the
cluster already has.
In CloudFormation, `AWS::EKS::Cluster` creates the cluster with its `UpgradePolicy` and updates it in place. A
template that drops `UpgradePolicy` returns the cluster to `EXTENDED`, and a stack rollback restores the policy. A
cluster a stack created before Floci kept the policy gets the one its template declares on the stack's next update.
## EKS Auto Mode configuration
`CreateCluster` accepts EKS Auto Mode's configuration, and `CreateCluster` and `DescribeCluster` return it as it
@@ -1219,7 +1247,7 @@ eks.deleteCluster(r -> r.name("my-cluster"));
The following EKS features are not yet supported:
- `UpdateClusterVersion`
- `UpdateClusterConfig` members other than `resourcesVpcConfig` endpoint access and `publicAccessCidrs`, `logging` and `accessConfig.authenticationMode`; a different `subnetIds` or `securityGroupIds` list is refused
- `UpdateClusterConfig` members other than `resourcesVpcConfig` endpoint access and `publicAccessCidrs`, `logging`, `accessConfig.authenticationMode` and `upgradePolicy`; a different `subnetIds` or `securityGroupIds` list is refused
- `UpdateNodegroupConfig` / `UpdateNodegroupVersion`
- Add-ons (`CreateAddon`, `DescribeAddon`, `ListAddons`)
- Identity provider configs
@@ -17,6 +17,7 @@ import io.floci.aws.services.eks.model.Logging;
import io.floci.aws.services.eks.model.Nodegroup;
import io.floci.aws.services.eks.model.ResourcesVpcConfig;
import io.floci.aws.services.eks.model.UpdateClusterConfigRequest;
import io.floci.aws.services.eks.model.UpgradePolicy;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
@@ -55,7 +56,8 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
private static final List<String> NODEGROUP_ATTRIBUTES = List.of("Id", "ClusterName", "NodegroupName", "Arn");
private static final String SNAPSHOT_ATTR = CfnRollback.EKS_CLUSTER_UPDATE_SNAPSHOT_ATTR;
/** The cluster properties updateInPlace applies through UpdateClusterConfig, besides Tags. */
private static final Set<String> CLUSTER_APPLIED = Set.of("ResourcesVpcConfig", "Logging", "AccessConfig");
private static final Set<String> CLUSTER_APPLIED =
Set.of("ResourcesVpcConfig", "Logging", "AccessConfig", "UpgradePolicy");
private static final String NODEGROUP_SNAPSHOT_ATTR = CfnRollback.EKS_NODEGROUP_UPDATE_SNAPSHOT_ATTR;
// The tag keys the last deployment resolved, reserved ones included, as Ec2Tags.recordKeys records
// them, so an update removes only those and keeps a tag added outside the stack.
@@ -134,6 +136,7 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
request.setResourcesVpcConfig(createSetting(props, "ResourcesVpcConfig", ctx, new TypeReference<>() { }));
request.setAccessConfig(createSetting(props, "AccessConfig", ctx, new TypeReference<>() { }));
request.setLogging(logging(props, ctx));
request.setUpgradePolicy(createSetting(props, "UpgradePolicy", ctx, new TypeReference<>() { }));
Cluster created = eksService.createCluster(request);
// The cluster this resource named before is gone or replaced; publish writes only what the
// new one has, so its endpoint and certificate must not outlive it.
@@ -240,9 +243,9 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
/**
* The update AWS makes for the properties it does not replace on: the cluster keeps its name.
* Tags, Logging, AccessConfig.AuthenticationMode and the endpoint access members of ResourcesVpcConfig
* are applied, and only when the template's value differs from the live cluster's. EksService has no
* UpdateClusterVersion, so a changed Version is accepted with a warning and not applied. AWS lets
* Tags, Logging, AccessConfig.AuthenticationMode, UpgradePolicy and the endpoint access members of
* ResourcesVpcConfig are applied, and only when the template's value differs from the live cluster's.
* EksService has no UpdateClusterVersion, so a changed Version is accepted with a warning and not applied. AWS lets
* UpdateClusterConfig choose different subnets and security groups, but floci does not apply that, so a
* changed or dropped subnet or security group list fails the resource. The snapshot holds, and the
* rollback restores, only the config families the update changes, taken from the same read the request is
@@ -254,6 +257,7 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
// One read of the cluster: the request, the snapshot and the apply all start from it.
Cluster current = currentOr(live);
UpdateClusterConfigRequest configRequest = configRequest(props, ctx, changes, current);
UpgradePolicy unstoredPolicy = unstoredPolicy(props, ctx, changes, current);
updateTagsInPlace(r, props, ctx, live.getArn(), live.getTags(), live.getName(), TAG_KEYS_ATTR, SNAPSHOT_ATTR,
() -> publish(r, live), true, snapshot -> {
snapshot.put("name", live.getName());
@@ -262,9 +266,28 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
if (configRequest != null) {
eksService.updateClusterConfig(live.getName(), configRequest);
}
if (unstoredPolicy != null) {
eksService.restoreClusterConfig(live.getName(), null, null, null, unstoredPolicy);
}
});
}
/**
* The policy an unchanged template declares for a cluster created before Floci kept the policy, whose create
* therefore never stored it, or null. It is written as that create would have written it, without
* UpdateClusterConfig's rules, and stays when the update rolls back. A changed policy goes through
* UpdateClusterConfig instead, and a cluster that holds a policy keeps it, as one changed outside the stack does.
*/
private static UpgradePolicy unstoredPolicy(JsonNode props, ProvisionContext ctx, PropertyChanges changes,
Cluster live) {
if (live.hasStoredUpgradePolicy() || changed(changes, "UpgradePolicy")) {
return null;
}
UpgradePolicy declared = createSetting(props, "UpgradePolicy", ctx, new TypeReference<>() { });
return declared == null || !UpgradePolicy.SUPPORT_TYPES.contains(declared.supportType())
|| declared.supportType().equals(live.getUpgradePolicy().supportType()) ? null : declared;
}
/**
* Nothing create-only changed on the in-place path, so every other property the engine reports
* as added, changed or dropped is one EksService has no call to apply: it is accepted with a
@@ -345,7 +368,8 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
/**
* The UpdateClusterConfig request for the families whose changed template value differs from the live
* cluster, or null when none does. A member the template dropped is read as its AWS default: public access
* on, private access off, every address allowed and no log type exported; floci applies that default itself.
* on, private access off, every address allowed, no log type exported and extended support; floci applies that
* default itself.
* A dropped AuthenticationMode asks for nothing, as a mode cannot be moved back. The subnet and security
* group lists go along as the template has them, a dropped list counting as an empty one, so the service
* refuses one that differs from the live cluster's.
@@ -355,6 +379,7 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
ResourcesVpcConfig vpc = null;
Logging logging = null;
AccessConfig access = null;
UpgradePolicy upgradePolicy = null;
ResourcesVpcConfig current = live.getResourcesVpcConfig();
if (changed(changes, "ResourcesVpcConfig") && current != null) {
ResourcesVpcConfig desired = createSetting(props, "ResourcesVpcConfig", ctx, new TypeReference<>() { });
@@ -404,8 +429,16 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
access = new AccessConfig(desired.authenticationMode(), null);
}
}
return vpc == null && logging == null && access == null ? null
: new UpdateClusterConfigRequest(vpc, logging, access, null);
if (changed(changes, "UpgradePolicy")) {
UpgradePolicy desired = createSetting(props, "UpgradePolicy", ctx, new TypeReference<>() { });
String supportType = desired == null || desired.supportType() == null
? UpgradePolicy.EXTENDED : desired.supportType();
if (!supportType.equals(live.getUpgradePolicy().supportType())) {
upgradePolicy = new UpgradePolicy(supportType);
}
}
return vpc == null && logging == null && access == null && upgradePolicy == null ? null
: new UpdateClusterConfigRequest(vpc, logging, access, upgradePolicy, null);
}
private static boolean changed(PropertyChanges changes, String name) {
@@ -442,6 +475,9 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
&& live.getAccessConfig().authenticationMode() != null) {
snapshot.put("authenticationMode", live.getAccessConfig().authenticationMode());
}
if (request.upgradePolicy() != null) {
snapshot.set("upgradePolicy", MAPPER.valueToTree(live.getUpgradePolicy()));
}
}
/**
@@ -463,11 +499,14 @@ public class EksCfnProvisioner implements CfnResourceProvisioner {
snapshot.path("touched").forEach(key -> touched.add(key.asText()));
converge(CfnRollback.snapshotText(snapshot, "arn"), CfnRollback.snapshotTags(snapshot), touched);
String name = CfnRollback.snapshotText(snapshot, "name");
if (name != null && (snapshot.has("endpoint") || snapshot.has("logging") || snapshot.has("authenticationMode"))) {
if (name != null && (snapshot.has("endpoint") || snapshot.has("logging") || snapshot.has("authenticationMode")
|| snapshot.has("upgradePolicy"))) {
eksService.restoreClusterConfig(name,
snapshot.has("endpoint") ? MAPPER.convertValue(snapshot.get("endpoint"), ResourcesVpcConfig.class) : null,
snapshot.has("logging") ? MAPPER.convertValue(snapshot.get("logging"), Logging.class) : null,
snapshot.has("authenticationMode") ? snapshot.get("authenticationMode").asText() : null);
snapshot.has("authenticationMode") ? snapshot.get("authenticationMode").asText() : null,
snapshot.has("upgradePolicy")
? MAPPER.convertValue(snapshot.get("upgradePolicy"), UpgradePolicy.class) : null);
}
Ec2Tags.restoreRecord(r, keysAttr, snapshot);
}
@@ -61,9 +61,10 @@ public class EksController {
+ "aws(?::|%3[aA])cluster-access-policy(?:/|%2[fF])[^/]+";
private static final List<String> UPDATE_CONFIG_FAMILIES = List.of("resourcesVpcConfig", "logging", "accessConfig");
private static final List<String> UPDATE_CONFIG_FAMILIES =
List.of("resourcesVpcConfig", "logging", "accessConfig", "upgradePolicy");
private static final Set<String> UPDATE_CONFIG_MEMBERS =
Set.of("name", "clientRequestToken", "resourcesVpcConfig", "logging", "accessConfig");
Set.of("name", "clientRequestToken", "resourcesVpcConfig", "logging", "accessConfig", "upgradePolicy");
private final EksService eksService;
private final EksAccessEntryService accessEntries;
@@ -57,6 +57,7 @@ import io.floci.aws.services.eks.model.StorageConfig;
import io.floci.aws.services.eks.model.Update;
import io.floci.aws.services.eks.model.UpdateClusterConfigRequest;
import io.floci.aws.services.eks.model.UpdateParam;
import io.floci.aws.services.eks.model.UpgradePolicy;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.ApplicationScoped;
@@ -808,6 +809,9 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
throw new AwsException("InvalidParameterException", "Invalid authenticationMode", 400);
}
validateAutoMode(request.getComputeConfig(), request.getStorageConfig(), request.getKubernetesNetworkConfig());
UpgradePolicy requestedPolicy = request.getUpgradePolicy();
UpgradePolicy upgradePolicy = requestedPolicy == null || requestedPolicy.supportType() == null
? UpgradePolicy.DEFAULT : new UpgradePolicy(requireSupportType(requestedPolicy.supportType()));
AccessConfig accessConfig = new AccessConfig(authenticationMode,
requestedAccess == null || requestedAccess.bootstrapClusterCreatorAdminPermissions() == null
|| requestedAccess.bootstrapClusterCreatorAdminPermissions());
@@ -821,6 +825,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
cluster.setAccessConfig(accessConfig);
cluster.setComputeConfig(request.getComputeConfig());
cluster.setStorageConfig(request.getStorageConfig());
cluster.setUpgradePolicy(upgradePolicy);
cluster.setArn(arn);
cluster.setAccountId(accountId);
cluster.setCreatedAt(Instant.now());
@@ -845,6 +850,11 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
cluster.setVersion(DEFAULT_K8S_VERSION);
cluster.setExplicitVersion(false);
}
if (UpgradePolicy.STANDARD.equals(upgradePolicy.supportType()) && !inStandardSupport(cluster)) {
throw new AwsException("InvalidParameterException", "The requested Kubernetes version \""
+ cluster.getVersion() + "\" is only supported under extended support. Please change the "
+ "supportType to extended support to create the cluster.", 400);
}
cluster.setRoleArn(request.getRoleArn());
@@ -1042,9 +1052,10 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
Map.of("CONFIG_MAP", 0, "API_AND_CONFIG_MAP", 1, "API", 2);
/**
* UpdateClusterConfig for {@code resourcesVpcConfig} endpoint access, {@code logging} and
* {@code accessConfig.authenticationMode}. AWS accepts more members and lets the subnets and security
* groups change; floci applies these three families and refuses a different subnet or security group list.
* UpdateClusterConfig for {@code resourcesVpcConfig} endpoint access, {@code logging},
* {@code accessConfig.authenticationMode} and {@code upgradePolicy}. AWS accepts more members and lets the subnets
* and security groups change; floci applies these four families and refuses a different subnet or security group
* list.
* Each family the request names is stored as its own {@link Update} and all are returned in order. The
* REST endpoint refuses a request naming more than one family, as EKS does, so it returns the only one. The
* request is kept with the first update, and a repeat of its {@code clientRequestToken} returns that update.
@@ -1054,9 +1065,9 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
Cluster cluster = requireClusterInRequestRegion(name);
EksAddonService.requireActiveCluster(cluster);
if (request == null || (request.resourcesVpcConfig() == null && request.logging() == null
&& request.accessConfig() == null)) {
&& request.accessConfig() == null && request.upgradePolicy() == null)) {
throw new AwsException("InvalidParameterException",
"UpdateClusterConfig supports resourcesVpcConfig, logging and accessConfig only", 400);
"UpdateClusterConfig supports resourcesVpcConfig, logging, accessConfig and upgradePolicy only", 400);
}
String token = request.clientRequestToken();
if (token != null && !token.isBlank()) {
@@ -1104,6 +1115,14 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
if (requestedMode != null) {
requireForwardAuthenticationMode(mode, requestedMode);
}
String requestedSupportType = request.upgradePolicy() == null || request.upgradePolicy().supportType() == null
? null : requireSupportType(request.upgradePolicy().supportType());
// Extended support can be turned on at any time, and off only while the version is in standard support.
if (UpgradePolicy.STANDARD.equals(requestedSupportType) && !inStandardSupport(cluster)) {
throw new AwsException("InvalidParameterException", "The Kubernetes version \"" + cluster.getVersion()
+ "\" is not in standard support. Please update the cluster to a version in standard support to "
+ "change the supportType", 400);
}
Boolean finalPublicAccess = publicAccess;
Boolean finalPrivateAccess = privateAccess;
@@ -1139,13 +1158,20 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
List.of(new UpdateParam("AuthenticationMode", requestedMode)), null,
updates.isEmpty() ? request : null));
}
if (requestedSupportType != null) {
UpgradePolicy policy = new UpgradePolicy(requestedSupportType);
current.setUpgradePolicy(policy);
updates.add(addons.recordUpdate(current, "UpgradePolicyUpdate",
List.of(new UpdateParam("UpgradePolicy", json(policy))), null,
updates.isEmpty() ? request : null));
}
});
if (!saved[0]) {
throw new AwsException("ResourceNotFoundException", "No cluster found for name: " + name, 404);
}
if (updates.isEmpty()) {
throw new AwsException("InvalidParameterException",
"UpdateClusterConfig supports resourcesVpcConfig, logging and accessConfig.authenticationMode only", 400);
throw new AwsException("InvalidParameterException", "UpdateClusterConfig supports resourcesVpcConfig, "
+ "logging, accessConfig.authenticationMode and upgradePolicy.supportType only", 400);
}
LOG.infov("Updated the configuration of EKS cluster {0}: {1}", cluster.getName(),
updates.stream().map(Update::type).toList());
@@ -1165,7 +1191,8 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
&& Objects.equals(a.getEndpointPrivateAccess(), b.getEndpointPrivateAccess())
&& Objects.equals(a.getPublicAccessCidrs(), b.getPublicAccessCidrs());
return sameVpc && Objects.equals(existing.logging(), request.logging())
&& Objects.equals(existing.accessConfig(), request.accessConfig());
&& Objects.equals(existing.accessConfig(), request.accessConfig())
&& Objects.equals(existing.upgradePolicy(), request.upgradePolicy());
}
/** The cluster's current settings with the request applied on top, in the shape createCluster validates. */
@@ -1191,7 +1218,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
* authentication mode backwards, which UpdateClusterConfig refuses.
*/
public synchronized void restoreClusterConfig(String name, ResourcesVpcConfig endpoint, Logging logging,
String authenticationMode) {
String authenticationMode, UpgradePolicy upgradePolicy) {
Cluster cluster = requireClusterInRequestRegion(name);
saveClusterIfNotDeleting(regionResolver.getAccountId(), clusterKey(cluster), current -> {
if (endpoint != null && current.getResourcesVpcConfig() != null) {
@@ -1206,6 +1233,9 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
current.setAccessConfig(new AccessConfig(authenticationMode,
current.getAccessConfig().bootstrapClusterCreatorAdminPermissions()));
}
if (upgradePolicy != null) {
current.setUpgradePolicy(upgradePolicy);
}
});
}
@@ -1246,6 +1276,22 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
}
}
/**
* Whether the cluster's Kubernetes version is in standard support now. A cluster that named no version is: AWS gives
* it a version in standard support, while Floci reports {@link #DEFAULT_K8S_VERSION} for it.
*/
private static boolean inStandardSupport(Cluster cluster) {
return !cluster.isExplicitVersion() || EksVersionCalendar.inStandardSupport(cluster.getVersion(), Instant.now());
}
private static String requireSupportType(String supportType) {
if (!UpgradePolicy.SUPPORT_TYPES.contains(supportType)) {
throw new AwsException("InvalidParameterException",
"Invalid supportType '" + supportType + "'. Valid values: STANDARD | EXTENDED", 400);
}
return supportType;
}
private static void requireForwardAuthenticationMode(String current, String requested) {
Integer to = AUTHENTICATION_MODE_RANK.get(requested);
if (to == null) {
@@ -0,0 +1,34 @@
package io.floci.aws.services.eks;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.Map;
/**
* When each Kubernetes version Floci serves leaves Amazon EKS standard support, from the Amazon EKS Kubernetes release
* calendar, whose dates are UTC. 1.28 to 1.30 have left the calendar since; their dates are the ones it gave them.
*/
final class EksVersionCalendar {
private static final Map<String, LocalDate> END_OF_STANDARD_SUPPORT = Map.of(
"1.28", LocalDate.of(2024, 11, 26),
"1.29", LocalDate.of(2025, 3, 23),
"1.30", LocalDate.of(2025, 7, 23),
"1.31", LocalDate.of(2025, 11, 26),
"1.32", LocalDate.of(2026, 3, 23),
"1.33", LocalDate.of(2026, 7, 29),
"1.34", LocalDate.of(2026, 12, 2),
"1.35", LocalDate.of(2027, 3, 27),
"1.36", LocalDate.of(2027, 8, 2),
"1.37", LocalDate.of(2027, 12, 1));
private EksVersionCalendar() {
}
/** Whether {@code version} is in standard support at {@code now}. A version the calendar does not list yet is. */
static boolean inStandardSupport(String version, Instant now) {
LocalDate end = END_OF_STANDARD_SUPPORT.get(version);
return end == null || now.isBefore(end.atStartOfDay(ZoneOffset.UTC).toInstant());
}
}
@@ -158,6 +158,17 @@ public class Cluster {
@JsonProperty("storageConfig")
private StorageConfig storageConfig;
@JsonProperty("upgradePolicy")
private UpgradePolicy upgradePolicy;
/** A cluster stored before Floci kept the policy reports EKS's default, which existing clusters were given too. */
public UpgradePolicy getUpgradePolicy() { return upgradePolicy == null ? UpgradePolicy.DEFAULT : upgradePolicy; }
public void setUpgradePolicy(UpgradePolicy upgradePolicy) { this.upgradePolicy = upgradePolicy; }
/** Whether the cluster holds a policy of its own, which one stored before Floci kept the policy does not. */
@JsonIgnore
public boolean hasStoredUpgradePolicy() { return upgradePolicy != null; }
public AccessConfig getAccessConfig() { return accessConfig; }
public void setAccessConfig(AccessConfig accessConfig) { this.accessConfig = accessConfig; }
@@ -305,6 +316,7 @@ public class Cluster {
c.accessConfig = this.accessConfig;
c.computeConfig = this.computeConfig;
c.storageConfig = this.storageConfig;
c.upgradePolicy = this.upgradePolicy;
return c;
}
}
@@ -46,6 +46,12 @@ public class CreateClusterRequest {
@JsonProperty("storageConfig")
private StorageConfig storageConfig;
@JsonProperty("upgradePolicy")
private UpgradePolicy upgradePolicy;
public UpgradePolicy getUpgradePolicy() { return upgradePolicy; }
public void setUpgradePolicy(UpgradePolicy upgradePolicy) { this.upgradePolicy = upgradePolicy; }
public AccessConfig getAccessConfig() { return accessConfig; }
public void setAccessConfig(AccessConfig accessConfig) { this.accessConfig = accessConfig; }
@@ -12,5 +12,6 @@ public record UpdateClusterConfigRequest(
ResourcesVpcConfig resourcesVpcConfig,
Logging logging,
AccessConfig accessConfig,
UpgradePolicy upgradePolicy,
String clientRequestToken
) {}
@@ -0,0 +1,21 @@
package io.floci.aws.services.eks.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.Set;
/**
* A cluster's version support policy: with {@code EXTENDED} its Kubernetes version enters extended support at the end
* of standard support, with {@code STANDARD} the cluster is upgraded then instead.
*/
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public record UpgradePolicy(String supportType) {
public static final String STANDARD = "STANDARD";
public static final String EXTENDED = "EXTENDED";
public static final Set<String> SUPPORT_TYPES = Set.of(STANDARD, EXTENDED);
/** The policy EKS gives new and existing clusters. */
public static final UpgradePolicy DEFAULT = new UpgradePolicy(EXTENDED);
}
@@ -318,6 +318,7 @@ class CloudFormationEksIntegrationTest {
assertEquals(List.of("api", "audit"), cluster.getList(
"cluster.logging.clusterLogging.find { it.enabled == true }.types").stream().sorted().toList());
assertEquals("API", cluster.getString("cluster.accessConfig.authenticationMode"));
assertEquals("STANDARD", cluster.getString("cluster.upgradePolicy.supportType"));
} finally {
CfnStackWaits.deleteStack(stack);
}
@@ -336,6 +337,7 @@ class CloudFormationEksIntegrationTest {
assertEquals(true, cluster.getBoolean("cluster.resourcesVpcConfig.endpointPublicAccess"));
assertEquals("API_AND_CONFIG_MAP", cluster.getString("cluster.accessConfig.authenticationMode"));
assertEquals(List.of(), cluster.getList("cluster.logging.clusterLogging.findAll { it.enabled == true }"));
assertEquals("EXTENDED", cluster.getString("cluster.upgradePolicy.supportType"));
CfnStackWaits.updateStack(client, stack, configStack(true, false), "UPDATE_COMPLETE");
assertEquals(id, physicalId(client, stack, "Subject"));
@@ -345,6 +347,7 @@ class CloudFormationEksIntegrationTest {
assertEquals(List.of("api"),
cluster.getList("cluster.logging.clusterLogging.find { it.enabled == true }.types"));
assertEquals("API", cluster.getString("cluster.accessConfig.authenticationMode"));
assertEquals("STANDARD", cluster.getString("cluster.upgradePolicy.supportType"));
} finally {
CfnStackWaits.deleteStack(stack);
}
@@ -405,7 +408,8 @@ class CloudFormationEksIntegrationTest {
+ " \"ServiceIpv4Cidr\": \"172.20.0.0/16\"}";
private static final String SETTINGS = "\"Logging\": {\"ClusterLogging\": {\"EnabledTypes\": ["
+ "{\"Type\": \"api\"}, {\"Type\": \"audit\"}]}}, \"AccessConfig\": {\"AuthenticationMode\": \"API\"}";
+ "{\"Type\": \"api\"}, {\"Type\": \"audit\"}]}}, \"AccessConfig\": {\"AuthenticationMode\": \"API\"},"
+ " \"UpgradePolicy\": {\"SupportType\": \"STANDARD\"}";
private static String subnet(String id, String cidr, String zone) {
return "\"" + id + "\": {\"Type\": \"AWS::EC2::Subnet\", \"Properties\": {\"VpcId\": {\"Ref\": \"Vpc\"},"
@@ -421,7 +425,8 @@ class CloudFormationEksIntegrationTest {
private static String configStack(boolean updated, boolean fails) {
String settings = updated
? "\"EndpointPublicAccess\": false, \"EndpointPrivateAccess\": true}, \"Logging\": {\"ClusterLogging\": "
+ "{\"EnabledTypes\": [{\"Type\": \"api\"}]}}, \"AccessConfig\": {\"AuthenticationMode\": \"API\"}"
+ "{\"EnabledTypes\": [{\"Type\": \"api\"}]}}, \"AccessConfig\": {\"AuthenticationMode\": \"API\"},"
+ " \"UpgradePolicy\": {\"SupportType\": \"STANDARD\"}"
: "\"EndpointPublicAccess\": true}, \"AccessConfig\": {\"AuthenticationMode\": \"API_AND_CONFIG_MAP\"}";
return "{\"Resources\": {"
+ "\"Vpc\": {\"Type\": \"AWS::EC2::VPC\", \"Properties\": {\"CidrBlock\": \"10.7.0.0/16\"}},"
@@ -13,6 +13,8 @@ import io.floci.aws.services.eks.model.CreateClusterRequest;
import io.floci.aws.services.eks.model.Logging;
import io.floci.aws.services.eks.model.Nodegroup;
import io.floci.aws.services.eks.model.OidcIdentity;
import io.floci.aws.services.eks.model.UpdateClusterConfigRequest;
import io.floci.aws.services.eks.model.UpgradePolicy;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@@ -31,6 +33,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -92,7 +95,67 @@ class EksCfnProvisionerTest {
"prod", event -> { }, before, PropertyChanges.between("AWS::EKS::Cluster", true, before, after));
provisioner.provision(r, after, update);
assertTrue(provisioner.rollbackUpdate(r));
verify(eks, never()).restoreClusterConfig(any(), any(), any(), any());
verify(eks, never()).restoreClusterConfig(any(), any(), any(), any(), any());
}
@Test
void aDroppedUpgradePolicyReturnsTheClusterToExtendedSupportAndARollbackRestoresIt() throws Exception {
Cluster created = new Cluster();
created.setName("prod");
created.setArn("arn:aws:eks:us-east-1:000000000000:cluster/prod");
when(eks.createCluster(any(CreateClusterRequest.class))).thenReturn(created);
StackResource r = resource("AWS::EKS::Cluster", "Control");
JsonNode before = props("{\"Name\": \"prod\", \"RoleArn\": \"arn:aws:iam::000000000000:role/eks\", "
+ "\"UpgradePolicy\": {\"SupportType\": \"STANDARD\"}}");
provisioner.provision(r, before, ctx());
ArgumentCaptor<CreateClusterRequest> create = ArgumentCaptor.forClass(CreateClusterRequest.class);
verify(eks).createCluster(create.capture());
assertEquals(new UpgradePolicy("STANDARD"), create.getValue().getUpgradePolicy());
created.setUpgradePolicy(new UpgradePolicy("STANDARD"));
when(eks.describeCluster("prod")).thenReturn(created);
JsonNode after = props("{\"Name\": \"prod\", \"RoleArn\": \"arn:aws:iam::000000000000:role/eks\"}");
ProvisionContext update = new ProvisionContext(ctx().engine(), "us-east-1", "000000000000", "my-stack",
"prod", event -> { }, before, PropertyChanges.between("AWS::EKS::Cluster", true, before, after));
provisioner.provision(r, after, update);
verify(eks).updateClusterConfig("prod",
new UpdateClusterConfigRequest(null, null, null, new UpgradePolicy("EXTENDED"), null));
assertTrue(provisioner.rollbackUpdate(r));
verify(eks).restoreClusterConfig("prod", null, null, null, new UpgradePolicy("STANDARD"));
}
@Test
void anUnrelatedUpdateStoresThePolicyTheTemplateDeclaresForAClusterThatHoldsNone() throws Exception {
Cluster created = new Cluster();
created.setName("prod");
created.setArn("arn:aws:eks:us-east-1:000000000000:cluster/prod");
when(eks.createCluster(any(CreateClusterRequest.class))).thenReturn(created);
StackResource r = resource("AWS::EKS::Cluster", "Control");
String declared = "\"Name\": \"prod\", \"RoleArn\": \"arn:aws:iam::000000000000:role/eks\", "
+ "\"UpgradePolicy\": {\"SupportType\": \"STANDARD\"}, ";
JsonNode first = props("{" + declared + "\"Tags\": [{\"Key\": \"team\", \"Value\": \"a\"}]}");
provisioner.provision(r, first, ctx());
// A cluster created before Floci kept the policy holds none, and reports EXTENDED.
created.setTags(new HashMap<>(Map.of("team", "a")));
when(eks.describeCluster("prod")).thenReturn(created);
JsonNode second = props("{" + declared + "\"Tags\": [{\"Key\": \"team\", \"Value\": \"b\"}]}");
provisioner.provision(r, second, update(first, second));
verify(eks).restoreClusterConfig("prod", null, null, null, new UpgradePolicy("STANDARD"));
verify(eks, never()).updateClusterConfig(any(), any());
// A cluster that holds a policy keeps it, as it keeps one changed outside the stack.
created.setUpgradePolicy(new UpgradePolicy("EXTENDED"));
JsonNode third = props("{" + declared + "\"Tags\": [{\"Key\": \"team\", \"Value\": \"c\"}]}");
provisioner.provision(r, third, update(second, third));
verify(eks, times(1)).restoreClusterConfig(any(), any(), any(), any(), any());
verify(eks, never()).updateClusterConfig(any(), any());
}
private ProvisionContext update(JsonNode before, JsonNode after) {
return new ProvisionContext(ctx().engine(), "us-east-1", "000000000000", "my-stack",
"prod", event -> { }, before, PropertyChanges.between("AWS::EKS::Cluster", true, before, after));
}
@Test
@@ -197,6 +260,7 @@ class EksCfnProvisionerTest {
return node == null ? null : node.asText();
});
when(engine.resolveNode(any())).thenAnswer(inv -> inv.getArgument(0));
when(engine.omitNoValue(any())).thenAnswer(inv -> inv.getArgument(0));
when(engine.resolveStringList(any())).thenAnswer(inv -> {
JsonNode node = inv.getArgument(0);
List<String> out = new ArrayList<>();
@@ -268,6 +268,12 @@ class EksEncryptionLoggingIntegrationTest {
"{\"resourcesVpcConfig\":{\"endpointPublicAccess\":true},"
+ "\"logging\":{\"clusterLogging\":[{\"types\":[\"audit\"],\"enabled\":true}]}}"
+ "|400|InvalidParameterException|Only one type of update can be allowed.",
"{\"upgradePolicy\":{\"supportType\":\"STANDARD\"},"
+ "\"accessConfig\":{\"authenticationMode\":\"API\"}}"
+ "|400|InvalidParameterException|Only one type of update can be allowed.",
// upgradePolicy: an unknown support type, and none at all
"{\"upgradePolicy\":{\"supportType\":\"BOGUS\"}}|400|InvalidParameterException|null",
"{\"upgradePolicy\":{}}|400|InvalidParameterException|null",
// a number where the model has a boolean, as createCluster refuses it
"{\"resourcesVpcConfig\":{\"endpointPublicAccess\":1}}|400|SerializationException|null",
// members UpdateClusterConfig does not support here
@@ -295,6 +301,83 @@ class EksEncryptionLoggingIntegrationTest {
}
}
@Test
void aClusterGetsExtendedSupportUnlessItAsksForStandardAndAnUpdateChangesIt() {
String standard = "it-upgrade-standard-" + UUID.randomUUID();
String name = "it-upgrade-policy-" + UUID.randomUUID();
try {
createClusterFrom(standard, ",\"upgradePolicy\":{\"supportType\":\"STANDARD\"}");
createClusterFrom(name, "");
given().when().get("/clusters/" + standard).then().statusCode(200)
.body("cluster.upgradePolicy.supportType", equalTo("STANDARD"));
given().when().get("/clusters/" + name).then().statusCode(200)
.body("cluster.upgradePolicy.supportType", equalTo("EXTENDED"));
String id = given().contentType(JSON)
.body("{\"upgradePolicy\":{\"supportType\":\"STANDARD\"}}")
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(200)
.body("update.type", equalTo("UpgradePolicyUpdate"))
.body("update.status", equalTo("Successful"))
.body("update.params", hasSize(1))
.body("update.params[0].type", equalTo("UpgradePolicy"))
.body("update.params[0].value", equalTo("{\"supportType\":\"STANDARD\"}"))
.extract().path("update.id");
given().when().get("/clusters/" + name + "/updates/" + id).then().statusCode(200)
.body("update.type", equalTo("UpgradePolicyUpdate"));
given().when().get("/clusters/" + name).then().statusCode(200)
.body("cluster.upgradePolicy.supportType", equalTo("STANDARD"));
} finally {
deleteCluster(standard);
deleteCluster(name);
}
}
@Test
void standardSupportIsRefusedOnAVersionPastItsEndOfStandardSupport() {
String name = "it-upgrade-retired-" + UUID.randomUUID();
try {
given().contentType(JSON)
.body("{\"name\":\"" + name + "\",\"roleArn\":\"" + ROLE_ARN + "\",\"version\":\"1.30\","
+ "\"upgradePolicy\":{\"supportType\":\"STANDARD\"}}")
.when().post("/clusters")
.then().statusCode(400).body("__type", equalTo("InvalidParameterException"))
.body("message", equalTo("The requested Kubernetes version \"1.30\" is only supported under "
+ "extended support. Please change the supportType to extended support to create the "
+ "cluster."));
createClusterFrom(name, ",\"version\":\"1.30\"");
given().contentType(JSON)
.body("{\"upgradePolicy\":{\"supportType\":\"STANDARD\"}}")
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(400).body("__type", equalTo("InvalidParameterException"))
.body("message", equalTo("The Kubernetes version \"1.30\" is not in standard support. Please "
+ "update the cluster to a version in standard support to change the supportType"));
given().when().get("/clusters/" + name).then().statusCode(200)
.body("cluster.upgradePolicy.supportType", equalTo("EXTENDED"));
} finally {
deleteCluster(name);
}
}
@Test
void aClientRequestTokenReusedForAnotherUpgradePolicyIsRefused() {
String name = createClusterFrom("it-upgrade-token-" + UUID.randomUUID(), "");
try {
given().contentType(JSON)
.body("{\"clientRequestToken\":\"policy-1\",\"upgradePolicy\":{\"supportType\":\"STANDARD\"}}")
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(200);
given().contentType(JSON)
.body("{\"clientRequestToken\":\"policy-1\",\"upgradePolicy\":{\"supportType\":\"EXTENDED\"}}")
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(400).body("__type", equalTo("InvalidParameterException"));
given().when().get("/clusters/" + name).then().statusCode(200)
.body("cluster.upgradePolicy.supportType", equalTo("STANDARD"));
} finally {
deleteCluster(name);
}
}
@Test
void updateConfigWithTheSameClientRequestTokenReturnsTheSameUpdate() {
String name = createClusterFrom("it-update-idempotent-" + UUID.randomUUID(), "");
@@ -52,6 +52,8 @@ import io.floci.aws.services.eks.model.ResourcesVpcConfig;
import io.floci.aws.services.eks.model.StorageConfig;
import io.floci.aws.services.eks.model.Update;
import io.floci.aws.services.eks.model.UpdateClusterConfigRequest;
import io.floci.aws.services.eks.model.UpdateParam;
import io.floci.aws.services.eks.model.UpgradePolicy;
import io.floci.aws.testing.ThreadStates;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -85,6 +87,7 @@ import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
@@ -938,7 +941,7 @@ class EksServiceTest {
vpc.setEndpointPublicAccess(false);
vpc.setPublicAccessCidrs(List.of(cidr));
AwsException e = assertThrows(AwsException.class, () -> service.updateClusterConfig(
"cidr-cluster", new UpdateClusterConfigRequest(vpc, null, null, null)), cidr);
"cidr-cluster", new UpdateClusterConfigRequest(vpc, null, null, null, null)), cidr);
assertEquals("InvalidParameterException", e.getErrorCode(), cidr);
ResourcesVpcConfig stored = service.describeCluster("cidr-cluster").getResourcesVpcConfig();
assertEquals(Boolean.TRUE, stored.getEndpointPublicAccess(), cidr);
@@ -947,6 +950,102 @@ class EksServiceTest {
verify(addons, never()).recordUpdate(any(), anyString(), any(), any(), any());
}
@Test
void createClusterGivesExtendedSupportUnlessTheRequestAsksForStandard() {
CreateClusterRequest noSupportType = new CreateClusterRequest();
noSupportType.setName("policy-default");
noSupportType.setRoleArn("arn:aws:iam::000000000000:role/eks-role");
noSupportType.setUpgradePolicy(new UpgradePolicy(null));
assertEquals(new UpgradePolicy("EXTENDED"), eksService.createCluster(noSupportType).getUpgradePolicy());
CreateClusterRequest standard = new CreateClusterRequest();
standard.setName("policy-standard");
standard.setRoleArn("arn:aws:iam::000000000000:role/eks-role");
standard.setUpgradePolicy(new UpgradePolicy("STANDARD"));
eksService.createCluster(standard);
assertEquals(new UpgradePolicy("STANDARD"), eksService.describeCluster("policy-standard").getUpgradePolicy());
CreateClusterRequest bogus = new CreateClusterRequest();
bogus.setName("policy-bogus");
bogus.setRoleArn("arn:aws:iam::000000000000:role/eks-role");
bogus.setUpgradePolicy(new UpgradePolicy("standard"));
AwsException e = assertThrows(AwsException.class, () -> eksService.createCluster(bogus));
assertEquals("InvalidParameterException", e.getErrorCode());
assertEquals("Invalid supportType 'standard'. Valid values: STANDARD | EXTENDED", e.getMessage());
assertFalse(eksService.listClusters().contains("policy-bogus"));
}
@Test
void standardSupportIsRefusedForAVersionPastItsEndOfStandardSupport() {
CreateClusterRequest create = new CreateClusterRequest();
create.setName("policy-retired");
create.setRoleArn("arn:aws:iam::000000000000:role/eks-role");
create.setVersion("1.30");
create.setUpgradePolicy(new UpgradePolicy("STANDARD"));
AwsException refused = assertThrows(AwsException.class, () -> eksService.createCluster(create));
assertEquals("InvalidParameterException", refused.getErrorCode());
assertEquals("The requested Kubernetes version \"1.30\" is only supported under extended support. "
+ "Please change the supportType to extended support to create the cluster.", refused.getMessage());
assertFalse(eksService.listClusters().contains("policy-retired"));
create.setUpgradePolicy(null);
eksService.createCluster(create);
AwsException update = assertThrows(AwsException.class, () -> eksService.updateClusterConfig("policy-retired",
new UpdateClusterConfigRequest(null, null, null, new UpgradePolicy("STANDARD"), null)));
assertEquals("InvalidParameterException", update.getErrorCode());
assertEquals("The Kubernetes version \"1.30\" is not in standard support. Please update the cluster to a "
+ "version in standard support to change the supportType", update.getMessage());
assertEquals(new UpgradePolicy("EXTENDED"), eksService.describeCluster("policy-retired").getUpgradePolicy());
}
@Test
void standardSupportIsAcceptedForAVersionTheCalendarDoesNotListYet() {
CreateClusterRequest create = new CreateClusterRequest();
create.setName("policy-newest");
create.setRoleArn("arn:aws:iam::000000000000:role/eks-role");
create.setVersion("1.38");
create.setUpgradePolicy(new UpgradePolicy("STANDARD"));
assertEquals(new UpgradePolicy("STANDARD"), eksService.createCluster(create).getUpgradePolicy());
}
@Test
void aClusterStoredBeforeFlociKeptTheUpgradePolicyReportsExtendedSupport() throws Exception {
// AWS gave existing clusters extended support too.
ObjectMapper mapper = new ObjectMapper();
Cluster stored = mapper.readValue("{\"name\":\"old\"}", Cluster.class);
assertEquals("EXTENDED", mapper.valueToTree(stored).path("upgradePolicy").path("supportType").asText());
}
@Test
void updateClusterConfigRecordsTheUpgradePolicyAsJsonAndRefusesAnUnknownSupportType() {
EksAddonService addons = mock(EksAddonService.class);
Update recorded = new Update("u", "Successful", "UpgradePolicyUpdate", List.of(), 0, List.of());
when(addons.recordUpdate(any(), anyString(), any(), any(), any())).thenReturn(recorded);
EksService service = new EksService(storageFactory, testConfig(), regionResolver, null, ec2Service,
new EksOidcService(storageFactory, new ObjectMapper()), mock(EksAccessEntryService.class),
mock(EksPodIdentityAssociationService.class), addons);
CreateClusterRequest create = new CreateClusterRequest();
create.setName("policy-update");
create.setRoleArn("arn:aws:iam::000000000000:role/eks-role");
service.createCluster(create);
AwsException e = assertThrows(AwsException.class, () -> service.updateClusterConfig("policy-update",
new UpdateClusterConfigRequest(null, null, null, new UpgradePolicy("LONG"), null)));
assertEquals("InvalidParameterException", e.getErrorCode());
assertEquals(new UpgradePolicy("EXTENDED"), service.describeCluster("policy-update").getUpgradePolicy());
verify(addons, never()).recordUpdate(any(), anyString(), any(), any(), any());
UpdateClusterConfigRequest request =
new UpdateClusterConfigRequest(null, null, null, new UpgradePolicy("STANDARD"), null);
service.updateClusterConfig("policy-update", request);
verify(addons).recordUpdate(any(), eq("UpgradePolicyUpdate"),
eq(List.of(new UpdateParam("UpgradePolicy", "{\"supportType\":\"STANDARD\"}"))), any(), eq(request));
assertEquals(new UpgradePolicy("STANDARD"), service.describeCluster("policy-update").getUpgradePolicy());
}
@Test
void updateClusterConfigMovesTheAuthenticationModeOneStepForwardOnly() {
EksAddonService addons = mock(EksAddonService.class);
@@ -966,7 +1065,7 @@ class EksServiceTest {
create.setAccessConfig(new AccessConfig(modes.get(from), null));
service.createCluster(create);
UpdateClusterConfigRequest request = new UpdateClusterConfigRequest(
null, null, new AccessConfig(modes.get(to), null), null);
null, null, new AccessConfig(modes.get(to), null), null, null);
if (to == from + 1) {
service.updateClusterConfig(name, request);
assertEquals(modes.get(to), service.describeCluster(name).getAccessConfig()
@@ -0,0 +1,23 @@
package io.floci.aws.services.eks;
import org.junit.jupiter.api.Test;
import java.time.Instant;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class EksVersionCalendarTest {
@Test
void aVersionLeavesStandardSupportAtTheStartOfItsEndDateInUtc() {
assertTrue(EksVersionCalendar.inStandardSupport("1.31", Instant.parse("2025-11-25T23:59:59Z")));
assertFalse(EksVersionCalendar.inStandardSupport("1.31", Instant.parse("2025-11-26T00:00:00Z")));
assertFalse(EksVersionCalendar.inStandardSupport("1.28", Instant.parse("2026-11-23T00:00:00Z")));
}
@Test
void aVersionTheCalendarDoesNotListYetIsInStandardSupport() {
assertTrue(EksVersionCalendar.inStandardSupport("1.38", Instant.parse("2030-01-01T00:00:00Z")));
}
}
@@ -301,7 +301,6 @@ AWS::EKS::Cluster OutpostConfig accepted and ignored
AWS::EKS::Cluster RemoteNetworkConfig accepted and ignored
AWS::EKS::Cluster RollbackConfig accepted and ignored
AWS::EKS::Cluster StorageConfig accepted and ignored
AWS::EKS::Cluster UpgradePolicy accepted and ignored
AWS::EKS::Cluster ZonalShiftConfig accepted and ignored
AWS::EKS::Nodegroup AmiType accepted and ignored
AWS::EKS::Nodegroup CapacityType accepted and ignored
1 AWS::ApiGateway::ApiKey StageKeys accepted and ignored, as the ApiGatewayApiKeyCfnProvisioner javadoc records
301 AWS::EKS::Cluster RemoteNetworkConfig accepted and ignored
302 AWS::EKS::Cluster RollbackConfig accepted and ignored
303 AWS::EKS::Cluster StorageConfig accepted and ignored
AWS::EKS::Cluster UpgradePolicy accepted and ignored
304 AWS::EKS::Cluster ZonalShiftConfig accepted and ignored
305 AWS::EKS::Nodegroup AmiType accepted and ignored
306 AWS::EKS::Nodegroup CapacityType accepted and ignored
+1 -1
View File
@@ -236,7 +236,7 @@ notes:
AWS::CDK::Metadata: accepted; no-op
AWS::Transfer::Server: 'management plane only; Ref returns the server ARN; Arn, ServerId and State attributes supported; AS2 managed egress IPs are not modeled; Domain replacement and IdentityProviderType changes are not supported'
AWS::Transfer::User: 'management plane only; Ref returns the user ARN; Arn attribute supported; Policy and PosixProfile are not supported; a ServerId or UserName change replaces the user'
AWS::EKS::Cluster: 'created with `Name`, `Version`, `RoleArn`, `Tags`, `EncryptionConfig`, `ResourcesVpcConfig`, `Logging`, `AccessConfig` and `KubernetesNetworkConfig.IpFamily` and `ServiceIpv4Cidr`, a replacement included; a change to `EncryptionConfig`, `IpFamily` or `ServiceIpv4Cidr` replaces the cluster with the new value applied; `ElasticLoadBalancing`, `ServiceIpv6Cidr` and `ResourcesVpcConfig.ControlPlaneEgressMode` are accepted and ignored; updated in place for `Tags`, keeping tags added outside the stack, for `Logging`, for `AccessConfig.AuthenticationMode` (a mode cannot be moved back, so a stack update that does so fails, and a stack rollback restores it) and for `ResourcesVpcConfig` endpoint access and `PublicAccessCidrs`; a change to `Name`, `RoleArn`, `EncryptionConfig`, `BootstrapSelfManagedAddons`, `OutpostConfig`, `AccessConfig.BootstrapClusterCreatorAdminPermissions`, `KubernetesNetworkConfig.IpFamily` or `KubernetesNetworkConfig.ServiceIpv4Cidr` replaces the cluster, as the registry marks them create-only, and deletes the old one once the update commits; a change to `Version` is accepted with a warning and not applied, as the emulator has no `UpdateClusterVersion`; a change to the subnets or security groups of `ResourcesVpcConfig` fails the resource, as the emulator''s `UpdateClusterConfig` does not change them'
AWS::EKS::Cluster: 'created with `Name`, `Version`, `RoleArn`, `Tags`, `EncryptionConfig`, `ResourcesVpcConfig`, `Logging`, `AccessConfig`, `UpgradePolicy` and `KubernetesNetworkConfig.IpFamily` and `ServiceIpv4Cidr`, a replacement included; a change to `EncryptionConfig`, `IpFamily` or `ServiceIpv4Cidr` replaces the cluster with the new value applied; `ElasticLoadBalancing`, `ServiceIpv6Cidr` and `ResourcesVpcConfig.ControlPlaneEgressMode` are accepted and ignored; updated in place for `Tags`, keeping tags added outside the stack, for `Logging`, for `AccessConfig.AuthenticationMode` (a mode cannot be moved back, so a stack update that does so fails, and a stack rollback restores it), for `UpgradePolicy` (a dropped one returns the cluster to `EXTENDED`) and for `ResourcesVpcConfig` endpoint access and `PublicAccessCidrs`; a change to `Name`, `RoleArn`, `EncryptionConfig`, `BootstrapSelfManagedAddons`, `OutpostConfig`, `AccessConfig.BootstrapClusterCreatorAdminPermissions`, `KubernetesNetworkConfig.IpFamily` or `KubernetesNetworkConfig.ServiceIpv4Cidr` replaces the cluster, as the registry marks them create-only, and deletes the old one once the update commits; a change to `Version` is accepted with a warning and not applied, as the emulator has no `UpdateClusterVersion`; a change to the subnets or security groups of `ResourcesVpcConfig` fails the resource, as the emulator''s `UpdateClusterConfig` does not change them'
AWS::EKS::Nodegroup: 'created with `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets` and `Tags`; updated in place for `Tags`, keeping tags added outside the stack; a change to `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets`, `AmiType`, `CapacityType`, `DiskSize`, `InstanceTypes` or `RemoteAccess` replaces the nodegroup, as the registry marks them create-only, and deletes the old one once the update commits; `ScalingConfig`, `Labels`, `Taints`, `UpdateConfig`, `Version`, `ReleaseVersion`, `ForceUpdateEnabled`, `LaunchTemplate`, `NodeRepairConfig` and `WarmPoolConfig` are accepted and not applied, whether changed or dropped, with a warning, as the emulator cannot update a nodegroup in place'
AWS::EMR::Cluster: 'created through `RunJobFlow`, once it is waiting or running, its master, core and task groups or fleets as `RunJobFlow`''s `InstanceGroups` or `InstanceFleets`; `AdditionalInfo` and `Instances`'' `HadoopVersion` are accepted with a warning and not stored; task groups and fleets need unique names; a template that sets the read-only `Id` or `MasterPublicDNS` is refused; updated in place for `AutoTerminationPolicy`, `ManagedScalingPolicy`, `StepConcurrencyLevel`, `VisibleToAllUsers`, `Tags` (keeping tags added outside the stack), `TerminationProtected`, `UnhealthyNodeReplacement`, a core or task group''s `InstanceCount` and `AutoScalingPolicy` and a core or task fleet''s target capacities, a dropped one taking its default; any other change, within `Instances` included, replaces the cluster and terminates the old one once the update commits; a termination-protected cluster refuses the delete'
AWS::EMR::InstanceFleetConfig: 'a `TASK` fleet, the one type the reference allows, added through `AddInstanceFleet`; `TargetOnDemandCapacity`, `TargetSpotCapacity`, `InstanceTypeConfigs` and `ResizeSpecifications` update in place through `ModifyInstanceFleet`, and a create-only change adds a new fleet; a rollback puts them back, but not an instance type the update added, which every later `ModifyInstanceFleet` must include, nor resize specifications where the fleet had none, which no request can clear, and dropped configs or resize specifications are kept for the same reason; the delete shrinks the fleet to nothing, as a fleet cannot be removed from its cluster'