# shellcheck shell=bash # Sourced by the chainsaw kubernetes-latest/previous Tests after cd to repo root. . hack/e2e-chainsaw/_lib/remediation-guard.sh . hack/e2e-chainsaw/_lib/talos-image-cache.sh # The QEMU sandbox, which no CI lane boots, exercises replicated DRBD storage. # The container lane cannot represent three DRBD nodes on one shared kernel, so # its otherwise-identical suites use the production local class instead. Keep # the accepted values narrow because this result is interpolated into # Kubernetes YAML below. cozy_e2e_storage_class() { case "${COZY_E2E_STORAGE_CLASS:-replicated}" in local | replicated) printf '%s\n' "${COZY_E2E_STORAGE_CLASS:-replicated}" ;; *) echo "COZY_E2E_STORAGE_CLASS must be local or replicated, got '${COZY_E2E_STORAGE_CLASS}'" >&2 return 1 ;; esac } # talos_spec_block: emit the tenant Kubernetes CR `spec.talos` block with the Talos # OS image cache (imageFactoryURL) when the in-sandbox cache is up. Prints nothing # when it falls back to the public default, so the chart default applies. # Indented for insertion directly under `spec:` in the heredoc below. # # No trailing newline, unlike the single-key helper this replaced: the caller reads # it through `$(...)`, which strips one anyway, and `${talos_block}` sits on a line # of its own in the heredoc, which supplies the break before the next `spec` key. # An empty result therefore leaves a blank line, which is valid YAML. talos_spec_block() { local url url=$(resolve_talos_image_factory_url) [ -n "$url" ] || return 0 printf ' talos:\n' printf ' imageFactoryURL: %s\n' "$url" return 0 } # kubectl_wait_retry: wraps `kubectl wait` with retries against transient # management-cluster apiserver/etcd errors. # # The e2e sandbox is a 3-node kind cluster on Talos VMs; the 3-instance # etcd HA cluster can shed a leader under the accumulated CDI+DRBD IO + # multiple back-to-back Kamaji tenant control-plane bringups this suite # stacks. kubectl's watch-based `wait` exits non-zero on the FIRST server # error it sees on the channel, even when the target is on the cusp of # becoming Ready. Concretely, we have seen: # Error from server: etcdserver: leader changed # fire mid-wait for `kubernetes--{cluster-autoscaler,kccm,kcsi-controller,base}` # with 3 of 4 deployments already `condition met` and the 4th ~200ms # from Ready. The snapshot-on-fail collector then showed all four at # `readyReplicas: 2` — the wait exited early, not the target's fault. # # This wrapper retries a small number of times against a curated allowlist # of transient server-side signatures. It does NOT swallow legitimate # timeouts (`--timeout=... expired`) or NotFound; those still surface. # # The capture guards the assignment with `|| _rc=$?`: the chainsaw scripts run # under `set -eu`, where a bare `_out=$(kubectl wait ...)` on a failing wait # aborts the WHOLE sourcing script right there -- before the retry loop, before # anything prints (stderr is captured into _out and dies with the shell). That # exact shape killed the kubernetes-latest suite silently the moment a wait # failed, with the transient-retry machinery never once reachable. kubectl_wait_retry() { local _attempts=3 local _i _out _rc for _i in $(seq 1 "${_attempts}"); do _rc=0 _out=$(kubectl wait "$@" 2>&1) || _rc=$? if [ "${_rc}" = 0 ]; then printf '%s\n' "${_out}" return 0 fi # Transient server-side signatures: etcd leader flap, etcd request # timeout, or apiserver watch channel closed without a clear reason. # Anything else (target NotFound, --timeout expired, permission # denied, etc.) is a real failure. if printf '%s' "${_out}" | grep --quiet --extended-regexp "etcdserver: leader changed|etcdserver: request timed out|the server was unable to return a response in the time allotted"; then printf 'kubectl_wait_retry: attempt %d/%d hit transient server error, retrying in 5s: %s\n' "${_i}" "${_attempts}" "${_out}" >&2 sleep 5 continue fi printf '%s\n' "${_out}" return "${_rc}" done printf 'kubectl_wait_retry: exhausted %d attempts on transient errors\n' "${_attempts}" >&2 return 1 } # Wait for a HelmRelease upgrade that has not started yet at the call site. # `kubectl wait --for=condition=Ready` alone is unsafe here: the old Ready=True # condition remains visible until helm-controller observes the changed spec, so # it can return before the upgrade even begins. Require a newer generation and # require status.observedGeneration to catch up to it before accepting Ready. # A terminal Stalled condition fails immediately instead of burning the whole # timeout on work Flux has already declared impossible. cozy_wait_helmrelease_upgrade() { local namespace="$1" local name="$2" local previous_generation="$3" local timeout_seconds="${4:-600}" local deadline=$(( $(date +%s) + timeout_seconds )) local state generation observed ready stalled while [ "$(date +%s)" -lt "${deadline}" ]; do state=$(kubectl -n "${namespace}" get helmrelease "${name}" \ -o 'jsonpath={.metadata.generation}{"|"}{.status.observedGeneration}{"|"}{.status.conditions[?(@.type=="Ready")].status}{"|"}{.status.conditions[?(@.type=="Stalled")].status}' \ 2>/dev/null) || state= IFS='|' read -r generation observed ready stalled <}" >&2 if ! kubectl -n "${namespace}" describe helmrelease "${name}" >&2; then echo "The HelmRelease failure diagnostic could not be collected" >&2 fi return 1 fi case "${generation}:${observed}" in *[!0-9:]* | :* | *:) ;; *) if [ "${generation}" -gt "${previous_generation}" ] \ && [ "${observed}" -eq "${generation}" ] \ && [ "${ready}" = True ]; then echo "HelmRelease ${namespace}/${name} reconciled generation ${generation}" return 0 fi ;; esac sleep 5 done echo "HelmRelease ${namespace}/${name} did not reconcile a generation newer than ${previous_generation} within ${timeout_seconds}s" >&2 if ! kubectl -n "${namespace}" describe helmrelease "${name}" >&2; then echo "The HelmRelease timeout diagnostic could not be collected" >&2 fi return 1 } cozy_oidc_bindings() { local test_name="$1" local bindings bindings=$(kubectl --kubeconfig "tenantkubeconfig-${test_name}" get clusterrolebindings \ --selector="app.kubernetes.io/managed-by=cozystack-oidc,app.kubernetes.io/instance=kubernetes-${test_name}" \ -o 'jsonpath={range .items[*]}{.subjects[0].name}{"\t"}{.roleRef.name}{"\n"}{end}') || return 1 printf '%s' "${bindings}" | sort } cozy_assert_oidc_apiserver_flags() { local release="$1" local extra_args # Captured because a pipeline is single-use: a second grep on it reads nothing. extra_args=$(kubectl -n tenant-test get kamajicontrolplane "${release}" \ -o jsonpath='{.spec.apiServer.extraArgs}') printf '%s\n' "${extra_args}" | grep -qF -- '--authentication-config=/etc/kubernetes/authentication-config/config.yaml' printf '%s\n' "${extra_args}" | grep -qF -- '--requestheader-uid-headers=X-Remote-Uid' } cozy_assert_oidc_system() { local test_name="$1" local release="kubernetes-${test_name}" local audience="tenant-test-${release}" local authn_config oidc_kubeconfig bindings kubectl -n tenant-test wait job "${release}-oidc-bootstrap" \ --for=condition=complete --timeout=1m cozy_assert_oidc_apiserver_flags "${release}" authn_config=$(kubectl -n tenant-test get secret "${release}-oidc-authn-config" \ -o jsonpath='{.data.config\.yaml}' | base64 -d) printf '%s\n' "${authn_config}" | grep -qE 'url: https://keycloak\.[^/]+/realms/cozy' printf '%s\n' "${authn_config}" | grep -qF -- "- ${audience}" printf '%s\n' "${authn_config}" | grep -qF -- 'claim: sub' [ "$(kubectl -n tenant-test get keycloakclient.v1.edp.epam.com "${audience}" \ -o jsonpath='{.spec.public}')" = true ] [ "$(kubectl -n tenant-test get keycloakclientscope.v1.edp.epam.com "${audience}-audience" \ -o jsonpath='{.spec.protocolMappers[0].protocolMapper}')" = oidc-audience-mapper ] oidc_kubeconfig=$(kubectl -n tenant-test get secret "${release}-oidc-kubeconfig" \ -o jsonpath='{.data.kubeconfig}' | base64 -d) printf '%s\n' "${oidc_kubeconfig}" | grep -qF -- '- oidc-login' printf '%s\n' "${oidc_kubeconfig}" | grep -qF -- "--oidc-client-id=${audience}" bindings=$(cozy_oidc_bindings "${test_name}") [ "${bindings}" = "$(printf 'e2e-admin@example.test\tcluster-admin\ne2e-viewer@example.test\tview\n' | sort)" ] } cozy_switch_and_assert_oidc_custom_config() { local test_name="$1" local probe= local release="kubernetes-${test_name}" local audience="cozystack-byo-${test_name}" local previous_generation authn_config bindings previous_generation=$(kubectl -n tenant-test get helmrelease "${release}" \ -o jsonpath='{.metadata.generation}') kubectl -n tenant-test patch kuberneteses.apps.cozystack.io "${test_name}" \ --type=merge --patch "$(printf '%s' '{ "spec": { "oidc": { "mode": "CustomConfig", "customConfig": { "config": "apiVersion: apiserver.config.k8s.io/v1beta1\nkind: AuthenticationConfiguration\njwt:\n- issuer:\n url: https://idp.byo.example.test\n audiences:\n - '"${audience}"'\n claimMappings:\n username:\n claim: preferred_username\n prefix: \"\"\n groups:\n claim: groups\n prefix: \"\"\n" }, "users": [ {"email": "byo-admin@example.test", "role": "admin"} ] } } }')" cozy_wait_helmrelease_upgrade tenant-test "${release}" \ "${previous_generation}" 600 kubectl -n tenant-test wait job "${release}-oidc-bootstrap" \ --for=condition=complete --timeout=1m cozy_assert_oidc_apiserver_flags "${release}" authn_config=$(kubectl -n tenant-test get secret "${release}-oidc-authn-config" \ -o jsonpath='{.data.config\.yaml}' | base64 -d) printf '%s\n' "${authn_config}" | grep -qF 'url: https://idp.byo.example.test' printf '%s\n' "${authn_config}" | grep -qF -- "- ${audience}" if printf '%s\n' "${authn_config}" | grep -qE 'url: https://keycloak\.[^/]+/realms/cozy'; then echo "CustomConfig AuthenticationConfiguration still carries the System issuer" >&2 return 1 fi bindings=$(cozy_oidc_bindings "${test_name}") [ "${bindings}" = "$(printf 'byo-admin@example.test\tcluster-admin')" ] # `--ignore-not-found` is what separates "the object is gone" from "could not # ask": absent is exit 0 with empty output, while an RBAC denial, a timeout or # a missing CRD is still non-zero. A bare `if kubectl get ... >/dev/null 2>&1` # reads all of those as gone, so the teardown assertions used to report # success for never having observed anything. if ! probe=$(kubectl -n tenant-test get keycloakclient.v1.edp.epam.com "tenant-test-${release}" \ --ignore-not-found -o name); then echo "could not determine whether the System-mode KeycloakClient is gone" >&2 return 1 fi if [ -n "${probe}" ]; then echo "System-mode KeycloakClient survived the CustomConfig upgrade" >&2 return 1 fi if ! probe=$(kubectl -n tenant-test get keycloakclientscope.v1.edp.epam.com "tenant-test-${release}-audience" \ --ignore-not-found -o name); then echo "could not determine whether the System-mode KeycloakClientScope is gone" >&2 return 1 fi if [ -n "${probe}" ]; then echo "System-mode KeycloakClientScope survived the CustomConfig upgrade" >&2 return 1 fi if ! probe=$(kubectl -n tenant-test get secret "${release}-oidc-kubeconfig" \ --ignore-not-found -o name); then echo "could not determine whether the System-mode OIDC kubeconfig is gone" >&2 return 1 fi if [ -n "${probe}" ]; then echo "System-mode OIDC kubeconfig survived the CustomConfig upgrade" >&2 return 1 fi } # Pure exit-condition for the inter-test drain loop (cozy_wait_tenant_drained). # Each argument is one resource-probe capture: the stdout of a # `kubectl get -o name` (empty once the resource is gone) or the literal "err" # the loop substitutes when a probe itself fails. Returns 0 (drained) only when # every capture holds nothing but whitespace; any capture with a non-whitespace # character -- a resource name, or the "err" sentinel the loop injects on a # probe failure -- yields non-zero, so a transient API blip is never misread as # "the tenant has drained" (same guard as etcd_drain). Pure text logic, # unit-tested in hack/run-kubernetes-drain_test.bats. cozy_tenant_drained() { for _capture in "$@"; do case "$_capture" in *[![:space:]]*) return 1 ;; esac done return 0 } # Keep only PVC resource names that belong to one Kubernetes worker pool. The # worker-disk PVCs carry no cluster label, but CDI preserves the owning # MachineDeployment name inside every one of their generated names. cozy_filter_cluster_pvcs() { local test_name="$1" local capture="$2" printf '%s\n' "${capture}" | awk -v cluster="kubernetes-${test_name}-md0" 'index($0, cluster) != 0' } # Block until one tenant cluster's KubeVirt compute and storage are actually # released, not merely triggered for deletion. Deleting the Kubernetes CR # returns as soon as its finalizers clear, but that only TRIGGERS teardown of # the CAPK worker VMs and their DataVolume-backed disk PVCs. The virt-launcher # pods keep their guest RAM reserved until the VMIs are gone, so without this # barrier the next tenant test's worker VMs begin scheduling against a sandbox # the previous tenant has not yet vacated -> memory starvation -> a worker VM # misses the node-join budget and the test flakes on worker-node-join. # # Bounded and authoritative: this returns non-zero on timeout, so a stuck # teardown cannot be mistaken for a clean sandbox. Other suites use the same # tenant-test namespace and can legitimately leave their own PVCs there while # this cleanup runs; VM/VMI probes therefore select the CAPI cluster label, and # the unlabeled worker-disk PVCs are filtered by their MachineDeployment name # component. cozy_wait_tenant_drained() { local _test_name="$1" local _ns=tenant-test local _timeout="${2:-300}" local _deadline=$(( $(date +%s) + _timeout )) local _cluster="kubernetes-${_test_name}" local _vm _vmi _pvc _pvc_all while :; do _vm=$(kubectl -n "$_ns" get virtualmachines.kubevirt.io \ -l "cluster.x-k8s.io/cluster-name=${_cluster}" -o name 2>/dev/null) || _vm=err _vmi=$(kubectl -n "$_ns" get virtualmachineinstances.kubevirt.io \ -l "cluster.x-k8s.io/cluster-name=${_cluster}" -o name 2>/dev/null) || _vmi=err if _pvc_all=$(kubectl -n "$_ns" get pvc -o name 2>/dev/null); then _pvc=$(cozy_filter_cluster_pvcs "$_test_name" "$_pvc_all") else _pvc=err fi if cozy_tenant_drained "$_vm" "$_vmi" "$_pvc"; then echo "» ${_cluster} VMs/VMIs/PVCs drained from $_ns" return 0 fi if [ "$(date +%s)" -ge "$_deadline" ]; then echo "» ERROR: ${_cluster} teardown did not drain within ${_timeout}s; the next test would face memory/storage pressure" >&2 printf '%s\n' "$_vm" "$_vmi" "$_pvc" | awk 'NF { print " drain-leftover: " $0 }' >&2 return 1 fi sleep 5 done } # Pure predicate for ONE node row of the capture cozy_has_schedulable_node # scans. Encodes the scheduler's own admission rule for a Pod that tolerates # nothing: the NodeUnschedulable plugin rejects a node whose # .spec.unschedulable is set (what `kubectl get nodes` renders as # SchedulingDisabled), and the TaintToleration plugin rejects one carrying any # taint with effect NoSchedule or NoExecute. PreferNoSchedule only lowers the # node's score, so it is deliberately not treated as blocking. Ready is checked # explicitly rather than left to the not-ready taint, so the gate does not # depend on how promptly the node-lifecycle controller applies that taint. # # The backend Pod is not literally toleration-free: DefaultTolerationSeconds # admission gives every Pod a 300s NoExecute toleration for # node.kubernetes.io/not-ready and node.kubernetes.io/unreachable. So for those # two taints this predicate is stricter than the scheduler and would keep # waiting where the Pod could in fact be placed. That errs toward waiting, # never toward releasing the gate early, and requiring Ready makes the case # nearly unreachable anyway. cozy_node_accepts_pods() { # $1 Ready condition status, $2 .spec.unschedulable, $3 taint effects if [ "$1" != True ]; then return 1 fi case "$2" in true | True) return 1 ;; esac case ",$3," in *,NoSchedule,* | *,NoExecute,*) return 1 ;; esac return 0 } # Pure exit-condition for the tenant scheduling gate # (cozy_wait_schedulable_node). The single argument is the capture of a # `kubectl get nodes --no-headers -o custom-columns=NAME,READY,UNSCHEDULABLE,TAINTS`, # one whitespace-separated row per node. custom-columns renders an absent field # as the literal "" and joins several taint effects with a comma, so both # are matched as text. Returns 0 as soon as one row describes a node that would # accept a Pod that tolerates nothing. A failed probe leaves the capture empty, # which reports not-schedulable rather than schedulable, so an API blip can # never release the gate (same guard as cozy_tenant_drained). The scan runs in # the subshell on the right of the pipeline, so its `exit` ends that subshell # and becomes the function's status -- it never leaves the caller. Pure text # logic, unit-tested in hack/run-kubernetes-schedulable_test.bats. cozy_has_schedulable_node() { printf '%s\n' "$1" | { while read -r _name _ready _unschedulable _taints _rest; do if [ -z "$_name" ]; then continue fi if cozy_node_accepts_pods "$_ready" "$_unschedulable" "$_taints"; then exit 0 fi done exit 1 } } # Block until the tenant cluster has at least one node that actually accepts a # Pod, then print the node table it decided on (the same table the failure path # prints, so the two outcomes are read the same way). The node-join gate in # run_kubernetes_test establishes that two nodes are Ready, which is a weaker # guarantee: a Ready node still carries `node.cilium.io/agent-not-ready` until # the tenant's cilium agent claims it, and a node the bringup has not finished # with is Ready,SchedulingDisabled. # Scheduling against such a set is not stuck, only slow, and the time it takes # is variable -- so it belongs in a budget of its own rather than inside the # workload's readiness budget, where it is indistinguishable from a slow image # pull or a failing probe. cozy_wait_schedulable_node() { _kc="$1" _timeout="${2:-300}" _deadline=$(( $(date +%s) + _timeout )) while :; do _nodes=$(kubectl --kubeconfig "$_kc" get nodes --no-headers -o custom-columns='NAME:.metadata.name,READY:.status.conditions[?(@.type=="Ready")].status,UNSCHEDULABLE:.spec.unschedulable,TAINTS:.spec.taints[*].effect' 2>/dev/null) || _nodes="" if cozy_has_schedulable_node "$_nodes"; then echo "» tenant has a node that accepts Pods:" printf '%s\n' "$_nodes" | sed 's/^/ node: /' return 0 fi if [ "$(date +%s)" -ge "$_deadline" ]; then echo "» no tenant node became schedulable (Ready, not cordoned, no NoSchedule/NoExecute taint) within ${_timeout}s" >&2 printf '%s\n' "${_nodes:-}" | sed 's/^/ node: /' >&2 return 1 fi sleep 5 done } # Block until every ZFS storage pool on every LINSTOR satellite reports at # least _min_free_gib of FreeCapacity. Motivation is proven from a # cozyreport artefact captured by hack/cozyreport.sh (see PR #3044 run # 28751310913, LINSTOR satellite ErrorReport 6A4AADFD-349B2-000000): # tearing down a tenant Kubernetes worker with a `replicated` (autoPlace=3, # DRBD) 20 GiB root disk removes the PVC from the API within seconds, but # the ZFS `zvol destroy` on each satellite lags behind by tens of seconds # as DRBD adjusts, unref counts drain and ZFS batch-destroys the datasets. # cozy_wait_tenant_drained above only waits on the API-level PVC delete, # not on the physical satellite space return; if the next tenant test # starts inside that window it hits `zfs create -V ...` failing with # `cannot create '...': out of space`, LINSTOR-CSI then retries autoplace, # each retry racing the still-being-torn-down previous placement and # stretching worker-Machine bringup past the MHC nodeStartupTimeout. # # Two 20 GiB replicated worker targets (60 GiB total per satellite, since # autoPlace=3 places one replica per node) plus two 21 GiB CDI scratch # PVCs (worst case both landing on the same node via the local # storageClass) yields a ~82 GiB per-satellite peak footprint; 90 GiB # default threshold covers that with margin. That makes it a precondition of # the replicated suite rather than a cleanup criterion: volumes earlier suites # legitimately keep can hold a node below it after this suite reclaimed # everything it used, which only the pre-suite baseline can tell apart. It reads # the free capacity LINSTOR caches for thick pools (see # _cozy_linstor_pool_datasets), so it can understate a pool whose last destroy # was still freeing blocks when the satellite reported. cozy_wait_linstor_pool_free() { _min_free_gib="${1:-90}" _timeout="${2:-300}" _min_free_kib=$(( _min_free_gib * 1024 * 1024 )) _deadline=$(( $(date +%s) + _timeout )) while :; do # jq lives inside the controller pod (Debian-bookworm base, `sh` is # dash — keep the heredoc POSIX-safe). LINSTOR's `--machine-readable` # output for `sp l` on LINSTOR 1.33.x is a one-element outer array # whose sole element is a flat array of storage-pool objects; each # pool object exposes free_capacity at the top level in KiB. Filter # to ZFS variants (both `ZFS` and `ZFS_THIN`) so DISKLESS # placeholders (whose free_capacity is a Long.MAX_VALUE sentinel) # and any future non-ZFS driver are skipped. Also guard against # OFFLINE satellites, whose pool objects omit free_capacity entirely # (StoragePool schema marks it optional) — without the null guard # `sort -n` would rank the string "null" ahead of real numbers and # the loop would silently poll to timeout. Emit # `:` lines so a single sort yields the # smallest pool and its owner in one round-trip. _min_line=$(kubectl -n cozy-linstor exec deploy/linstor-controller -- sh -c ' linstor --machine-readable sp l 2>/dev/null | jq -r "first | .[] | select((.provider_kind | test(\"^ZFS\")) and .free_capacity != null) | \"\(.free_capacity):\(.node_name)\"" | sort -n | head -n 1 ' 2>/dev/null) || _min_line="" _min_kib="${_min_line%%:*}" _min_node="${_min_line#*:}" if [ -n "$_min_kib" ] && [ "$_min_kib" -ge "$_min_free_kib" ] 2>/dev/null; then echo "» LINSTOR ZFS pool free: smallest satellite ${_min_node} has $(( _min_kib / 1024 / 1024 )) GiB (>= ${_min_free_gib} GiB threshold)" return 0 fi if [ "$(date +%s)" -ge "$_deadline" ]; then echo "» ERROR: LINSTOR ZFS pool free did not reach ${_min_free_gib} GiB on every satellite within ${_timeout}s (smallest observed: ${_min_kib:-unknown} KiB on ${_min_node:-unknown})" >&2 _pool_diag_rc=0 _pool_diag=$(kubectl -n cozy-linstor exec deploy/linstor-controller -- linstor --no-color sp l 2>&1) || _pool_diag_rc=$? if [ "$_pool_diag_rc" -ne 0 ]; then echo " linstor-pool: diagnostic read failed with exit $_pool_diag_rc" >&2 fi printf '%s\n' "$_pool_diag" | sed 's/^/ linstor-pool: /' >&2 return 1 fi sleep 5 done } _cozy_linstor_pool_baseline_file() { printf '%s\n' "${COZY_LINSTOR_POOL_BASELINE_FILE:-_out/e2e-kubernetes-linstor-pool-baseline}" } # Print every ZFS dataset under each node's LINSTOR storage pool as # `node dataset` rows, the pool's own root included, so a node whose pool holds # no volume still shows up as read. The names come from `zfs list` on the # satellite rather than from LINSTOR's free capacity: on a node with only thick # pools `linstor sp l` serves the figure cached at the satellite's last report, # which can be taken while `zfs destroy` is still freeing blocks in the # background, so a pool can read hundreds of MiB short of its baseline until # some later report with nothing left on it. A destroyed dataset's name is gone # by the time `zfs destroy` returns. The zpool is read off the pool's # `StorDriver/StorPoolName` property, under which LINSTOR stores the zpool of # both ZFS drivers, because it differs by lane: `data` on QEMU nodes, # `data-srvN` in container mode, where every node's pool is imported into one # shared kernel. Every read carries its own ceiling, so a wedged controller or # satellite fails the poll within 35s instead of holding the caller for good. _cozy_linstor_pool_datasets() { _pools=$(timeout -k 5 30 kubectl -n cozy-linstor exec deploy/linstor-controller -- sh -c ' linstor --machine-readable sp l 2>/dev/null | jq -r "first | .[] | select(.provider_kind | test(\"^ZFS\")) | \"\(.node_name) \(.props[\"StorDriver/StorPoolName\"] // \"\")\"" ' 2>/dev/null) || return 1 [ -n "$_pools" ] || return 1 _satellites=$(timeout -k 5 30 kubectl -n cozy-linstor get pods -l app.kubernetes.io/component=linstor-satellite \ -o jsonpath='{range .items[*]}{.spec.nodeName} {.metadata.name}{"\n"}{end}' 2>/dev/null) || return 1 while read -r _node _zpool; do [ -n "$_node" ] && [ -n "$_zpool" ] || return 1 _pod=$(printf '%s\n' "$_satellites" | awk -v node="$_node" '$1 == node { print $2; exit }') [ -n "$_pod" ] || return 1 _datasets=$(timeout -k 5 30 kubectl -n cozy-linstor exec "$_pod" --container=linstor-satellite -- \ zfs list -H -o name -t filesystem,volume,snapshot -r "$_zpool" /dev/null) || return 1 [ -n "$_datasets" ] || return 1 printf '%s\n' "$_datasets" | awk -v node="$_node" '{ print node " " $0 }' done <"$_baseline_file" _baseline=$(_cozy_linstor_pool_datasets) || _baseline="" if [ -z "$_baseline" ]; then echo "» ERROR: could not record the LINSTOR pool baseline; reclamation of this suite's volumes would be unverifiable" >&2 return 1 fi _baseline_nodes=$(printf '%s\n' "$_baseline" | awk '{ print $1 }' | sort -u | tr '\n' ' ') if [ "$_baseline_nodes" != "srv1 srv2 srv3 " ] \ || printf '%s\n' "$_baseline" | awk 'NF != 2 { bad = 1 } END { exit !bad }'; then echo "» ERROR: LINSTOR pool baseline is incomplete or malformed (expected 'node dataset' rows for srv1, srv2 and srv3): ${_baseline}" >&2 return 1 fi printf '%s\n' "$_baseline" >"$_baseline_file" echo "» LINSTOR pool baseline recorded:" printf '%s\n' "$_baseline" | sed 's/^/ baseline-dataset: /' } # Pure comparison of two `node dataset` listings. Prints `new ` # for each dataset the current listing has and the baseline does not, and # `unread ` for each baseline node the current listing lacks, and fails # when it printed anything. A baseline dataset that is gone is not a finding: # the suite may have reclaimed something an earlier one left. cozy_linstor_pool_new_datasets() { [ -n "$1" ] && [ -n "$2" ] || return 1 { printf '%s\n' "$1" printf '%s\n' '--' printf '%s\n' "$2" } | awk ' !current && $0 == "--" { current = 1; next } !current { seen[$0] = 1; base[$1] = 1; next } { read_nodes[$1] = 1; if (!($0 in seen)) { print "new " $0; bad = 1 } } END { for (node in base) if (!(node in read_nodes)) { print "unread " node; bad = 1 } exit bad }' } cozy_wait_linstor_pool_baseline() { _timeout="${1:-300}" _baseline_file=$(_cozy_linstor_pool_baseline_file) # Returns 2 here and 1 on a timeout, so the caller can tell an unchecked # reclamation from a failed one. if [ ! -s "$_baseline_file" ]; then echo "» ERROR: no LINSTOR pool baseline was recorded for this suite, so it stopped before creating its tenant; reclamation was not checked" >&2 return 2 fi _baseline=$(cat "$_baseline_file") _deadline=$(( $(date +%s) + _timeout )) _current="" _residue="" while :; do _current=$(_cozy_linstor_pool_datasets) || _current="" if [ -n "$_current" ] && _residue=$(cozy_linstor_pool_new_datasets "$_baseline" "$_current"); then echo "» LINSTOR pools hold no dataset beyond their pre-suite baseline" return 0 fi if [ "$(date +%s)" -ge "$_deadline" ]; then echo "» ERROR: LINSTOR pools did not return to their pre-suite baseline within ${_timeout}s; a worker or CDI scratch volume may still occupy ZFS space" >&2 if [ -z "$_current" ]; then echo " linstor-pool: the dataset probe returned nothing" >&2 else printf '%s\n' "$_residue" | sed 's/^/ linstor-pool: /' >&2 fi return 1 fi sleep 5 done } # Unconditional cleanup hook, invoked from the kubernetes-* tests' Chainsaw # `finally` block (which always runs, after any crust-gather `catch`). The tenant # Kubernetes CR is applied imperatively (kubectl) inside run_kubernetes_test, so # Chainsaw's auto-cleanup does not track it — `finally` is where it gets # reclaimed. A failed run otherwise leaves the tenant cluster's worker-VM PVCs # (tens of GiB) in tenant-test, exhausting the shared tenant-quota and # cascade-failing every storage-heavy suite that runs afterwards. Cleanup # failures are accumulated so every safe reclamation attempt still runs, then # returned to Chainsaw: a passing workload on a dirty sandbox is not a pass. cozy_cleanup() { local test_name="${1:-}" local cleanup_failed=0 # Delete any test-scoped tenant API LoadBalancer Services left by a failed run # so they don't leak MetalLB IPs from the shared host pool. Labeled by the # test so a single selector reaps them all. if ! kubectl -n tenant-test delete service -l cozystack-e2e.io/tenant-api-lb --ignore-not-found --wait=false 2>/dev/null; then echo "» ERROR: failed to delete tenant API LoadBalancer Services" >&2 cleanup_failed=1 fi # A failed node-join capture creates a short-lived reader Certificate and a # hardened helper Pod. They are labelled separately from the tenant API LB: # the Secret contains a Talos client key and must be reaped even if the # diagnostic collector itself returned early. if ! kubectl -n tenant-test delete certificates.cert-manager.io -l cozystack-e2e.io/tenant-talos-diagnostics --ignore-not-found --wait=true --timeout=30s 2>/dev/null; then echo "» ERROR: failed to delete tenant Talos diagnostic Certificates" >&2 cleanup_failed=1 fi if ! kubectl -n tenant-test delete pod,secret -l cozystack-e2e.io/tenant-talos-diagnostics --ignore-not-found --wait=false 2>/dev/null; then echo "» ERROR: failed to delete tenant Talos diagnostic Pod/Secret" >&2 cleanup_failed=1 fi # Delete worker node pools (KubernetesNodes) before the parent Kubernetes CR: # the pool owns the workers and its pre-delete hook unpins the adopted objects # so uninstall is clean. Chainsaw does not track this imperatively applied CR, # so cozy_cleanup must reap it too. local child_drained=0 if ! kubectl -n tenant-test delete kubernetesnodeses.apps.cozystack.io --all --ignore-not-found --wait=true --timeout=5m 2>/dev/null; then echo "» ERROR: tenant KubernetesNodes did not delete within 5m" >&2 cleanup_failed=1 else child_drained=1 fi if [ "$child_drained" -eq 1 ]; then if ! kubectl -n tenant-test delete kuberneteses.apps.cozystack.io --all --ignore-not-found --wait=true --timeout=5m 2>/dev/null; then echo "» ERROR: tenant Kubernetes resources did not delete within 5m" >&2 cleanup_failed=1 fi else echo "» ERROR: refusing to delete parent Kubernetes resources while KubernetesNodes remain" >&2 fi # The CR delete above finalizes once the Kubernetes CR is gone, which only # TRIGGERS KubeVirt VM teardown + PVC release. Block until the worker VMs, # VMIs (guest RAM) and disk PVCs are actually gone so the next tenant test # starts on a freed sandbox -- the root cause of the node-join flake. if [ -n "${test_name}" ]; then if ! cozy_wait_tenant_drained "${test_name}" 300; then echo "» ERROR: scoped tenant resources did not drain" >&2 cleanup_failed=1 fi else echo "» ERROR: cleanup has no test name; scoped tenant drain cannot be verified" >&2 cleanup_failed=1 fi # Wait for this suite's saved per-node baseline: that catches a volume LINSTOR # has not destroyed yet, or never will, without requiring volumes the suite # did not create to vanish. Blocks a destroy is still freeing do not count. local pool_rc=0 cozy_wait_linstor_pool_baseline 300 || pool_rc=$? if [ "$pool_rc" -eq 1 ]; then echo "» ERROR: LINSTOR pools did not return to the pre-suite level" >&2 fi [ "$pool_rc" -eq 0 ] || cleanup_failed=1 return "$cleanup_failed" } # Where a suite's captures land, spelled once, so a handler that writes beside # the snapshot cannot drift from where the snapshot actually goes. _cozy_suite_snapshot_dir() { printf '%s\n' "${COZY_REPORT_DIR:-/workspace/_out/cozyreport}/snapshots/${COZY_SNAPSHOT_NAME:-kubernetes}" } # Snapshot the tenant cluster (its cilium/CSI/coredns internals) on a failed run. # Reached from _tenant_failure_on_exit, which run_kubernetes_test installs as an # EXIT trap, so it fires during THIS test subshell's exit, before the success # path (or cozy_cleanup) deletes the tenant API LoadBalancer. crust-gather # reaches the tenant only through the kubeconfig's server URL (it connects # directly — no host-proxy mode — and the in-cluster URL is unreachable from the # runner), which is the LB IP and stays routable until teardown. # CURRENT_TENANT_KC is a global so the handler can read it regardless of # function scope at EXIT-trap time. # # Takes the failing exit status as $1 rather than reading $? itself, because the # handler that calls it runs a collector first and $? at entry would be that # collector's status. _tenant_snapshot_on_fail() { local _rc="$1" [ "$_rc" -eq 0 ] && return 0 command -v crust-gather >/dev/null 2>&1 || return 0 [ -n "${CURRENT_TENANT_KC:-}" ] && [ -f "${CURRENT_TENANT_KC}" ] || return 0 # COZY_SNAPSHOT_NAME is the Chainsaw test name (set in the kubernetes-* test's # script env), so the tenant snapshot co-locates with the host snapshot the # global .chainsaw.yaml catch writes under snapshots//. Falls back to a # generic name if sourced outside the Chainsaw harness. _snap=$(_cozy_suite_snapshot_dir) mkdir -p "$_snap" 2>/dev/null || true echo "» capturing tenant crust-gather snapshot (${CURRENT_TENANT_KC}) before teardown" # Bounded with a timeout for the same reason as the host snapshot in # cozytest.sh: an unbounded collect can hang for hours and wedge the job. # --duration is crust-gather's own collection budget (default 60s, which # silently truncates and skips its finish step on elapse); the outer # wall-clock has to exceed it because the API discovery that runs first is # not covered by that budget at all. # (timeout's own -k 30 / 360 are distinct from crust-gather's -k kubeconfig.) # Output goes to a log beside the snapshot instead of /dev/null so "complete # or truncated?" is answerable from the artifact, as for the host snapshot. _cg_rc=0 # --disable-additional-logs: the host-log leg spawns a privileged debug pod per # node, which baseline PodSecurity rejects (403); its retry loop then burns the # whole --duration and crust-gather exits 1. Skip it — it collects nothing here. timeout -k 30 360 crust-gather collect -k "${CURRENT_TENANT_KC}" --disable-additional-logs --duration 180s \ --exclude-kind Secret -f "$_snap/${CURRENT_TENANT_KC}" \ >"$_snap/crust-gather-${CURRENT_TENANT_KC}.log" 2>&1 || _cg_rc=$? case "$_cg_rc" in 0) echo "» tenant crust-gather snapshot complete (${CURRENT_TENANT_KC})" ;; 124 | 137) echo "» tenant crust-gather snapshot TRUNCATED (wall-clock $_cg_rc); partial state kept, see $_snap/crust-gather-${CURRENT_TENANT_KC}.log" ;; *) echo "» tenant crust-gather snapshot FAILED (exit $_cg_rc); see $_snap/crust-gather-${CURRENT_TENANT_KC}.log" ;; esac } # The EXIT handler run_kubernetes_test arms at the Kubernetes CR apply, which is # earlier than either collector needs the tenant: the parent HelmRelease exists # from that point and the classification reads the management cluster, while the # snapshot half stays a no-op until CURRENT_TENANT_KC is assigned. Two # collectors, in this order and for the reason the diagnostics conventions give # for it: the classification is a handful of bounded reads against the # management cluster and it discriminates between failure modes, while the # snapshot costs minutes. Run the other way round, a snapshot that spends its # wall clock would take the classification with it. # # The classification also sits ahead of the two guards below it, because neither # is about it: a runner without crust-gather, or a run whose tenant kubeconfig # never materialised, says nothing about the HelmReleases, which live on the # management cluster and are readable either way. # # Neither collector may fail the handler. The status the suite exits with is the # one that was in effect when the trap was entered, and it is what the Chainsaw # step reports. _tenant_failure_on_exit() { local _exit_rc=$? [ "$_exit_rc" -eq 0 ] && return 0 cozy_report_helmrelease_remediation tenant-test "${CURRENT_TENANT_PARENT_HR:-}" || true _tenant_snapshot_on_fail "$_exit_rc" || true } # Render name|IP rows for worker VMIs from a `kubectl get ... -o json` document. # Kept pure so an absent default interface is represented by an empty IP instead # of silently dropping the VMI from the diagnostic report. cozy_tenant_worker_vmi_rows() { jq -r '.items[] | [.metadata.name, ([.status.interfaces[]? | select(.name == "default") | .ipAddress][0] // "")] | join("|")' } # Ask cert-manager for a short-lived, read-only Talos client certificate. The # tenant chart deliberately uses TalosConfigTemplate generateType=none, so CABPT # creates no client talosconfig for this worker-only Kamaji topology. Reusing the # existing Talos CA Issuer avoids materialising an os:admin credential or copying # the CA private key out of Kubernetes. cozy_apply_tenant_talos_reader_certificate() { local test_name="$1" local release="kubernetes-${test_name}" local certificate="${release}-e2e-talos-reader" kubectl apply --request-timeout=30s -f - </dev/null 2>&1 || return 1 kubectl -n tenant-test delete secret "${certificate}" \ --ignore-not-found --wait=true --timeout=10s >/dev/null 2>&1 || return 1 cozy_apply_tenant_talos_reader_certificate "${test_name}" || return 1 # cert-manager issuance is asynchronous. Wait on its actual Ready condition; # on expiry, preserve Certificate diagnostics without ever printing the # generated Secret. if ! kubectl_wait_retry -n tenant-test certificate "${certificate}" \ --for=condition=Ready --timeout=30s; then echo "tenant Talos reader Certificate was not issued within 30s" >&2 kubectl -n tenant-test describe certificate "${certificate}" --request-timeout=30s >&2 || true kubectl -n tenant-test get certificaterequests.cert-manager.io \ -l cert-manager.io/certificate-name="${certificate}" -o wide --request-timeout=30s >&2 || true return 1 fi kubectl -n tenant-test get secret "${release}-talos-ca" \ -o go-template='{{index .data "tls.crt" | base64decode}}' --request-timeout=30s >"${workdir}/ca.crt" || return 1 kubectl -n tenant-test get secret "${certificate}" \ -o go-template='{{index .data "tls.crt" | base64decode}}' --request-timeout=30s >"${workdir}/client.crt" || return 1 kubectl -n tenant-test get secret "${certificate}" \ -o go-template='{{index .data "tls.key" | base64decode}}' --request-timeout=30s >"${workdir}/client.key" || return 1 talosctl --talosconfig "${workdir}/talosconfig" config add "${release}" \ --ca "${workdir}/ca.crt" --crt "${workdir}/client.crt" \ --key "${workdir}/client.key" || return 1 talosctl --talosconfig "${workdir}/talosconfig" config context "${release}" || return 1 chmod 600 "${workdir}/talosconfig" ) # Apply the helper Pod separately from its readiness/copy steps so its security # invariants have focused unit coverage. The Pod runs on the management cluster # in the same namespace as bridge-networked worker VMIs, which lets talosctl use # each real VMI IP as both endpoint and node and keeps server-TLS verification # valid. A MetalLB or localhost port-forward address would not be in the Talos # serving certificate SANs. cozy_apply_tenant_talos_diagnostics_pod() { local test_name="$1" local pod_name="kubernetes-${test_name}-talos-diagnostics" kubectl apply --request-timeout=30s -f - </dev/null 2>&1 || return 1 cozy_apply_tenant_talos_diagnostics_pod "${test_name}" || return 1 if ! kubectl -n tenant-test wait pod "${pod_name}" \ --for=condition=Ready --timeout=60s; then kubectl -n tenant-test describe pod "${pod_name}" --request-timeout=30s >&2 || true kubectl -n tenant-test get events \ --field-selector involvedObject.name="${pod_name}" \ --sort-by=.lastTimestamp --request-timeout=30s >&2 || true return 1 fi if ! timeout -k 5 60 kubectl -n tenant-test exec -i "${pod_name}" \ -c diagnostics -- sh -ec 'cat > /tmp/talosctl && chmod 500 /tmp/talosctl' \ <"${talosctl_bin}"; then echo "failed to stream talosctl into tenant diagnostics Pod" >&2 return 1 fi if ! timeout -k 5 20 kubectl -n tenant-test exec -i "${pod_name}" \ -c diagnostics -- sh -ec 'umask 077; cat > /tmp/talosconfig; chmod 600 /tmp/talosconfig' \ <"${talosconfig}"; then echo "failed to stream tenant talosconfig into diagnostics Pod" >&2 return 1 fi } # Capture one bounded Talos command through the helper Pod and retain the exit # status alongside partial output. A timeout or unreachable pre-apid worker is # itself useful evidence and must not erase captures from the other worker. # # The bound is the caller's rather than a constant here because the reads differ # in kind: two of them stream (a kernel ring buffer, five hundred lines of # service log) and two are single tabular RPCs that a reachable apid answers at # once. The whole walk sits inside the collector the diagnostics phase budget is # sized against, so a second spent here is a second the collectors gated after # it do not get -- and a bound picked for the streams, applied to the tabular # reads, buys nothing and costs that. cozy_capture_tenant_talos_command() { local pod_name="$1" local node_ip="$2" local output="$3" local bound="$4" shift 4 local rc=0 timeout -k 5 "${bound}" kubectl -n tenant-test exec "${pod_name}" -c diagnostics -- \ /tmp/talosctl --talosconfig /tmp/talosconfig \ -e "${node_ip}" -n "${node_ip}" "$@" >"${output}" 2>&1 || rc=$? printf '\n[capture exit code: %s]\n' "${rc}" >>"${output}" return "${rc}" } cozy_capture_tenant_talos_node() { local pod_name="$1" local node_ip="$2" local output_dir="$3" local answered=0 mkdir -p "${output_dir}" printf 'endpoint: %s\nnode: %s\n' "${node_ip}" "${node_ip}" >"${output_dir}/target.txt" cozy_capture_tenant_talos_command "${pod_name}" "${node_ip}" \ "${output_dir}/dmesg.log" 20 dmesg && answered=$((answered + 1)) cozy_capture_tenant_talos_command "${pod_name}" "${node_ip}" \ "${output_dir}/kubelet.log" 20 logs kubelet --tail=500 && answered=$((answered + 1)) # The service state machine, which answers what the kubelet log cannot when # there is no kubelet log to read. Talos creates a service's log buffer when # its runner opens the log writer, which the runner does as it starts the # process -- so a kubelet still Waiting on its volumes, on time sync, or on # the container runtime reporting healthy has never reached its runner, has no # buffer, and `logs kubelet` fails with `log "kubelet" was not registered`. # That is a true statement about the log and says nothing about the service, # while the state and the condition being waited on are the finding. One call # covers every service, so the runtime the kubelet is waiting for arrives in # the same file. cozy_capture_tenant_talos_command "${pod_name}" "${node_ip}" \ "${output_dir}/services.log" 10 services && answered=$((answered + 1)) # Read as yaml because MTU lives in the LinkStatus spec and not among the # resource's print columns, so the default table omits the one field this is # read for: a guest at 1500 over an encapsulated fabric drops the large # segments and passes the small ones, which is the signature a stalled # transfer beside a healthy probe presents. cozy_capture_tenant_talos_command "${pod_name}" "${node_ip}" \ "${output_dir}/links.yaml.log" 10 get links -o yaml && answered=$((answered + 1)) # Stated for the worker rather than per read, because per read it is already # stated and still invisible: with apid refusing the connection each log holds # its own rpc error and an exit code, accurate one file at a time and adding # up to a directory that looks like a worker with little to report. Written # only when nothing completed, so a worker that answered one read of the four # is not written up as unreachable. # # `answered` counts reads that COMPLETED, and the wording below is bounded by # that rather than claiming more. A read killed at its bound has already # written what it managed to read, so the directory can hold real evidence # while nothing in it exited zero -- which is the slow-apid worker, the shape # this capture is most often reached on. A marker saying nothing was observed # would be the collector making exactly the unsupported claim the arms above # exist to prevent, one directory up. if [ "${answered}" -eq 0 ]; then # `|| true` on the write, not only `return 0` below: under a live errexit a # failing redirect aborts AT the redirect, so a trailing return never runs # and cannot be what carries the guarantee. A full scratch directory on the # runner is how this fails. printf '%s\n' \ 'no Talos read completed for this worker: all four failed or were cut short, so this directory holds no whole capture -- what is here is whatever arrived before a read was killed, or the error a read returned, and each log carries its own reason and exit code' \ >"${output_dir}/CAPTURE-FAILED.txt" || true fi # Defensive rather than load-bearing today, and worth saying which: the one # call site reaches this through `cozy_capture_tenant_talos ... || true`, and # that suppression covers the whole subshell and everything it calls, so no # status returned from here can end the worker walk. What this pair buys is # that the guarantee survives a caller that drops the `|| true` -- the walk # continues to the next worker because nothing in here fails, rather than # because of how the call happens to be written. return 0 } # Name the console experiment's own failure before the noise starts. Enabling # logSerialConsole punches through the platform's cluster-wide disable, and if # kubevirt/kubevirt#15989 still bites, guest-console-log wedges virt-launcher # in Init: the workers never boot, no Node registers, and the suite reports # "fewer than 2 tenant nodes Ready within 29m" -- byte-identical to the failure # this instrumentation was added to study. A triager reading that line files it # as the known flake and the experiment's answer is lost at the bottom of # POD-STATE.txt. A diagnostic whose own worst case is disguised as the bug it # investigates is worth less than none, so it says so itself, and says it # first. # # The bit it reads is `ready` on the init container. This sidecar is built with # no probes at all, and kubelet's UpdatePodStatus sets `ready = !exists` for a # container with no readiness worker once it is running -- liveness is not an # input to readiness anywhere. So the bit is exactly "the container is # running", and false means not running: never-started, waiting between # restarts, or already-terminated. Running-but-not-ready is not a shape this # container can hold, which is why the taxonomy below does not claim it. # Those are not one finding: the hang starts the container and then fails it, # so with restartPolicy Always it settles into CrashLoopBackOff and passes # through Error, while a superseded virt-launcher from a VM restart exits # cleanly and terminates Completed. ContainerState is a union, so a waiting # reason alone leaves the terminated case blank and cannot tell the two apart. # Both reasons are carried so each shape arrives labelled. # # Even so this line points rather than concludes, and it says so out loud: the # bit cannot separate every shape, the describe that follows can, and a # headline that asserts more than the bit carries is the same mislabel this # function exists to prevent, merely pointing the other way. cozy_report_guest_console_wedge() { local rows read_rc=0 local read_err if ! read_err=$(mktemp); then # Same rule as the read-failure branch below: saying nothing here would # read as "the console container is fine" when nothing was checked. echo "=== could not allocate a scratch file to read virt-launcher Pod state; whether guest-console-log started is unknown, not fine ===" return 0 fi rows=$(timeout -k 5 30 kubectl -n tenant-test get pods \ -l kubevirt.io=virt-launcher \ -o jsonpath='{range .items[*]}{range .status.initContainerStatuses[?(@.name=="guest-console-log")]}{.ready}{" "}{.state.waiting.reason}{.state.terminated.reason}{" "}{end}{.metadata.name}{"\n"}{end}' \ --request-timeout=30s 2>"${read_err}") || read_rc=$? if [ "${read_rc}" -ne 0 ]; then # Silence here would be the same mislabel inverted: the reader would take # the absent headline as "the console container is fine" when nothing was # actually checked. echo "=== could not read virt-launcher Pod state (exit ${read_rc}); whether guest-console-log started is unknown, not fine ===" cat "${read_err}" || true rm -f "${read_err}" return 0 fi rm -f "${read_err}" case "${rows}" in *"false "*) ;; *) return 0 ;; esac echo "=== guest-console-log is not running on the workers below; if these are current Pods this is the console experiment failing rather than the node-join failure it instruments (kubevirt/kubevirt#15989) ===" echo "=== a reason of CrashLoopBackOff or Error below is the wedge shape (kubevirt/kubevirt#15989); Completed is a superseded Pod and not this bug; any other reason, or none, is not covered by either and the describe that follows settles it ===" echo "=== if it is the wedge: the cluster-wide disableSerialConsoleLog in packages/system/kubevirt exists for this, and dropping logSerialConsole from the e2e node group returns the suite to its prior behaviour ===" printf '%s\n' "${rows}" | grep '^false ' || true } # Check that KubeVirt actually attached the guest console container, on the # path where the workers did boot. The capture below runs only when node-join # fails, so without this the suite would first learn that the node group's # logSerialConsole never took effect in the run that needed the console, when # it can no longer be recovered. The platform disables console logging # cluster-wide (see packages/system/kubevirt), so what this asks is whether # the per-VM override beat that on the KubeVirt version actually shipping. # # The read's own status is kept separate from the answer it returns, and the # two get different exit codes, because they are different claims. Piping # kubectl into grep would collapse them: a read that failed produces no output, # grep finds nothing, and an API blip would be reported as "the override did # not take effect" -- a cause that was never established, sending the next # reader at KubeVirt config instead of at the apiserver. A selector that # matched no Pod at all is the same trap one step further on, and is kept # apart from a Pod that matched and carries nothing -- the second is the # finding, the first is not a statement about any Pod. # # What it establishes is that SOME virt-launcher Pod in the namespace carries # the container, not that every one does. That is the direction worth erring # in for a check whose only job is to catch an inert setting: it can miss, but # it cannot fail a run over a Pod that is not this test's. The match runs over # the whole name=containers line, so a Pod named after the container would # satisfy it -- these names come from the Machine name, so that cannot happen # here, but a reader changing the format should know the glob spans both. # # 0 a Pod carries the container # 1 the read did not answer, or matched no Pod; not evidence either way # 2 Pods matched and none carries the container cozy_assert_guest_console_attached() { local init_names read_rc=0 local attached total # The Pod name is in the output for a reason that is not cosmetic: without # it, a Pod whose initContainers list is absent emits a bare newline, command # substitution strips it, and "Pods matched, none carries the container" is # byte-identical to "no Pod matched". Those two must not collapse -- the # first is the finding this whole check exists for, and on these workers it # is also the only shape it can take, since guest-console-log is the only # init container a DataVolume-booted virt-launcher Pod ever has. init_names=$(timeout -k 5 30 kubectl -n tenant-test get pods \ -l kubevirt.io=virt-launcher \ -o jsonpath='{range .items[*]}{.metadata.name}{"="}{.spec.initContainers[*].name}{" "}{.spec.containers[*].name}{"\n"}{end}' \ --request-timeout=30s) || read_rc=$? if [ "${read_rc}" -ne 0 ]; then echo "could not read tenant virt-launcher Pods to verify the guest console container (exit ${read_rc})" >&2 echo "this says nothing about logSerialConsole either way; continuing" >&2 return 1 fi if [ -z "${init_names}" ]; then echo "no tenant virt-launcher Pod matched; nothing to verify about the guest console container" >&2 echo "this says nothing about logSerialConsole either way; continuing" >&2 return 1 fi case "${init_names}" in *guest-console-log*) # The positive outcome goes on the record too. This run doubles as the # revalidation of a platform-wide workaround, and a check that returns # 0 in silence leaves "the override worked" to be inferred from the # absence of a complaint -- the inference this collector refuses to # make everywhere else. Counted rather than asserted for every Pod: the # check is deliberately "some Pod carries it", so the ratio is the # honest way to say what was seen. attached=$(printf '%s\n' "${init_names}" | grep -c 'guest-console-log' || true) total=$(printf '%s\n' "${init_names}" | grep -c '=' || true) echo "» guest-console-log attached on ${attached} of ${total} virt-launcher Pods" return 0 ;; esac echo "tenant worker virt-launcher Pods carry no guest-console-log container" >&2 echo "the node group asked for logSerialConsole, so either the cluster-wide" >&2 echo "disableSerialConsoleLog won the override or the field never reached the VM" >&2 # Bounded like the read above, and for the same reason: these run on a path # that ends in exit 1, and a hang here would take the step's whole deadline # with it -- losing the tenant snapshot that the exit is supposed to reach. timeout -k 5 30 kubectl -n tenant-test get pods -l kubevirt.io=virt-launcher \ -o jsonpath='{range .items[*]}{.metadata.name}{": "}{.spec.initContainers[*].name}{"\n"}{end}' \ --request-timeout=30s || true timeout -k 5 30 kubectl -n tenant-test get virtualmachineinstances.kubevirt.io \ -o jsonpath='{range .items[*]}{.metadata.name}{": logSerialConsole="}{.spec.domain.devices.logSerialConsole}{"\n"}{end}' \ --request-timeout=30s || true return 2 } # Summarise the kubelet-image leg from one already-captured guest console. Talos # does not print a separate "pull complete" line: the next kubelet milestone is # Creating service runner, after the image has been fetched and unpacked. Keep # that distinction in the label. The source is explicit because e2e deliberately # leaves the chart's registryMirrors empty and exercises the public GHCR path. _cozy_guest_kubelet_image_timing() { local pod="$1" local console_log="$2" awk -v pod="$pod" ' function guest_seconds(line, value) { value = line sub(/^\[[[:space:]]*/, "", value) sub(/\].*$/, "", value) return value + 0 } /pulling image ghcr\.io\/siderolabs\/kubelet:/ && !have_start { have_start = 1 started = guest_seconds($0) image = $0 sub(/^.*pulling image /, "", image) sub(/: starting\.\.\..*$/, "", image) next } have_start && !have_runner && /service\[kubelet\]\(Preparing\): Creating service runner/ { have_runner = 1 runner = guest_seconds($0) } have_start && !have_healthy && /service\[kubelet\]\(Running\): Health check successful/ { have_healthy = 1 healthy = guest_seconds($0) } END { if (!have_start) { exit } printf "» tenant worker %s guest timing: kubelet image %s", pod, image if (have_runner) { printf " fetch+unpack %.3fs (guest %.3fs -> %.3fs)", runner - started, started, runner } else { printf " fetch+unpack incomplete (started at guest %.3fs)", started } if (have_healthy) { printf "; kubelet healthy at guest %.3fs", healthy } printf "; source=ghcr.io (no e2e registry mirror)" printf "\n" } ' "$console_log" } # Capture each tenant worker's guest serial console from the management # cluster. When a node group sets logSerialConsole, KubeVirt streams the # console into a guest-console-log container beside virt-launcher, and reading # it needs nothing from inside the guest: no talosctl, no client certificate, # no helper Pod, no reachable apid. That is the whole reason it exists. The # talosctl capture below can only describe a worker whose apid already answers, # so a worker that stalls earlier -- the case where no Node registers and no # certificate request is ever made -- is invisible to it by construction, and # the console is the only remaining surface. # # Reads start at the beginning of the stream rather than tailing it, because a # guest that repaints its console would push the boot output out of any tail # window while --limit-bytes truncates from the far end instead. That covers # only what kubectl returns: whatever the kubelet has already rotated out of # the container log (containerLogMaxSize, 10Mi x 5 by default) is gone before # the capture runs, and no read option recovers it. # # An absent guest-console-log container is the finding, not a gap: it says # console logging did not take effect on this run, which is a different fact # from a guest that printed nothing. kubectl's refusal is kept beside the # capture rather than inside it so the two stay distinguishable, and the # capture file says which of them happened. # # The Pod list is namespace-wide rather than scoped to one release. The two # virt-launcher captures immediately above the call site already select that # way, and suites run one at a time. Below the cap a Pod that does not belong # to this test costs one extra file named after itself and nothing else; at # the cap it can displace one of this suite's own, since kubectl returns the # list name-sorted. COLLECTION-TRUNCATED.txt is what keeps that visible. # # Takes the context it was called in, because it is called from both paths and # both write here. On the failure path the console is the evidence; on the # passing path it is the baseline that evidence is read against, and the two are # the same files in the same directory. Which one a tarball holds is otherwise # recoverable only from the run's verdict somewhere else entirely, so the # capture states it. cozy_capture_tenant_serial_console() { local context="$1" # How many Pods the walk may cover, taken from the caller because the two # paths have different room. The failure path runs inside a phase whose budget # is derived against the whole op, so it can afford the pool at its maximum. # The passing path has no phase and no budget of its own: it runs inside the # same operation whose ceiling the suite has already spent most of, and a # diagnostic that turns a suite green-then-red for running long would be worse # than the missing baseline it exists to collect. So that caller asks for the # pool's minimum, which is what a boot baseline needs -- two workers booting # is the same measurement as ten -- and the cap that fires records what it # dropped either way. local max_pods="$2" local report_dir="${COZY_REPORT_DIR:-/workspace/_out/cozyreport}/snapshots/${COZY_SNAPSHOT_NAME:-kubernetes}/tenant-serial-console" local pods pod rc local list_rc=0 local seen=0 local walked=0 local silent=0 local cut_short=0 local pod_err read_at read_done local timeline timeline_err timeline_why timeline_rc=0 timeline_err_kept=0 local err_log="${report_dir}/setup-error.log" local warn_log="${report_dir}/READ-WARNINGS.txt" mkdir -p "${report_dir}" # Written before the first read, not after the walk: the outcome this most # needs to be legible in is the one where nothing was captured, and every # early return below leaves the directory holding a note alone. printf '%s\n' "${context}" >"${report_dir}/CAPTURE-CONTEXT.txt" # stderr goes to its own file rather than being folded into the captured # stdout: a warning kubectl prints on an otherwise successful call would # otherwise be read back as a Pod name. Which file it goes to is decided by # the exit status, not by the fact that something was written: an apiserver # Warning header or a deprecation notice arrives on stderr with a zero exit, # so a warning beside a healthy read belongs in READ-WARNINGS.txt as # elsewhere in this tree, while the stderr of a call that actually failed IS # the diagnosis and belongs in setup-error.log. The list is wrapped in # timeout for the same reason every read below it is: --request-timeout # bounds the HTTP request, not a client retrying against a wedged # apiserver, and a hang here would cost the whole # section rather than one Pod. pods=$(timeout -k 5 30 kubectl -n tenant-test get pods -l kubevirt.io=virt-launcher \ -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' \ --request-timeout=30s 2>"${warn_log}") || list_rc=$? if [ "${list_rc}" -ne 0 ]; then echo "failed to list tenant virt-launcher Pods for serial console capture" >&2 mv "${warn_log}" "${err_log}" 2>/dev/null || true printf '%s\n' \ "failed to list tenant virt-launcher Pods for serial console capture (exit ${list_rc})" \ >>"${err_log}" return 1 fi [ -s "${warn_log}" ] || rm -f "${warn_log}" if [ -z "${pods}" ]; then echo "no virt-launcher Pod found for serial console capture" >&2 printf '%s\n' 'no virt-launcher Pod found in namespace tenant-test' \ >"${err_log}" return 1 fi # Cap the walk, at the number the caller asked for. Every read here is bounded, # but the pool can reach maxReplicas, so # an uncapped loop is a term whose size the cluster sets rather than this file -- # inside a failure path that has to reach the tenant snapshot at the end of it. # The phase budget beside COZY_DIAG_PHASE_BUDGET is what stops the collectors as a # group from spending the time that snapshot needs; this cap is what stops this # walk from being the collector that spends it. A cap that fired is recorded with both # counts rather than leaving the shortfall implicit, since a short listing # otherwise reads as a small pool rather than a truncated walk. for pod in ${pods}; do seen=$((seen + 1)) if [ "${seen}" -gt "${max_pods}" ]; then echo "--- guest serial console capture stopped at ${max_pods} Pods ---" printf 'capture stopped after %s Pods; %s matched in total\n' \ "${max_pods}" "$(printf '%s\n' ${pods} | wc -l | tr -d ' ')" \ >"${report_dir}/COLLECTION-TRUNCATED.txt" break fi # Counted after the cap test, not from it. `seen` is incremented before that # test so it can fire on the Pod past the cap, which leaves it one higher # than the number of Pods read whenever the walk truncates. Reporting a # count of silent consoles against it would state a denominator that is # neither what was read nor what matched -- and the truncation marker beside # the capture prints both correctly, so the job log and the artifact would # disagree on a run nobody opens the artifact for. walked=$((walked + 1)) echo "--- capturing guest serial console: ${pod} ---" rc=0 # stderr goes beside the capture, not into it. Folded in, kubectl's own # "container guest-console-log is not valid for pod ..." would make the # file non-empty and the console would look like it had said something. # That error is the headline case here -- it is what a container wedged in # Init looks like -- so it has to stay separable from console bytes. Which # name it lands under is decided by the exit status, the same way the list # read above decides it: kubectl writes warnings on stderr with a zero # status too, and a warning beside a healthy capture is not an error. pod_err="${report_dir}/${pod}.read-error.log" read_at=$(date +%s) timeout -k 5 30 kubectl -n tenant-test logs "${pod}" \ -c guest-console-log --limit-bytes=1048576 \ >"${report_dir}/${pod}.log" 2>"${pod_err}" || rc=$? read_done=$(date +%s) if [ ! -s "${pod_err}" ]; then rm -f "${pod_err}" pod_err= elif [ "${rc}" -eq 0 ]; then mv "${pod_err}" "${report_dir}/${pod}.READ-WARNINGS.txt" 2>/dev/null || true pod_err= fi # Tested before the exit-code line is appended, or nothing is ever empty. # Three outcomes, three labels, because only one of them is a statement # about what the guest did. if [ ! -s "${report_dir}/${pod}.log" ] && [ "${rc}" -ne 0 ]; then silent=$((silent + 1)) # timeout kills the child without a word, so a read can fail having # written nothing to either stream. Naming a file that was never created # sends the reader looking for evidence that does not exist. if [ -n "${pod_err}" ]; then printf '%s\n' \ 'the read returned no console at all; see read-error.log and POD-STATE.txt' \ >>"${report_dir}/${pod}.log" else printf '%s\n' \ 'the read failed silently and returned no console at all; see POD-STATE.txt' \ >>"${report_dir}/${pod}.log" fi elif [ ! -s "${report_dir}/${pod}.log" ]; then silent=$((silent + 1)) printf '%s\n' \ 'the read succeeded and returned nothing; see POD-STATE.txt for whether the container started' \ >>"${report_dir}/${pod}.log" elif [ "${rc}" -ne 0 ]; then silent=$((silent + 1)) # Counted apart as well as together. `silent` gates the Pod-state read # below, and a console cut off part way needs that read as much as an # empty one does; but it is not silence, and the summary line these feed # would otherwise report bytes that arrived as bytes that never did. cut_short=$((cut_short + 1)) if [ -n "${pod_err}" ]; then printf '%s\n' \ 'console output is truncated; see read-error.log and POD-STATE.txt' \ >>"${report_dir}/${pod}.log" else printf '%s\n' \ 'console output is truncated; see POD-STATE.txt for the Pod state' \ >>"${report_dir}/${pod}.log" fi fi # Reuse the console bytes just read rather than paying for another API/log # call in the successful timing report. Best-effort: a guest that has not # reached the pull yet is already described by the full capture itself. _cozy_guest_kubelet_image_timing "${pod}" "${report_dir}/${pod}.log" || true # The wall clock the log's own stamps have to be read against. Every line a # guest prints is stamped in seconds since that guest's kernel started, so # the file says how far the guest had got and nothing about when that was. # Paired with the compute container's start in CAPTURE-TIMELINE.txt beside # it, this turns the two questions a short console raises -- a guest that # started too late to reach a milestone, or one that reached it and then # went quiet -- into one subtraction. The read instant is otherwise nowhere # in the file: it survives as the artifact's mtime, which is metadata rather # than content, so a reader who opens the log sees nothing and anything that # regenerates or rewrites the file loses it. # Same bracket form the cAdvisor captures use, and for the same # reason: the stream is drained somewhere between the two instants, so an # age computed against either end is exact to the width of the bracket. printf '\n[console read started at %s and returned at %s epoch seconds]\n' \ "${read_at}" "${read_done}" >>"${report_dir}/${pod}.log" printf '[capture exit code: %s]\n' "${rc}" >>"${report_dir}/${pod}.log" done # When each guest started, read once for the whole selector rather than per # Pod, like the Pod-state read below and for the same reason: several workers # are one finding and paying per Pod would put back the unbounded term the cap # removed. Unlike that read this one is unconditional, because the question it # answers is raised by a console that arrived intact just as much as by one # that did not -- a full log ending mid-boot is the shape this failure keeps # producing, and it is the shape that says nothing on its own. # # Both container starts, not just compute's: the guest's clock begins with # compute, and the console container starting later or restarting would mean # the stream missed a stretch the guest did print, which reads identically to # a guest that was quiet. # # The console container is asked for in both status lists, the way the attach # check asks for it in both spec lists. KubeVirt runs it as an init container # today, so its runtime state is under initContainerStatuses and reading only # containerStatuses returns empty for a container that started fine, which # costs the field its meaning. Missing keys are not an error for a jsonpath # template, so naming both costs an empty string on whichever list does not # hold it. # # Both fields read the RUNNING instance, so a container that has since # terminated reads empty here even though it ran. The legend says so rather # than the query chasing lastState as well: what this pairs with is a console # that was read from a live Pod, and a second start time for an instance whose # console is not the one in the file beside it would be read as the same # quantity. timeline="${report_dir}/CAPTURE-TIMELINE.txt" timeline_err="${report_dir}/CAPTURE-TIMELINE-warnings.txt" { printf '=== when each tenant worker guest started, against the reads above ===\n' printf '%s\n' \ 'each console log carries the instant its own read returned, in epoch seconds; the times below are RFC 3339, so convert before subtracting rather than comparing the two as printed. computeStartedAt subtracted from that instant is how long the guest had been alive when it was read; compare the result against the last [ ss.ssssss] stamp in the log, which counts from the same start. Close together means the guest was still printing when the read ran, so the log ends because the guest had not got further. Far apart means the console stopped growing for the difference, which is the guest going quiet or the stream no longer carrying it; consoleStartedAt is what separates those, since a console container that started late or restarted missed whatever the guest printed before it. Read that against CAPTURE-CONTEXT.txt before calling it a finding: on a capture taken after a suite passed, the guest finished booting long before the read and a large difference is what a healthy worker looks like, so what is worth comparing there is the guest seconds each milestone landed at rather than the size of the gap. These are the running instances only: a Pod whose compute has no start time has no compute container running now, which is not the same as never having had one, and phase beside it is what says which' } >"${timeline}" # Bounded like every read here, and its stderr kept out of the file for the # same reason the reads above keep theirs out: the success probe below matches # on the row prefix, and a warning kubectl writes beside a healthy read would # otherwise be sitting inside the rows it is supposed to be distinguished # from. timeout -k 5 30 kubectl -n tenant-test get pods -l kubevirt.io=virt-launcher \ -o jsonpath='{range .items[*]}{"name="}{.metadata.name}{" phase="}{.status.phase}{" podStartTime="}{.status.startTime}{" computeStartedAt="}{.status.containerStatuses[?(@.name=="compute")].state.running.startedAt}{" consoleStartedAt="}{.status.initContainerStatuses[?(@.name=="guest-console-log")].state.running.startedAt}{.status.containerStatuses[?(@.name=="guest-console-log")].state.running.startedAt}{"\n"}{end}' \ --request-timeout=30s >>"${timeline}" 2>>"${timeline_err}" || timeline_rc=$? timeline_err_kept=0 if [ ! -s "${timeline_err}" ]; then rm -f "${timeline_err}" elif [ "${timeline_rc}" -ne 0 ]; then if mv "${timeline_err}" "${report_dir}/CAPTURE-TIMELINE-error.log" 2>/dev/null; then timeline_err_kept=1 fi fi # Three outcomes, three labels, because only one of them says anything about # the guests. A read that failed is a statement about this machine's view of # the cluster; a read that answered with nothing is a statement about the # namespace; and neither may be left as an absent file, which reads as a # capture that had no reason to write one. The failed arm is tested for rows # as well, because a read cut off part way leaves both -- and a note saying # nothing was observed, sitting under rows that plainly were, is a file that # contradicts itself. # The error file is named only when there is one. `timeout` kills the child # without a word, so this read can fail having written to neither stream, and # a note pointing at a file that was never created sends the reader looking # for evidence that does not exist -- the same trap the per-Pod notes above # avoid the same way. if [ "${timeline_err_kept}" -eq 1 ]; then timeline_why='; the reason it gave is in CAPTURE-TIMELINE-error.log' else timeline_why='; it gave no reason on either stream' fi if [ "${timeline_rc}" -ne 0 ] && grep -q '^name=' "${timeline}"; then printf '%s\n' \ "the start-time read was cut off (exit ${timeline_rc}); the rows above are a prefix and the Pods missing from them were not observed${timeline_why}" \ >>"${timeline}" elif [ "${timeline_rc}" -ne 0 ]; then printf '%s\n' \ "the start-time read failed (exit ${timeline_rc}); when these guests started was not observed, which is not the same as their having no start time${timeline_why}" \ >>"${timeline}" elif ! grep -q '^name=' "${timeline}"; then printf '%s\n' \ 'the start-time read succeeded and returned no rows; the walk above read consoles from Pods this selector no longer matches' \ >>"${timeline}" fi # An empty console log has two causes that are indistinguishable in the log # itself: the guest printed nothing, or the container never started and there # was no stream to read. The second is what kubevirt/kubevirt#15989 produces, # and it is the reading that would otherwise be filed as a quiet guest -- # silence reported as a result is the failure this collector exists to # prevent, so it is not allowed to produce one. The Pod's own state and its # events are what separate the two, and they are read once for the whole # selector rather than per Pod: several silent workers are one finding, and # paying per Pod would put back the unbounded term the cap removed. if [ "${silent}" -gt 0 ]; then # Said on stdout as well as in the report, because the two callers read # different things. On the failure path the report is opened either way; on # the passing path it is not opened at all, and a baseline that came back # empty there would otherwise be visible only to whoever downloads a green # run's artifact -- which is nobody. The count is not a failure: on the # failure path a guest that printed nothing is itself a finding. echo "» of the ${walked} guest consoles read, $((silent - cut_short)) came back empty and ${cut_short} were cut short; see POD-STATE.txt beside the capture" { printf '=== describe pods -l kubevirt.io=virt-launcher ===\n' timeout -k 5 30 kubectl -n tenant-test describe pods \ -l kubevirt.io=virt-launcher --request-timeout=30s 2>&1 || true printf '\n=== Pod events in tenant-test (not filtered to virt-launcher) ===\n' timeout -k 5 30 kubectl -n tenant-test get events \ --field-selector involvedObject.kind=Pod \ --sort-by=.lastTimestamp --request-timeout=30s 2>&1 || true } >"${report_dir}/POD-STATE.txt" fi } # One bounded read of a node's cAdvisor stream, shared by every worker counter # capture and deliberately subject-agnostic: it fetches and reports a status, # and says nothing about which series the caller is after. The reasoning about # what each capture reads, and why from the kubelet rather than from inside the # container, belongs to the captures and is written above each of them. _cozy_cadvisor_node_stream() { local node="$1" local stream="$2" local node_err="$3" local rc=0 # One read per capture, so a node's stream is fetched once per subject rather # than once in total, and once per SAMPLE where a subject is read twice. That # is a real cost -- bounded by the read bound and the node cap at up to 100s # per invocation, a ceiling those numbers impose rather than a measured # duration -- and it is declined for a reason that outlives any particular way # of sharing the read. # # Sharing it means the captures of one node becoming one walk, and that is not # done here for scope rather than for merit: one walk behind the earliest of # their gates would be cheaper AND collect more. The gate is a deadline checked # with date, not a per-collector allowance, so a run yields all of them, a # prefix of them, or none -- and a merged walk admitted at the earliest gate # turns every prefix into all of them while leaving none unchanged. Anyone # weighing this should read that as an argument for merging, not against it. # # A cross-phase cache avoids the merge and was tried; it is not what stands # here, and the reason is not the cost above but that a cache publishes a # local write failure as a statement about the cluster -- the one thing this # collector may not do. # # The timeout-absent fallback is the sibling collectors': bounding with a # binary that is not there turns every read into an exit 127 and every note # into "the kubelet refused". if command -v timeout >/dev/null 2>&1; then timeout -k "${COZY_DIAG_READ_GRACE}" "${COZY_DIAG_READ_TIMEOUT}" \ kubectl get --raw "/api/v1/nodes/${node}/proxy/metrics/cadvisor" \ "--request-timeout=${COZY_DIAG_READ_TIMEOUT}s" \ >"${stream}" 2>"${node_err}" || rc=$? else kubectl get --raw "/api/v1/nodes/${node}/proxy/metrics/cadvisor" \ "--request-timeout=${COZY_DIAG_READ_TIMEOUT}s" \ >"${stream}" 2>"${node_err}" || rc=$? fi printf '%s\n' "${rc}" } # _cozy_capture_worker_cadvisor