24 lines
1.0 KiB
Python
24 lines
1.0 KiB
Python
"""Shared helpers for CKA task banks."""
|
|
|
|
NS = r"""
|
|
mkns() {
|
|
$K create ns "$1" --dry-run=client -o yaml | $K apply -f - >/dev/null
|
|
# Wait for the namespace's `default` ServiceAccount before returning. The controller creates it
|
|
# asynchronously, and a Pod applied in the gap is rejected outright:
|
|
# error looking up service account <ns>/default: serviceaccount "default" not found
|
|
# Setups that create a namespace and immediately apply Pods lose that race under load (Q204),
|
|
# which fails the seed and costs the candidate a whole task. It belongs here, not in each task.
|
|
for _ in $(seq 1 30); do $K -n "$1" get sa default >/dev/null 2>&1 && return 0; sleep 1; done
|
|
}
|
|
"""
|
|
|
|
def C(name, pts, script):
|
|
return {"name": name, "pts": pts, "script": script}
|
|
|
|
def ns_pick(r, base):
|
|
"""Namespace name with a random suffix so the same task never lands on the same namespace twice."""
|
|
return f"{base}-{r.choice(['alpha', 'bravo', 'delta', 'echo', 'kilo', 'nova', 'omega', 'zulu'])}"
|
|
|
|
def name_pick(r, base):
|
|
return f"{base}-{r.randint(10, 99)}"
|