"""Building blocks shared by the CKAD task banks written for the per-task hosts (77 onwards): bash for setups and checks. The generic ones - NET, PODS, PY - are sim/bank.py's. The two rules of the CKS banks hold here as well: a task scores nothing before anyone has worked on it, and what can be tested for real - a request, a file in a container, a container's environment - is tested for real rather than read off the object. """ from sim.bank import C, CAN, NET, NS, PODS, PY, ns_pick, name_pick # noqa: F401 (the banks import these from here) # Rollouts and the Pods they leave behind. ROLL = r""" # rolled NS DEPLOYMENT N [SECONDS]: the Deployment has N replicas, all of them updated and available rolled() { local i for i in $(seq 1 $(( ${4:-60} / 3 ))); do [ "$(j -n "$1" deploy "$2" '{.status.replicas}')" = "$3" ] && [ "$(j -n "$1" deploy "$2" '{.status.updatedReplicas}')" = "$3" ] \ && [ "$(j -n "$1" deploy "$2" '{.status.availableReplicas}')" = "$3" ] && return 0 sleep 3 done; return 1 } # newest NS SELECTOR: the name of the newest Running Pod the selector matches newest() { $K -n "$1" get pod -l "$2" --field-selector status.phase=Running --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1:].metadata.name}' 2>/dev/null; } """ # img IMAGE GO-TEMPLATE: a property of an image in the host's store ("" if there is no such image) IMG = r""" img() { podman image inspect "$1" --format "$2" 2>/dev/null | tr -d '\r'; } """ # same LIST-FILE EXPECTED-FILE: the candidate's list names exactly the expected items (order, # blanks and a leading "kind/" ignored) SAME = r""" same() { [ -s "$1" ] && diff <(tr -d ' \r' < "$1" | sed 's#.*/##' | grep . | sort -u) <(sort -u "$2") >/dev/null; } """ # one FILE: the file's content with blanks and line ends removed - for a one-word answer ONE = r""" one() { tr -d ' \t\n\r' < "$1" 2>/dev/null; } """