fix(eks): refuse an EKS Auto Mode NodePool that would outlive the 21-day maximum node lifetime (#9741)

Auto Mode's node pool guide: the sum of expireAfter and terminationGracePeriod can't exceed 21 days, and expireAfter can't be Never. The NodePool kind took a Never or 720h pool. It now has the three rules and messages AWS's NodePool kind has on an Auto Mode cluster, keyed on an eks.amazonaws.com NodeClass ref, and expireAfter's schema as AWS's (a 336h default and a duration-or-Never pattern); terminationGracePeriod's schema is Karpenter's published one.
This commit is contained in:
mrfelek authored and GitHub committed 2026-11-29 09:55:09 -04:00
1 parent 7b096e99d9
commit c2743ec70f
3 files changed
+100 -1

No files matched your search

+6 -1
View File
@@ -535,7 +535,12 @@ launches nodes on AWS. Floci checks every 10 seconds.
counted from its creation, it is deleted, whatever the pool's disruption budgets, as AWS expired a `5m` pool's
claims five minutes in, a `nodes: "0"` budget aside; its node then goes as a deleted claim's does, and its pods get
another. No claim lives more than 21 days, Auto Mode's documented maximum node lifetime, which `expireAfter` can
only shorten: a pool's `Never`, or an `expireAfter` longer than that, still has its claims go at 21 days. A claim that couldn't be made is made
only shorten: a claim whose `expireAfter` is `Never`, or longer than that, still goes at 21 days. The NodePool kind
refuses such a pool with the rules and messages AWS's NodePool kind has: an `expireAfter` of `Never` ("expireAfter
may not be set to Never"), or an `expireAfter` and `terminationGracePeriod` that come to more than 21 days ("the sum
of expireAfter and terminationGracePeriod may not exceed 21 days", with "(defaulted to 24h)" when the pool names no
grace period), so the largest `expireAfter` with the default grace period is `480h`. A pool without an
`expireAfter` is stored with `336h`, and one that isn't a duration or `Never` is refused by its pattern. 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
@@ -28,6 +28,42 @@ spec:
spec:
type: object
x-kubernetes-preserve-unknown-fields: true
properties:
template:
type: object
x-kubernetes-preserve-unknown-fields: true
properties:
spec:
type: object
x-kubernetes-preserve-unknown-fields: true
# As AWS's NodePool kind has them on an Auto Mode cluster (us-east-1, 2026-11-28): expireAfter's
# schema and default, and the three rules of the node pool guide's limit ("the sum of expireAfter
# and terminationGracePeriod can't exceed 21 days, and you can't set expireAfter to Never"),
# verbatim. terminationGracePeriod's schema is Karpenter's published v1 one. The 336h default is
# the one EksAutoModeNodeClaims gives a claim (DEFAULT_EXPIRE_AFTER): keep them in step.
properties:
expireAfter:
type: string
default: 336h
pattern: ^(([0-9]+(s|m|h))+|Never)$
terminationGracePeriod:
type: string
pattern: ^([0-9]+(s|m|h))+$
nodeClassRef:
type: object
x-kubernetes-preserve-unknown-fields: true
properties:
group:
type: string
kind:
type: string
x-kubernetes-validations:
- rule: "(self.nodeClassRef.group == 'eks.amazonaws.com' && self.nodeClassRef.kind == 'NodeClass' && has(self.terminationGracePeriod)) ? duration(self.expireAfter) + duration(self.terminationGracePeriod) <= duration('504h') : true"
message: the sum of expireAfter and terminationGracePeriod may not exceed 21 days
- rule: "(self.nodeClassRef.group == 'eks.amazonaws.com' && self.nodeClassRef.kind == 'NodeClass' && !has(self.terminationGracePeriod)) ? duration(self.expireAfter) <= duration('480h') : true"
message: the sum of expireAfter and terminationGracePeriod (defaulted to 24h) may not exceed 21 days
- rule: "(self.nodeClassRef.group == 'eks.amazonaws.com' && self.nodeClassRef.kind == 'NodeClass') ? self.expireAfter != 'Never' : true"
message: expireAfter may not be set to Never
status:
type: object
x-kubernetes-preserve-unknown-fields: true
@@ -2,6 +2,7 @@ package io.floci.aws.services.eks;
import com.github.dockerjava.api.DockerClient;
import io.floci.aws.core.common.RequestScopes;
import io.floci.aws.core.common.docker.ContainerExec;
import io.floci.aws.services.ec2.Ec2Service;
import io.floci.aws.services.ec2.model.Instance;
import io.floci.aws.services.ec2.model.Tag;
@@ -141,6 +142,63 @@ class EksAutoModeNodesDockerNightlyIntegrationTest {
return node;
}
/**
* The NodePool kind refuses a pool that would outlive Auto Mode's 21-day maximum node lifetime with the rules and
* messages AWS's NodePool kind has (measured on an Auto Mode cluster in us-east-1): an {@code expireAfter} of
* {@code Never}, or one that with {@code terminationGracePeriod} (24h when the pool doesn't say) comes to more than
* 21 days. A value that isn't a duration is refused by its pattern. A pool within them is accepted, and one without
* an {@code expireAfter} is stored with 336h.
*/
@Test
void aNodePoolThatWouldOutliveTwentyOneDaysIsRefused() {
EksTestNode node = clusterWithAnUnschedulablePod("10.73");
String defaulted = "the sum of expireAfter and terminationGracePeriod (defaulted to 24h) may not exceed 21 days";
String conversion = "type conversion error from 'string' to 'google.protobuf.Duration' evaluating rule: "
+ defaulted;
// As on AWS, Never fails the defaulted rule's conversion too, so both lines come back.
assertEquals(List.of(conversion, "expireAfter may not be set to Never"),
refusal(node, "never", "expireAfter: Never"));
assertEquals(List.of(defaulted), refusal(node, "longer", "expireAfter: 481h"));
assertEquals(List.of("the sum of expireAfter and terminationGracePeriod may not exceed 21 days"),
refusal(node, "graceful", "expireAfter: 400h\n terminationGracePeriod: 200h"));
assertEquals(List.of("spec.template.spec.expireAfter in body should match '^(([0-9]+(s|m|h))+|Never)$'",
conversion), refusal(node, "soon", "expireAfter: soon"));
node.apply(pool("most", "expireAfter: 480h"));
node.apply(pool("defaulted", ""));
assertEquals("336h 480h", node.kubectlOutput("get", "nodepool", "defaulted", "most",
"-o", "jsonpath={.items[*].spec.template.spec.expireAfter}"));
}
private static String pool(String name, String lifetime) {
return """
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
name: %s
spec:
template:
spec:
%s
nodeClassRef: {group: eks.amazonaws.com, kind: NodeClass, name: default}""".formatted(name,
lifetime);
}
/**
* Applies a pool that must be refused, returning the messages the API server refuses it with, one for each field
* error, without the value an older API server names ({@code "object": }) before a rule's message.
*/
private static List<String> refusal(EksTestNode node, String name, String lifetime) {
ContainerExec.Result result = node.exec("sh", "-c", "cat << 'EOF' | kubectl apply -f -\n"
+ pool(name, lifetime) + "\nEOF");
assertEquals(1, result.exitCode(), result::summary);
String marker = "Invalid value: ";
return result.stderr().lines().filter(line -> line.contains(marker)).map(line -> {
String message = line.substring(line.indexOf(marker) + marker.length());
return message.startsWith("\"") ? message.substring(message.indexOf("\": ") + 3) : message;
}).toList();
}
@Test
void anUnschedulablePodGetsANodeOfItsPoolWhichGoesWithCompute() {
EksTestNode node = clusterWithAnUnschedulablePod("10.71");