Dry-run and plan operations
A plan describes intended changes before an authorized execution. A local plan can validate input, compute a difference and produce structured output without changing infrastructure. Provider dry-run features vary: Kubernetes client dry-run generates output without persisting the requested object; server dry-run sends a request to the API server without persisting it, with applicable authorization and admission behavior. Client dry-run is not a guarantee of zero network traffic. AWS dry-run is operation-specific and can report its result as a nonzero service error. Never treat an arbitrary --dry-run flag as a universal safety boundary.
Review targets, limits and cost
Validate environment, resource identifiers, bounded replica counts and expected scope before constructing a plan. Keep planning and execution separate, require separate authorization for changes, and verify current state again because plans can become stale. Estimate cost from reviewed provider prices and usage assumptions; the exercise counts planned units, not money. Never enable paid resources from this lab. A plan's success does not prove deployment authorization, quotas, runtime readiness or future cost. The mock commands produce only local JSON or fixed status codes; no real apply path is included. Both local planning functions require exactly two arguments. The rejection example checks status 2 and the absence of the plan path, including a dangling symbolic link.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code. jq and GNU coreutils are external dependencies for selected examples. Use only the explicit local mock paths; do not use real accounts, clusters or sockets.
Generate a bounded local plan
plan() { [[ $# == 2 ]] || return 2 [[ $1 == lab && $2 =~ ^[1-3]$ ]] || return 2 jq -cn --arg env "$1" --argjson replicas "$2" '{environment:$env,replicas:$replicas,action:"preview"}' > plan.json}plan lab 2 || exit 1jq -r '.action + ":" + (.replicas|tostring)' plan.jsonExpected stdout:
preview:2Only the lab environment and one to three units are accepted. There is no deployment function.
Reject invalid plans before opening files
make_plan() { [[ $# == 2 ]] || return 2 [[ $1 == lab && $2 =~ ^[1-3]$ ]] || return 2 printf 'preview\n' > plan.txt}if make_plan prod 2; then exit 1; else rc=$?; fi[[ $rc == 2 ]] || exit 1printf 'rejected=%s\n' "$rc" || exit 1[[ ! -e plan.txt && ! -L plan.txt ]] || exit 1printf 'no plan file\n' Expected stdout:
rejected=2no plan fileThe check happens before output redirection; no plan is created on invalid input.
Mock a client-side preview
mkdir mock || exit 1cat > mock/kubectl <<'MOCK' || exit 1#!/bin/bash[[ $# == 5 && $1 == create && $2 == namespace && $3 == demo && $4 == --dry-run=client && $5 == -o=json ]] || exit 2printf '{"kind":"Namespace","metadata":{"name":"demo"}}\n'MOCKchmod 700 mock/kubectl || exit 1./mock/kubectl create namespace demo --dry-run=client -o=json > preview.json || exit 1jq -r '.metadata.name' preview.jsonExpected stdout:
demoThe mock only supports preview and returns a simplified object; no API call or namespace creation occurs.
Common mistakes
Do not treat planning as authorization, or interpret every nonzero dry-run status as the same failure.
Practice
Try replica count 0, 4 and text. Verify invalid plans do not create a plan file. Describe the review steps before any real change.
Next: Mock external CLI testing