mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
feat(eks): size the k3s node from a configured instance type while the API keeps the node group's type (#7773)
This commit is contained in:
1 parent
755eee683d
commit
5d086210b2
5 files changed
+143
-6
No files matched your search
@@ -3755,6 +3755,14 @@ public interface EmulatorConfig {
|
||||
@WithDefault("0")
|
||||
int maxVcpus();
|
||||
|
||||
/**
|
||||
* Optional EC2 catalog instance type the k3s node container is sized from, in place of its
|
||||
* first node group's type. The node group, the node's {@code node.kubernetes.io/instance-type}
|
||||
* label and the synthesized EC2 instance keep the requested type. A type absent from the
|
||||
* catalog is ignored with a warning; {@link #maxMemoryMib()} and {@link #maxVcpus()} still apply.
|
||||
*/
|
||||
Optional<String> nodeInstanceType();
|
||||
|
||||
@WithDefault("k3s")
|
||||
String provider();
|
||||
|
||||
|
||||
@@ -1152,7 +1152,7 @@ public class EksClusterManager
|
||||
private EksNodeCapacity.Limits resolveNodeCapacity(Cluster cluster) {
|
||||
try {
|
||||
Info host = lifecycleManager.getDockerClient().infoCmd().exec();
|
||||
CatalogInstanceType type = instanceTypeCatalog.find(nodeInstanceType(cluster)).orElseThrow();
|
||||
CatalogInstanceType type = instanceTypeCatalog.find(sizingInstanceType(cluster)).orElseThrow();
|
||||
EksNodeCapacity.Limits limits = EksNodeCapacity.calculate(type, host.getMemTotal(), host.getNCPU(),
|
||||
config.services().eks().maxMemoryMib(), config.services().eks().maxVcpus());
|
||||
if (limits == null) {
|
||||
@@ -1181,7 +1181,7 @@ public class EksClusterManager
|
||||
if (maxMemoryMib <= 0 && maxVcpus <= 0) {
|
||||
return null;
|
||||
}
|
||||
int vcpus = instanceTypeCatalog.find(nodeInstanceType(cluster))
|
||||
int vcpus = instanceTypeCatalog.find(sizingInstanceType(cluster))
|
||||
.map(type -> maxVcpus > 0 ? Math.min(type.vcpu, maxVcpus) : 0)
|
||||
.orElse(maxVcpus);
|
||||
LOG.warnv("Applying explicit EKS cluster {0} ceiling without kubelet reservations"
|
||||
@@ -1189,17 +1189,45 @@ public class EksClusterManager
|
||||
return EksNodeCapacity.explicitCeilingWithoutHostInfo(maxMemoryMib, vcpus);
|
||||
}
|
||||
|
||||
private static String capacityLabel(Cluster cluster, EksNodeCapacity.Limits limits) {
|
||||
/**
|
||||
* Carries the sizing type only when it is configured, so a survivor created without the
|
||||
* setting keeps its label and is not recreated after an upgrade. Changing the setting changes
|
||||
* the label, which recreates the node on the next start with its data volume.
|
||||
*/
|
||||
private String capacityLabel(Cluster cluster, EksNodeCapacity.Limits limits) {
|
||||
String types = nodeInstanceType(cluster) + configuredSizingInstanceType().map(type -> "@" + type).orElse("");
|
||||
if (limits == null) {
|
||||
return nodeInstanceType(cluster) + ":unbounded";
|
||||
return types + ":unbounded";
|
||||
}
|
||||
return nodeInstanceType(cluster) + ":" + limits.memoryBytes() + ":" + limits.vcpus()
|
||||
return types + ":" + limits.memoryBytes() + ":" + limits.vcpus()
|
||||
+ ":" + limits.systemMemoryMib() + ":" + limits.kubeMemoryMib()
|
||||
+ ":" + limits.evictionMemoryMib() + ":" + limits.systemCpuMilli()
|
||||
+ ":" + limits.kubeCpuMilli() + ":" + limits.reducedReservations()
|
||||
+ ":" + limits.kubeletArgsEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* The catalog type the node container is sized from: {@code floci.services.eks.node-instance-type}
|
||||
* when set, otherwise the node group's. Only the container's memory, CPU and kubelet reservations
|
||||
* follow it; the node group, the node's instance-type label and the synthesized EC2 instance keep
|
||||
* {@link #nodeInstanceType(Cluster)}.
|
||||
*/
|
||||
String sizingInstanceType(Cluster cluster) {
|
||||
return configuredSizingInstanceType().orElseGet(() -> nodeInstanceType(cluster));
|
||||
}
|
||||
|
||||
private Optional<String> configuredSizingInstanceType() {
|
||||
Optional<String> configured = config.services().eks().nodeInstanceType()
|
||||
.map(String::trim)
|
||||
.filter(type -> !type.isEmpty());
|
||||
if (configured.isEmpty() || instanceTypeCatalog.find(configured.get()).isPresent()) {
|
||||
return configured;
|
||||
}
|
||||
LOG.warnv("floci.services.eks.node-instance-type {0} is absent from the EC2 catalog; sizing EKS nodes "
|
||||
+ "from their node group's instance type", configured.get());
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
static String nodeInstanceType(Cluster cluster) {
|
||||
return cluster != null && cluster.getNodeInstanceType() != null
|
||||
? cluster.getNodeInstanceType() : DEFAULT_NODE_INSTANCE_TYPE;
|
||||
|
||||
Reference in new issue
Block a user