updating script
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 40s

This commit is contained in:
2026-06-20 18:53:59 -03:00
parent 941b0f97e3
commit 36a0444344

View File

@@ -53,7 +53,7 @@ restore_warnings=0
total_backup_size_bytes=0 total_backup_size_bytes=0
_kubectl() { _kubectl() {
"$KUBECTL_BIN" "${KUBECTL_ARGS[@]}" "$@" "$KUBECTL_BIN" "${KUBECTL_ARGS[@]}" "$@" </dev/null
} }
parse_workload_kinds() { parse_workload_kinds() {
@@ -129,16 +129,25 @@ capture_replicas_state() {
local kind local kind
local name local name
local replicas local replicas
local owners
local output local output
for kind in "${WORKLOAD_KIND_LIST[@]}"; do for kind in "${WORKLOAD_KIND_LIST[@]}"; do
if ! output="$(_kubectl -n "$namespace" get "$kind" -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.replicas}{"\n"}{end}' 2>/dev/null)"; then if ! output="$(_kubectl -n "$namespace" get "$kind" -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.replicas}{"\t"}{range .metadata.ownerReferences[*]}{.kind},{end}{"\n"}{end}' 2>/dev/null)"; then
log_warn "Failed to list kind '${kind}' in namespace '${namespace}' while capturing state" log_warn "Failed to list kind '${kind}' in namespace '${namespace}' while capturing state"
scale_warnings=$((scale_warnings + 1)) scale_warnings=$((scale_warnings + 1))
continue continue
fi fi
while IFS=$'\t' read -r name replicas; do while IFS=$'\t' read -r name replicas owners; do
[[ -z "$name" ]] && continue [[ -z "$name" ]] && continue
# Skip resources managed by a higher-level controller (e.g. a
# ReplicaSet owned by a Deployment) — scaling them directly
# conflicts with the owning controller and can leave workloads
# in an inconsistent state after restore.
if [[ -n "$owners" ]]; then
log_debug "Skipping ${kind}/${name} in namespace '${namespace}': owned by ${owners%,}"
continue
fi
if [[ -z "$replicas" ]]; then if [[ -z "$replicas" ]]; then
replicas="1" replicas="1"
log_warn "Resource ${kind}/${name} had no explicit replicas; defaulting saved value to 1" log_warn "Resource ${kind}/${name} had no explicit replicas; defaulting saved value to 1"
@@ -155,7 +164,7 @@ scale_resource() {
local name="${3:?name is required}" local name="${3:?name is required}"
local replicas="${4:?replicas is required}" local replicas="${4:?replicas is required}"
retry "$SCALE_RETRY_COUNT" "$SCALE_RETRY_DELAY_SECONDS" \ retry "$SCALE_RETRY_COUNT" "$SCALE_RETRY_DELAY_SECONDS" \
_kubectl -n "$namespace" scale "${kind}/${name}" --replicas="$replicas" >/dev/null _kubectl -n "$namespace" scale "${kind}/${name}" --replicas="$replicas"
} }
scale_namespace_to_zero() { scale_namespace_to_zero() {
@@ -260,6 +269,12 @@ wait_for_scale_state() {
status="$(resource_replicas "$namespace" "$kind" "$name" '{.status.replicas}')" status="$(resource_replicas "$namespace" "$kind" "$name" '{.status.replicas}')"
ready="$(resource_replicas "$namespace" "$kind" "$name" '{.status.readyReplicas}')" ready="$(resource_replicas "$namespace" "$kind" "$name" '{.status.readyReplicas}')"
# If all three values are empty the resource was likely deleted
# between capture and now — nothing to wait for.
if [[ -z "$spec" && -z "$status" && -z "$ready" ]]; then
continue
fi
[[ -z "$spec" ]] && spec="1" [[ -z "$spec" ]] && spec="1"
[[ -z "$status" ]] && status="0" [[ -z "$status" ]] && status="0"
[[ -z "$ready" ]] && ready="0" [[ -z "$ready" ]] && ready="0"