mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(eks): turn EKS Auto Mode on and off with UpdateClusterConfig (#9264)
UpdateClusterConfig accepts computeConfig, storageConfig and kubernetesNetworkConfig.elasticLoadBalancing together as one AutoModeUpdate family. The cluster stores the result for DescribeCluster, and the update is recorded for DescribeUpdate and clientRequestToken replay.
A member the request omits keeps its stored value, and the request is checked against the configuration it leaves: the three capabilities on or off together, node pools named with a node role, the node role unchanged while compute stays on, and a request that changes nothing refused with "No changes needed for EKS Auto Mode configuration provided". An omitted node role keeps the stored one, so {"enabled": true, "nodePools": []} turns off the built-in node pools as in the AWS user guide.
Other kubernetesNetworkConfig and elasticLoadBalancing members, gatewayApi among them, are refused as unsupported. A null node pool is refused on CreateCluster and UpdateClusterConfig instead of failing with a server error.
Part of #8914.
This commit is contained in:
1 parent
a7d3108134
commit
16c2505a25
4 files changed
+356
-12
No files matched your search
@@ -63,8 +63,10 @@ public class EksController {
|
||||
|
||||
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", "upgradePolicy");
|
||||
/** The members that together make one EKS Auto Mode update. */
|
||||
private static final List<String> AUTO_MODE_MEMBERS = List.of("computeConfig", "storageConfig", "kubernetesNetworkConfig");
|
||||
private static final Set<String> UPDATE_CONFIG_MEMBERS = Set.of("name", "clientRequestToken", "resourcesVpcConfig",
|
||||
"logging", "accessConfig", "upgradePolicy", "computeConfig", "storageConfig", "kubernetesNetworkConfig");
|
||||
|
||||
private final EksService eksService;
|
||||
private final EksAccessEntryService accessEntries;
|
||||
@@ -367,7 +369,24 @@ public class EksController {
|
||||
"Floci does not support updating " + member + " through UpdateClusterConfig yet", 400);
|
||||
}
|
||||
}
|
||||
if (UPDATE_CONFIG_FAMILIES.stream().filter(body::has).count() > 1) {
|
||||
JsonNode network = body.path("kubernetesNetworkConfig");
|
||||
for (String member : (Iterable<String>) network::fieldNames) {
|
||||
if (!"elasticLoadBalancing".equals(member)) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Floci does not support updating kubernetesNetworkConfig." + member
|
||||
+ " through UpdateClusterConfig yet", 400);
|
||||
}
|
||||
}
|
||||
for (String member : (Iterable<String>) network.path("elasticLoadBalancing")::fieldNames) {
|
||||
if (!"enabled".equals(member)) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Floci does not support updating kubernetesNetworkConfig.elasticLoadBalancing." + member
|
||||
+ " through UpdateClusterConfig yet", 400);
|
||||
}
|
||||
}
|
||||
long families = UPDATE_CONFIG_FAMILIES.stream().filter(body::has).count()
|
||||
+ (AUTO_MODE_MEMBERS.stream().anyMatch(body::has) ? 1 : 0);
|
||||
if (families > 1) {
|
||||
throw new AwsException("InvalidParameterException", "Only one type of update can be allowed.", 400);
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -41,6 +41,7 @@ import io.floci.aws.services.eks.model.ComputeConfig;
|
||||
import io.floci.aws.services.eks.model.CreateClusterRequest;
|
||||
import io.floci.aws.services.eks.model.CreateFargateProfileRequest;
|
||||
import io.floci.aws.services.eks.model.CreateNodeGroupRequest;
|
||||
import io.floci.aws.services.eks.model.ElasticLoadBalancing;
|
||||
import io.floci.aws.services.eks.model.EncryptionConfig;
|
||||
import io.floci.aws.services.eks.model.FargateProfile;
|
||||
import io.floci.aws.services.eks.model.FargateProfileStatus;
|
||||
@@ -776,19 +777,32 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
*/
|
||||
private static void validateAutoMode(ComputeConfig compute, StorageConfig storage,
|
||||
KubernetesNetworkConfig network) {
|
||||
requireCapabilitiesTogether(compute, storage, elasticLoadBalancing(network));
|
||||
requireNodePoolsWithRole(compute);
|
||||
}
|
||||
|
||||
/** The compute, block storage and load balancing capabilities are on together or off together. */
|
||||
private static void requireCapabilitiesTogether(ComputeConfig compute, StorageConfig storage,
|
||||
ElasticLoadBalancing loadBalancing) {
|
||||
boolean computeEnabled = compute != null && Boolean.TRUE.equals(compute.enabled());
|
||||
boolean blockStorageEnabled = storage != null && storage.blockStorage() != null
|
||||
&& Boolean.TRUE.equals(storage.blockStorage().enabled());
|
||||
boolean loadBalancingEnabled = network != null && network.getElasticLoadBalancing() != null
|
||||
&& Boolean.TRUE.equals(network.getElasticLoadBalancing().enabled());
|
||||
boolean loadBalancingEnabled = loadBalancing != null && Boolean.TRUE.equals(loadBalancing.enabled());
|
||||
if (computeEnabled != blockStorageEnabled || computeEnabled != loadBalancingEnabled) {
|
||||
throw new AwsException("InvalidParameterException", "For EKS Auto Mode, please ensure that all "
|
||||
+ "required configs, including computeConfig, kubernetesNetworkConfig, and blockStorage are "
|
||||
+ "all either fully enabled or fully disabled.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
/** Node pools launch their nodes with the node role, so a compute configuration naming pools names it. */
|
||||
private static void requireNodePoolsWithRole(ComputeConfig compute) {
|
||||
if (compute == null) {
|
||||
return;
|
||||
}
|
||||
if (compute.nodePools() != null && compute.nodePools().stream().anyMatch(Objects::isNull)) {
|
||||
throw new AwsException("InvalidParameterException", "nodePools must not contain null", 400);
|
||||
}
|
||||
boolean hasNodePools = compute.nodePools() != null && !compute.nodePools().isEmpty();
|
||||
boolean hasNodeRole = compute.nodeRoleArn() != null && !compute.nodeRoleArn().isEmpty();
|
||||
if (hasNodePools && !hasNodeRole) {
|
||||
@@ -1065,9 +1079,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.upgradePolicy() == null)) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"UpdateClusterConfig supports resourcesVpcConfig, logging, accessConfig and upgradePolicy only", 400);
|
||||
&& request.accessConfig() == null && request.upgradePolicy() == null && !request.changesAutoMode())) {
|
||||
throw new AwsException("InvalidParameterException", "UpdateClusterConfig supports resourcesVpcConfig, "
|
||||
+ "logging, accessConfig, upgradePolicy and the EKS Auto Mode configuration only", 400);
|
||||
}
|
||||
String token = request.clientRequestToken();
|
||||
if (token != null && !token.isBlank()) {
|
||||
@@ -1123,6 +1137,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
+ "\" is not in standard support. Please update the cluster to a version in standard support to "
|
||||
+ "change the supportType", 400);
|
||||
}
|
||||
AutoMode nextAutoMode = request.changesAutoMode() ? requireAutoModeChange(cluster, request) : null;
|
||||
|
||||
Boolean finalPublicAccess = publicAccess;
|
||||
Boolean finalPrivateAccess = privateAccess;
|
||||
@@ -1165,13 +1180,18 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
List.of(new UpdateParam("UpgradePolicy", json(policy))), null,
|
||||
updates.isEmpty() ? request : null));
|
||||
}
|
||||
if (nextAutoMode != null) {
|
||||
updates.add(addons.recordUpdate(current, "AutoModeUpdate", applyAutoMode(current, nextAutoMode, request), 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, accessConfig.authenticationMode and upgradePolicy.supportType only", 400);
|
||||
+ "logging, accessConfig.authenticationMode, upgradePolicy.supportType and the EKS Auto Mode "
|
||||
+ "configuration only", 400);
|
||||
}
|
||||
LOG.infov("Updated the configuration of EKS cluster {0}: {1}", cluster.getName(),
|
||||
updates.stream().map(Update::type).toList());
|
||||
@@ -1192,7 +1212,98 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
&& Objects.equals(a.getPublicAccessCidrs(), b.getPublicAccessCidrs());
|
||||
return sameVpc && Objects.equals(existing.logging(), request.logging())
|
||||
&& Objects.equals(existing.accessConfig(), request.accessConfig())
|
||||
&& Objects.equals(existing.upgradePolicy(), request.upgradePolicy());
|
||||
&& Objects.equals(existing.upgradePolicy(), request.upgradePolicy())
|
||||
&& Objects.equals(existing.computeConfig(), request.computeConfig())
|
||||
&& Objects.equals(existing.storageConfig(), request.storageConfig())
|
||||
&& Objects.equals(elasticLoadBalancing(existing.kubernetesNetworkConfig()),
|
||||
elasticLoadBalancing(request.kubernetesNetworkConfig()));
|
||||
}
|
||||
|
||||
private static ElasticLoadBalancing elasticLoadBalancing(KubernetesNetworkConfig network) {
|
||||
return network == null ? null : network.getElasticLoadBalancing();
|
||||
}
|
||||
|
||||
/** The cluster's EKS Auto Mode configuration: its compute, block storage and load balancing capabilities. */
|
||||
private record AutoMode(ComputeConfig compute, StorageConfig storage, ElasticLoadBalancing loadBalancing) {
|
||||
|
||||
boolean computeOn() {
|
||||
return compute != null && Boolean.TRUE.equals(compute.enabled());
|
||||
}
|
||||
|
||||
/** What it turns on, for telling whether a request changes it: off, or on with its pools and role. */
|
||||
List<Object> state() {
|
||||
if (!computeOn()) {
|
||||
return List.of(false);
|
||||
}
|
||||
return List.of(true, compute.nodePools() == null ? Set.of() : Set.copyOf(compute.nodePools()),
|
||||
String.valueOf(compute.nodeRoleArn()),
|
||||
storage != null && storage.blockStorage() != null
|
||||
&& Boolean.TRUE.equals(storage.blockStorage().enabled()),
|
||||
loadBalancing != null && Boolean.TRUE.equals(loadBalancing.enabled()));
|
||||
}
|
||||
}
|
||||
|
||||
private static AutoMode autoMode(Cluster cluster) {
|
||||
return new AutoMode(cluster.getComputeConfig(), cluster.getStorageConfig(),
|
||||
elasticLoadBalancing(cluster.getKubernetesNetworkConfig()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The cluster's EKS Auto Mode configuration once {@code request} applies, refusing the changes AWS refuses. A
|
||||
* member the request omits keeps its stored value, so the three capabilities are checked together as they will
|
||||
* be stored. Node pools and the node role are checked as the request names them, as {@code CreateCluster}
|
||||
* checks them: AWS's own example turns off the built-in pools with {@code "nodePools": []} and no role. The
|
||||
* node role can't change while the compute capability is on (botocore's ComputeConfigRequest: "This value
|
||||
* cannot be changed after the compute capability of EKS Auto Mode is enabled"), so a request that omits it
|
||||
* keeps it. A request that changes nothing is refused with the error EKS answers it.
|
||||
*/
|
||||
private static AutoMode requireAutoModeChange(Cluster cluster, UpdateClusterConfigRequest request) {
|
||||
AutoMode current = autoMode(cluster);
|
||||
ComputeConfig requested = request.computeConfig();
|
||||
ComputeConfig compute = current.compute();
|
||||
if (requested != null) {
|
||||
requireNodePoolsWithRole(requested);
|
||||
boolean staysOn = current.computeOn() && Boolean.TRUE.equals(requested.enabled());
|
||||
String role = requested.nodeRoleArn();
|
||||
if (staysOn && role != null && !role.isEmpty() && !role.equals(current.compute().nodeRoleArn())) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"nodeRoleArn cannot be changed after the compute capability of EKS Auto Mode is enabled", 400);
|
||||
}
|
||||
compute = staysOn && (role == null || role.isEmpty())
|
||||
? new ComputeConfig(requested.enabled(), requested.nodePools(), current.compute().nodeRoleArn())
|
||||
: requested;
|
||||
}
|
||||
ElasticLoadBalancing requestedLoadBalancing = elasticLoadBalancing(request.kubernetesNetworkConfig());
|
||||
AutoMode next = new AutoMode(compute,
|
||||
request.storageConfig() != null ? request.storageConfig() : current.storage(),
|
||||
requestedLoadBalancing != null ? requestedLoadBalancing : current.loadBalancing());
|
||||
requireCapabilitiesTogether(next.compute(), next.storage(), next.loadBalancing());
|
||||
if (current.state().equals(next.state())) {
|
||||
throw new AwsException("InvalidRequestException",
|
||||
"No changes needed for EKS Auto Mode configuration provided", 400);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
/** Stores {@code next}, and returns the Auto Mode members the request names as the update's parameters. */
|
||||
private static List<UpdateParam> applyAutoMode(Cluster cluster, AutoMode next, UpdateClusterConfigRequest request) {
|
||||
cluster.setComputeConfig(next.compute());
|
||||
cluster.setStorageConfig(next.storage());
|
||||
if (cluster.getKubernetesNetworkConfig() != null) {
|
||||
cluster.getKubernetesNetworkConfig().setElasticLoadBalancing(next.loadBalancing());
|
||||
}
|
||||
List<UpdateParam> params = new ArrayList<>();
|
||||
if (request.computeConfig() != null) {
|
||||
params.add(new UpdateParam("ComputeConfig", json(request.computeConfig())));
|
||||
}
|
||||
if (request.storageConfig() != null) {
|
||||
params.add(new UpdateParam("StorageConfig", json(request.storageConfig())));
|
||||
}
|
||||
ElasticLoadBalancing loadBalancing = elasticLoadBalancing(request.kubernetesNetworkConfig());
|
||||
if (loadBalancing != null) {
|
||||
params.add(new UpdateParam("KubernetesNetworkConfig", json(Map.of("elasticLoadBalancing", loadBalancing))));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
/** The cluster's current settings with the request applied on top, in the shape createCluster validates. */
|
||||
|
||||
@@ -5,6 +5,8 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/**
|
||||
* The members of UpdateClusterConfig that floci applies. The REST controller refuses any other member.
|
||||
* {@code computeConfig}, {@code storageConfig} and {@code kubernetesNetworkConfig} turn EKS Auto Mode on or off
|
||||
* together, and of {@code kubernetesNetworkConfig} only {@code elasticLoadBalancing} is applied.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@@ -13,5 +15,21 @@ public record UpdateClusterConfigRequest(
|
||||
Logging logging,
|
||||
AccessConfig accessConfig,
|
||||
UpgradePolicy upgradePolicy,
|
||||
String clientRequestToken
|
||||
) {}
|
||||
String clientRequestToken,
|
||||
ComputeConfig computeConfig,
|
||||
StorageConfig storageConfig,
|
||||
KubernetesNetworkConfig kubernetesNetworkConfig
|
||||
) {
|
||||
|
||||
/** As above, with no EKS Auto Mode change. */
|
||||
public UpdateClusterConfigRequest(ResourcesVpcConfig resourcesVpcConfig, Logging logging,
|
||||
AccessConfig accessConfig, UpgradePolicy upgradePolicy,
|
||||
String clientRequestToken) {
|
||||
this(resourcesVpcConfig, logging, accessConfig, upgradePolicy, clientRequestToken, null, null, null);
|
||||
}
|
||||
|
||||
/** Whether the request names any of the EKS Auto Mode members. */
|
||||
public boolean changesAutoMode() {
|
||||
return computeConfig != null || storageConfig != null || kubernetesNetworkConfig != null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user