mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(eks): stop launching EKS Auto Mode nodes at a NodePool's limits, and show its nodes in its status (#9538)
This commit is contained in:
1 parent
a2d37a4cc5
commit
ea85a11c44
5 files changed
+247
-30
No files matched your search
@@ -467,7 +467,9 @@ launches nodes on AWS. Floci checks every 10 seconds.
|
||||
|
||||
- **Pool.** The pod goes to the first NodePool, by `weight` then name, with an instance type the pool's requirements
|
||||
allow, whose node the pod's `nodeSelector`, required node affinity and tolerations accept, and that fits its CPU and
|
||||
memory requests. A requirement on a label Floci doesn't give its nodes (a GPU count, say) is left out. A pod one of
|
||||
memory requests. A type whose node would take the pool's nodes, joined or joining, past its `limits` (`cpu`,
|
||||
`memory`, `nodes`) is left out, as AWS stopped at two 2-vCPU nodes for a pool limited to 4 vCPUs, so a pod such a
|
||||
pool can't take goes to the next pool, or waits. A requirement on a label Floci doesn't give its nodes (a GPU count, say) is left out. A pod one of
|
||||
the pool's schedulable nodes has room for, joined or still joining, waits for the scheduler instead. A joined
|
||||
node's room is its `status.allocatable` CPU, memory and pods less its pods' requests (sidecars included); one still
|
||||
joining has its instance type's whole size and 110 pods. A cordoned node, one with a taint of its own the pod
|
||||
@@ -526,6 +528,8 @@ launches nodes on AWS. Floci checks every 10 seconds.
|
||||
with its instance, Karpenter's finalizer taken off (other finalizers stay). A claim that couldn't be made is made
|
||||
on a later pass. Floci touches only the claims labelled `app.kubernetes.io/managed-by: eks`. `kubectl get
|
||||
nodeclaims` shows the type, capacity type, zone, node and readiness, as Karpenter's columns do.
|
||||
- **Pool status.** Each pool's `status.resources` (`cpu`, `memory`, `pods`, `nodes`) and `status.nodes` say what its
|
||||
joined nodes have, the sum of their capacity, as AWS shows them.
|
||||
- **Removal.** Turning compute off terminates the cluster's Auto Mode instances and takes their nodes out of it.
|
||||
Deleting the cluster terminates them, waits up to a minute for them to finish terminating, as they hold the
|
||||
cluster security group deleted next (one that doesn't fails the delete, which can be retried), and deletes the
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.floci.aws.services.eks;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.Digests;
|
||||
import io.floci.aws.core.common.RequestScopes;
|
||||
@@ -178,12 +179,22 @@ public class EksAutoModeCompute implements EksAutoModeCleanup {
|
||||
removeStrayNodes(cluster, region, nodesByName);
|
||||
Set<String> claimsDeleted = syncNodeClaims(cluster, region, nodesByName, podList);
|
||||
removeStoppedOfDeletedClaims(cluster, region, claimsDeleted);
|
||||
// Read before the pass may stop, so a pool whose last node went shows none.
|
||||
JsonNode poolList = read(cluster, "nodepools");
|
||||
updatePoolStatus(cluster, region, poolList, launched, nodesByName);
|
||||
if (launched.isEmpty() && pods.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Pools poolsRead = Pools.of(read(cluster, "nodepools"));
|
||||
Pools poolsRead = Pools.of(poolList);
|
||||
Map<String, NodePool> pools = poolsRead.byName();
|
||||
Map<String, JsonNode> poolItems = poolsRead.items();
|
||||
// What each pool's nodes have, joined or joining, which its limits count, as Karpenter counts its NodeClaims.
|
||||
Map<String, EksAutoModeNodes.Capacity> poolUsed = new HashMap<>();
|
||||
for (Instance instance : launched) {
|
||||
instanceTypes.find(instance.getInstanceType()).ifPresent(type -> poolUsed.merge(
|
||||
String.valueOf(tag(instance, POOL_TAG)), EksAutoModeNodes.Capacity.of(type),
|
||||
EksAutoModeNodes.Capacity::plus));
|
||||
}
|
||||
// The DaemonSet pods a node runs besides its workload, which room and sizing count; read only for pods to place.
|
||||
List<EksAutoModeNodes.PendingPod> daemons = pods.isEmpty() ? List.of()
|
||||
: EksAutoModeNodes.daemonPods(read(cluster, "daemonsets"));
|
||||
@@ -299,7 +310,7 @@ public class EksAutoModeCompute implements EksAutoModeCleanup {
|
||||
nodeClasses.forEach((name, spec) -> zonesByNodeClass.put(name, ids(spec.path("subnetSelectorTerms")).stream()
|
||||
.map(subnetZones::get).filter(Objects::nonNull).distinct().toList()));
|
||||
for (Launch launch : EksAutoModeNodes.plan(List.copyOf(pools.values()), withoutRoom,
|
||||
instanceTypes.instanceTypes(), zonesByNodeClass, daemons, region)) {
|
||||
instanceTypes.instanceTypes(), zonesByNodeClass, daemons, region, poolUsed)) {
|
||||
try {
|
||||
launch(cluster, region, launch, nodeClasses.get(launch.pool().nodeClass()), subnetZones,
|
||||
poolItems.getOrDefault(launch.pool().name(), MAPPER.createObjectNode()));
|
||||
@@ -949,6 +960,52 @@ public class EksAutoModeCompute implements EksAutoModeCleanup {
|
||||
return launch.pods().stream().map(p -> p.namespace() + "/" + p.name()).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps each pool's {@code status.resources} and {@code status.nodes} what its joined nodes have, as Karpenter
|
||||
* reports them: the sum of their capacity's CPU, memory and pods, and how many they are. A pool whose status
|
||||
* already says so isn't written.
|
||||
*/
|
||||
private void updatePoolStatus(Cluster cluster, String region, JsonNode poolList, List<Instance> launched,
|
||||
Map<String, JsonNode> nodesByName) {
|
||||
Map<String, long[]> totals = new HashMap<>();
|
||||
for (Instance instance : launched) {
|
||||
JsonNode node = nodesByName.get(clusterManager.deriveInstanceNodeName(instance, region));
|
||||
if (node == null) {
|
||||
continue;
|
||||
}
|
||||
JsonNode capacity = node.path("status").path("capacity");
|
||||
long[] total = totals.computeIfAbsent(String.valueOf(tag(instance, POOL_TAG)), k -> new long[4]);
|
||||
total[0] += EksAutoModeNodes.cpuMillis(capacity.path("cpu").asText(""));
|
||||
total[1] += EksAutoModeNodes.bytes(capacity.path("memory").asText(""));
|
||||
total[2] += capacity.path("pods").asLong(0);
|
||||
total[3]++;
|
||||
}
|
||||
for (JsonNode item : poolList.path("items")) {
|
||||
String name = item.path("metadata").path("name").asText();
|
||||
long[] total = totals.getOrDefault(name, new long[4]);
|
||||
ObjectNode resources = MAPPER.createObjectNode();
|
||||
resources.put("cpu", EksAutoModeNodes.cpuQuantity(total[0]));
|
||||
resources.put("memory", EksAutoModeNodes.memoryQuantity(total[1]));
|
||||
resources.put("pods", String.valueOf(total[2]));
|
||||
resources.put("nodes", String.valueOf(total[3]));
|
||||
JsonNode status = item.path("status");
|
||||
if (resources.equals(status.path("resources")) && status.path("nodes").asLong(-1) == total[3]) {
|
||||
continue;
|
||||
}
|
||||
ObjectNode patch = MAPPER.createObjectNode();
|
||||
ObjectNode patchStatus = patch.putObject("status");
|
||||
patchStatus.set("resources", resources);
|
||||
patchStatus.put("nodes", total[3]);
|
||||
try {
|
||||
exec(cluster, List.of("kubectl", "patch", "nodepool", name, "--subresource=status", "--type=merge",
|
||||
"-p", patch.toString()), "patch nodepool " + name);
|
||||
} catch (RuntimeException e) {
|
||||
LOG.warnv("EKS Auto Mode NodePool {0} of cluster {1} doesn''t show its nodes yet: {2}", name,
|
||||
cluster.getName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The cluster's nodes by name. */
|
||||
private Map<String, JsonNode> nodesByName(Cluster cluster) {
|
||||
Map<String, JsonNode> nodesByName = new HashMap<>();
|
||||
|
||||
@@ -109,12 +109,44 @@ final class EksAutoModeNodes {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The CPU (millicores), memory (bytes) and nodes a pool's nodes have, or a pool's {@code limits} allow, each
|
||||
* {@link Long#MAX_VALUE} when unlimited.
|
||||
*/
|
||||
record Capacity(long cpuMillis, long memoryBytes, long nodes) {
|
||||
|
||||
static final Capacity NONE = new Capacity(0, 0, 0);
|
||||
static final Capacity UNLIMITED = new Capacity(Long.MAX_VALUE, Long.MAX_VALUE, Long.MAX_VALUE);
|
||||
|
||||
/** The capacity of one node of {@code type}. */
|
||||
static Capacity of(CatalogInstanceType type) {
|
||||
return new Capacity(type.vcpu * 1000L, type.memoryMib * 1024L * 1024L, 1);
|
||||
}
|
||||
|
||||
Capacity plus(Capacity other) {
|
||||
return new Capacity(cpuMillis + other.cpuMillis, memoryBytes + other.memoryBytes, nodes + other.nodes);
|
||||
}
|
||||
|
||||
/** Whether this, a pool's nodes with one more, stays within {@code limits}. */
|
||||
boolean within(Capacity limits) {
|
||||
return cpuMillis <= limits.cpuMillis && memoryBytes <= limits.memoryBytes && nodes <= limits.nodes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A NodePool: its NodeClass, its requirements, the taints and labels its nodes get, its weight, how long a node
|
||||
* stays empty before it goes (null for {@code Never}), and its disruption budgets' {@code nodes} values.
|
||||
* stays empty before it goes (null for {@code Never}), its disruption budgets' {@code nodes} values, and the
|
||||
* {@code limits} its nodes' capacity may not pass.
|
||||
*/
|
||||
record NodePool(String name, String nodeClass, List<Requirement> requirements, List<Taint> taints,
|
||||
Map<String, String> labels, int weight, Duration consolidateAfter, List<String> budgets) {
|
||||
Map<String, String> labels, int weight, Duration consolidateAfter, List<String> budgets,
|
||||
Capacity limits) {
|
||||
|
||||
/** A pool without limits. */
|
||||
NodePool(String name, String nodeClass, List<Requirement> requirements, List<Taint> taints,
|
||||
Map<String, String> labels, int weight, Duration consolidateAfter, List<String> budgets) {
|
||||
this(name, nodeClass, requirements, taints, labels, weight, consolidateAfter, budgets, Capacity.UNLIMITED);
|
||||
}
|
||||
|
||||
/**
|
||||
* How many of the pool's {@code nodes} may be disrupted at once: the least its budgets allow, a percentage
|
||||
@@ -320,6 +352,17 @@ final class EksAutoModeNodes {
|
||||
/** As above; with the region the nodes join in, whose label DaemonSets may select on. */
|
||||
static List<Launch> plan(List<NodePool> pools, List<PendingPod> pods, List<CatalogInstanceType> types,
|
||||
Map<String, List<String>> zonesByNodeClass, List<PendingPod> daemons, String region) {
|
||||
return plan(pools, pods, types, zonesByNodeClass, daemons, region, Map.of());
|
||||
}
|
||||
|
||||
/**
|
||||
* As above; with the capacity each pool's nodes already have, joined or joining, by pool name: no pool gets a node
|
||||
* that would take it past its {@code limits}, as Karpenter counts them, and a pod goes to the next pool that
|
||||
* could take it.
|
||||
*/
|
||||
static List<Launch> plan(List<NodePool> pools, List<PendingPod> pods, List<CatalogInstanceType> types,
|
||||
Map<String, List<String>> zonesByNodeClass, List<PendingPod> daemons, String region,
|
||||
Map<String, Capacity> used) {
|
||||
List<NodePool> ordered = pools.stream()
|
||||
.sorted(Comparator.comparingInt(NodePool::weight).reversed().thenComparing(NodePool::name))
|
||||
.toList();
|
||||
@@ -332,7 +375,7 @@ final class EksAutoModeNodes {
|
||||
for (PendingPod pod : pods) {
|
||||
for (NodePool pool : ordered) {
|
||||
if (candidate(pool, sized, zonesOf(pool, zonesByNodeClass), pod, pod.cpuMillis(), pod.memoryBytes(),
|
||||
daemons, region)
|
||||
daemons, region, used)
|
||||
.isPresent()) {
|
||||
byPool.computeIfAbsent(pool.name(), k -> new ArrayList<>()).add(pod);
|
||||
break;
|
||||
@@ -350,10 +393,11 @@ final class EksAutoModeNodes {
|
||||
PendingPod largest = group.stream().max(Comparator.comparingLong(PendingPod::cpuMillis)
|
||||
.thenComparingLong(PendingPod::memoryBytes)).orElseThrow();
|
||||
List<String> placesIn = zonesOf(pool, zonesByNodeClass);
|
||||
Optional<Placement> placement = candidate(pool, sized, placesIn, largest, cpu, memory, daemons, region)
|
||||
Optional<Placement> placement = candidate(pool, sized, placesIn, largest, cpu, memory, daemons, region,
|
||||
used)
|
||||
.filter(p -> group.stream().allMatch(pod -> pod.fits(labels(p.type(), pool, p.zone()), pool.taints())))
|
||||
.or(() -> candidate(pool, sized, placesIn, largest, largest.cpuMillis(), largest.memoryBytes(),
|
||||
daemons, region));
|
||||
daemons, region, used));
|
||||
placement.ifPresent(p -> launches.add(new Launch(pool, p.type(), p.zone(),
|
||||
labels(p.type(), pool, p.zone()), List.copyOf(group))));
|
||||
}
|
||||
@@ -412,8 +456,13 @@ final class EksAutoModeNodes {
|
||||
|
||||
private static Optional<Placement> candidate(NodePool pool, List<CatalogInstanceType> sized, List<String> zones,
|
||||
PendingPod pod, long cpuMillis, long memoryBytes,
|
||||
List<PendingPod> daemons, String region) {
|
||||
List<PendingPod> daemons, String region,
|
||||
Map<String, Capacity> used) {
|
||||
Capacity poolUsed = used.getOrDefault(pool.name(), Capacity.NONE);
|
||||
for (CatalogInstanceType type : sized) {
|
||||
if (!poolUsed.plus(Capacity.of(type)).within(pool.limits())) {
|
||||
continue;
|
||||
}
|
||||
for (String zone : zones) {
|
||||
Map<String, String> labels = labels(type, pool, zone);
|
||||
long[] daemon = daemonRequests(daemons, withRegion(labels, region), pool.taints());
|
||||
@@ -512,6 +561,24 @@ final class EksAutoModeNodes {
|
||||
return Optional.of(new NodeAsk(selector, List.copyOf(terms), List.copyOf(tolerations)));
|
||||
}
|
||||
|
||||
/** A CPU quantity as Kubernetes writes it: whole cores as a number, else millicores ({@code 1780m}). */
|
||||
static String cpuQuantity(long millis) {
|
||||
return millis % 1000 == 0 ? String.valueOf(millis / 1000) : millis + "m";
|
||||
}
|
||||
|
||||
/** A memory quantity as a node's capacity gives it, in kibibytes ({@code 3858672Ki}), or bytes when not whole. */
|
||||
static String memoryQuantity(long bytes) {
|
||||
return bytes % 1024 == 0 ? bytes / 1024 + "Ki" : String.valueOf(bytes);
|
||||
}
|
||||
|
||||
/** A pool's {@code limits}: {@code cpu}, {@code memory} and {@code nodes}, each unlimited when it doesn't say. */
|
||||
static Capacity limits(JsonNode limits) {
|
||||
return new Capacity(
|
||||
limits.hasNonNull("cpu") ? cpuMillis(limits.path("cpu").asText()) : Long.MAX_VALUE,
|
||||
limits.hasNonNull("memory") ? bytes(limits.path("memory").asText()) : Long.MAX_VALUE,
|
||||
limits.hasNonNull("nodes") ? count(limits.path("nodes").asText()) : Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
/** The NodePools of {@code kubectl get nodepools -o json}. */
|
||||
static List<NodePool> nodePools(JsonNode list) {
|
||||
List<NodePool> pools = new ArrayList<>();
|
||||
@@ -544,7 +611,7 @@ final class EksAutoModeNodes {
|
||||
template.path("spec").path("nodeClassRef").path("name").asText("default"),
|
||||
requirements(template.path("spec").path("requirements")), List.copyOf(taints), labels,
|
||||
item.path("spec").path("weight").asInt(0), duration(disruption.path("consolidateAfter").asText("0s")),
|
||||
List.copyOf(budgets)));
|
||||
List.copyOf(budgets), limits(item.path("spec").path("limits"))));
|
||||
}
|
||||
return pools;
|
||||
}
|
||||
@@ -738,22 +805,12 @@ final class EksAutoModeNodes {
|
||||
}
|
||||
|
||||
/**
|
||||
* A CPU quantity in millicores: {@code 100m}, {@code 1}, {@code 0.5}, {@code 2e3}; rounded up, as Kubernetes
|
||||
* does; 0 for none or one Floci can't read.
|
||||
* A CPU quantity in millicores: {@code 100m}, {@code 1}, {@code 0.5}, {@code 2e3}, {@code 1k}; rounded up, as
|
||||
* Kubernetes does; 0 for none or one Floci can't read.
|
||||
*/
|
||||
static long cpuMillis(String quantity) {
|
||||
Matcher m = QUANTITY.matcher(quantity.trim());
|
||||
if (!m.matches()) {
|
||||
return 0;
|
||||
}
|
||||
BigDecimal number = new BigDecimal(m.group(1));
|
||||
BigDecimal millis = switch (m.group(2)) {
|
||||
case "m" -> number;
|
||||
case "" -> number.movePointRight(3);
|
||||
case "k" -> number.movePointRight(6);
|
||||
default -> BigDecimal.ZERO;
|
||||
};
|
||||
return millis.setScale(0, RoundingMode.CEILING).longValue();
|
||||
BigDecimal value = quantity(quantity);
|
||||
return value == null ? 0 : rounded(value.movePointRight(3));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -761,13 +818,31 @@ final class EksAutoModeNodes {
|
||||
* up; 0 for none or one Floci can't read.
|
||||
*/
|
||||
static long bytes(String quantity) {
|
||||
BigDecimal value = quantity(quantity);
|
||||
return value == null ? 0 : rounded(value);
|
||||
}
|
||||
|
||||
/** A count given as a quantity, as a pool's {@code limits.nodes} may be: {@code 10}, {@code 1k}; rounded up. */
|
||||
static long count(String quantity) {
|
||||
BigDecimal value = quantity(quantity);
|
||||
return value == null ? 0 : rounded(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Kubernetes quantity in its base unit, with any of its suffixes: decimal ({@code n}, {@code u}, {@code m},
|
||||
* {@code k}, {@code M}, {@code G}, {@code T}, {@code P}, {@code E}), binary ({@code Ki} to {@code Ei}) or an
|
||||
* exponent; {@code null} for one Floci can't read.
|
||||
*/
|
||||
static BigDecimal quantity(String quantity) {
|
||||
Matcher m = QUANTITY.matcher(quantity.trim());
|
||||
if (!m.matches()) {
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
BigDecimal number = new BigDecimal(m.group(1));
|
||||
BigDecimal value = switch (m.group(2)) {
|
||||
return switch (m.group(2)) {
|
||||
case "" -> number;
|
||||
case "n" -> number.movePointLeft(9);
|
||||
case "u" -> number.movePointLeft(6);
|
||||
case "m" -> number.movePointLeft(3);
|
||||
case "k" -> number.movePointRight(3);
|
||||
case "M" -> number.movePointRight(6);
|
||||
@@ -781,9 +856,14 @@ final class EksAutoModeNodes {
|
||||
case "Ti" -> number.multiply(BigDecimal.valueOf(1L << 40));
|
||||
case "Pi" -> number.multiply(BigDecimal.valueOf(1L << 50));
|
||||
case "Ei" -> number.multiply(BigDecimal.valueOf(1L << 60));
|
||||
default -> BigDecimal.ZERO;
|
||||
default -> null;
|
||||
};
|
||||
return value.setScale(0, RoundingMode.CEILING).longValue();
|
||||
}
|
||||
|
||||
/** Rounded up, as Kubernetes rounds a quantity, and held at {@code Long.MAX_VALUE}. */
|
||||
private static long rounded(BigDecimal value) {
|
||||
BigDecimal up = value.setScale(0, RoundingMode.CEILING);
|
||||
return up.compareTo(BigDecimal.valueOf(Long.MAX_VALUE)) >= 0 ? Long.MAX_VALUE : up.longValue();
|
||||
}
|
||||
|
||||
/** A Kubernetes duration such as {@code 30s}, {@code 5m} or {@code 1h30m}; null for {@code Never}. */
|
||||
|
||||
@@ -325,6 +325,32 @@ class EksAutoModeComputeTest {
|
||||
+ "\"finalizers\": [\"karpenter.sh/termination\"" + moreFinalizers + "]}, \"status\": {}}";
|
||||
}
|
||||
|
||||
/**
|
||||
* A pool at its limit launches nothing more for a pending pod, and its status says what its joined nodes have,
|
||||
* as AWS shows it: their CPU, memory and pods, and how many they are.
|
||||
*/
|
||||
@Test
|
||||
void aPoolAtItsLimitLaunchesNothingAndItsStatusShowsItsNodes() {
|
||||
joinedNode("i-node", "node-1");
|
||||
// Cordoned, so the pending pod has no room on it and would get a node of its own but for the limit.
|
||||
lists.put("nodes", "{\"items\": [{\"metadata\": {\"name\": \"node-1\", \"labels\": {}}, "
|
||||
+ "\"spec\": {\"unschedulable\": true}, "
|
||||
+ "\"status\": {\"capacity\": {\"cpu\": \"2\", \"memory\": \"4194304Ki\", \"pods\": \"110\"}}}]}");
|
||||
lists.put("nodepools", POOLS.replace("\"spec\": {\"template\"",
|
||||
"\"spec\": {\"limits\": {\"cpu\": \"2\"}, \"template\""));
|
||||
Cluster cluster = cluster("prod");
|
||||
|
||||
compute.reconcile(cluster, REGION);
|
||||
|
||||
verify(ec2, never()).runInstances(anyString(), anyString(), anyString(), anyInt(), anyInt(), any(), anyList(),
|
||||
anyString(), anyString(), anyList(), anyString(), anyString(), any(), any(), anyInt(), any(), any(),
|
||||
any(), anyString(), anyBoolean(), any(), any(), any(), anyBoolean(), any(), any());
|
||||
verify(clusterManager).execInContainerForResult("k3s-1", new String[]{"kubectl", "patch", "nodepool",
|
||||
"general-purpose", "--subresource=status", "--type=merge", "-p",
|
||||
"{\"status\":{\"resources\":{\"cpu\":\"2\",\"memory\":\"4194304Ki\",\"pods\":\"110\","
|
||||
+ "\"nodes\":\"1\"},\"nodes\":1}}"}, 15);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPoolWhoseNodeClassIsMissingOrWhoseImageTheCatalogLacksLaunchesNothing() {
|
||||
lists.put("nodeclasses", "{\"items\": []}");
|
||||
|
||||
@@ -399,6 +399,54 @@ class EksAutoModeNodesTest {
|
||||
assertEquals(disruptable, pool.disruptable(nodes));
|
||||
}
|
||||
|
||||
/** A pool's limits: cpu, memory and nodes; one it doesn't name is unlimited. */
|
||||
@Test
|
||||
void aPoolsLimitsAreRead() throws Exception {
|
||||
String pools = """
|
||||
{"items": [{"metadata": {"name": "limited"}, "spec": {"limits": {"cpu": "4", "memory": "16Gi"},
|
||||
"template": {"spec": {}}}},
|
||||
{"metadata": {"name": "free"}, "spec": {"template": {"spec": {}}}}]}""";
|
||||
|
||||
List<NodePool> read = EksAutoModeNodes.nodePools(json(pools));
|
||||
|
||||
assertEquals(new EksAutoModeNodes.Capacity(4000, 16L << 30, Long.MAX_VALUE), read.getFirst().limits());
|
||||
assertEquals(EksAutoModeNodes.Capacity.UNLIMITED, read.get(1).limits());
|
||||
// Suffixed quantities, as the NodePool schema keeps them: 1k nodes, 1M cores, 1Ti.
|
||||
assertEquals(new EksAutoModeNodes.Capacity(1_000_000_000L, 1L << 40, 1000), EksAutoModeNodes.limits(json(
|
||||
"{\"cpu\": \"1M\", \"memory\": \"1Ti\", \"nodes\": \"1k\"}")));
|
||||
assertEquals(new EksAutoModeNodes.Capacity(Long.MAX_VALUE, Long.MAX_VALUE, 3), EksAutoModeNodes.limits(json(
|
||||
"{\"nodes\": 3}")));
|
||||
}
|
||||
|
||||
/**
|
||||
* No pool gets a node that would take its nodes past its limits, as AWS stopped at two 2-vCPU nodes for a pool
|
||||
* limited to 4 vCPUs; a smaller type that stays within is chosen, and a pod a pool can't take any more goes to
|
||||
* the next pool that can.
|
||||
*/
|
||||
@Test
|
||||
void aPoolsLimitsStopItsLaunchesAndAPodGoesToTheNextPool() throws Exception {
|
||||
NodePool limited = new NodePool("limited", "default", List.of(), List.of(), Map.of(), 10, null, List.of(),
|
||||
new EksAutoModeNodes.Capacity(4000, Long.MAX_VALUE, Long.MAX_VALUE));
|
||||
NodePool fallback = new NodePool("fallback", "default", List.of(), List.of(), Map.of(), 0, null, List.of());
|
||||
PendingPod web = new PendingPod("default", "web", 900, 64L << 20, Map.of(), List.of(), List.of());
|
||||
PendingPod big = new PendingPod("default", "big", 2500, 64L << 20, Map.of(), List.of(), List.of());
|
||||
|
||||
// Half used: a 2-vCPU node fits the limit, a 4-vCPU one doesn't, so a 2500m pod goes to the other pool.
|
||||
Map<String, EksAutoModeNodes.Capacity> half = Map.of("limited",
|
||||
new EksAutoModeNodes.Capacity(2000, 4096L << 20, 1));
|
||||
assertEquals("limited", EksAutoModeNodes.plan(List.of(limited), List.of(web), TYPES, Map.of(), List.of(),
|
||||
null, half).getFirst().pool().name());
|
||||
assertEquals("fallback", EksAutoModeNodes.plan(List.of(limited, fallback), List.of(big), TYPES, Map.of(),
|
||||
List.of(), null, half).getFirst().pool().name());
|
||||
// At the limit: nothing more from that pool.
|
||||
Map<String, EksAutoModeNodes.Capacity> full = Map.of("limited",
|
||||
new EksAutoModeNodes.Capacity(4000, 8192L << 20, 2));
|
||||
assertEquals(List.of(), EksAutoModeNodes.plan(List.of(limited), List.of(web), TYPES, Map.of(), List.of(),
|
||||
null, full));
|
||||
assertEquals("fallback", EksAutoModeNodes.plan(List.of(limited, fallback), List.of(web), TYPES, Map.of(),
|
||||
List.of(), null, full).getFirst().pool().name());
|
||||
}
|
||||
|
||||
@Test
|
||||
void consolidateAfterAndBudgetsAreReadFromThePoolScheduledAndOtherReasonsBudgetsLeftOut() throws Exception {
|
||||
String pools = """
|
||||
@@ -474,14 +522,16 @@ class EksAutoModeNodesTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"100m,100", "1,1000", "0.5,500", "2500m,2500", "2e3,2000000", "0.1m,1", ",0", "x,0"})
|
||||
@CsvSource({"100m,100", "1,1000", "0.5,500", "2500m,2500", "2e3,2000000", "0.1m,1", "1k,1000000",
|
||||
"1M,1000000000", "500000u,500", ",0", "x,0"})
|
||||
void cpuQuantities(String quantity, long millis) {
|
||||
assertEquals(millis, EksAutoModeNodes.cpuMillis(quantity == null ? "" : quantity));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"64Mi,67108864", "1Gi,1073741824", "1.5Gi,1610612736", "1G,1000000000", "1e9,1000000000",
|
||||
"128974848,128974848", "500M,500000000", "1Pi,1125899906842624", "1500m,2", ",0"})
|
||||
"128974848,128974848", "500M,500000000", "1Pi,1125899906842624", "1500m,2", "1k,1000", "1T,1000000000000",
|
||||
"100E,9223372036854775807", ",0"})
|
||||
void memoryQuantities(String quantity, long bytes) {
|
||||
assertEquals(bytes, EksAutoModeNodes.bytes(quantity == null ? "" : quantity));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user