feat: add OCI status and doctor commands
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-10-23 22:29:28 -06:00
parent ff0e89e55d
commit 21586b7f71
4 changed files with 159 additions and 0 deletions

View File

@ -66,6 +66,7 @@ var allowedCommands = map[string]bool{
"email-vm": true,
"oci-foundation": true,
"oci-auth": true,
"oci": true,
"secrets-init": true, "secrets-check": true, "tailnet-policy-check": true,
"secrets": true,
"ai-index": true, "ai-check": true, "ask": true, "ai-evals": true,

View File

@ -153,3 +153,9 @@ func TestOCIFoundationCommandIsRemotelyEnabled(t *testing.T) {
t.Fatal("oci-foundation must be exposed through the remote API")
}
}
func TestOCICommandIsRemotelyEnabled(t *testing.T) {
if !allowedCommands["oci"] {
t.Fatal("oci must be exposed through the remote API")
}
}

View File

@ -126,6 +126,7 @@ Observability And GitOps
oci-foundation {status|plan|apply|destroy --yes}
Create the opt-in OCI compartment, network, edge VM, and email VM.
oci-auth {install|init [--force]|check} Install/check OCI CLI and API-key authentication on Debian.
oci {status|doctor} Inspect OCI resources, service limits, and quotas (read-only).
edge-cache-flush Clear Nginx, Varnish, and Squid edge caches.
promote {plan|validate|rollback APP} Run canary promotion gates and rollback plan.
cert-check Check public DNS, TLS, and edge URL health.
@ -300,6 +301,13 @@ case "${1:-}" in
oci-auth)
oci_auth_manage "${@:2}"
;;
oci)
case "${2:-status}" in
status) oci_status ;;
doctor) oci_doctor ;;
*) echo "Usage: ./jeannie oci {status|doctor}" >&2; exit 2 ;;
esac
;;
edge-cache-flush)
edge_flush_caches
;;

View File

@ -3497,6 +3497,150 @@ oci_auth_manage() {
"${REPO_ROOT}/scripts/oci-auth" "$@"
}
oci_cli_resolve() {
if command -v oci >/dev/null 2>&1; then
command -v oci
elif [[ -x "${HOME}/.local/share/homelab/venvs/oci-cli/bin/oci" ]]; then
printf '%s\n' "${HOME}/.local/share/homelab/venvs/oci-cli/bin/oci"
else
return 1
fi
}
oci_status() {
require_debian_server "oci status"
oci_foundation_load_config
local oci_bin tenancy compartment region
oci_bin="$(oci_cli_resolve)" || {
echo "OCI CLI is not installed. Run ./jeannie oci-auth install." >&2
return 2
}
tenancy="${LAB_OCI_TENANCY_ID:-}"
compartment="${LAB_OCI_COMPARTMENT_ID:-${tenancy}}"
region="${LAB_OCI_REGION:-${OCI_CLI_REGION:-unknown}}"
[[ -n "${tenancy}" ]] || {
echo "OCI tenancy is not configured. Run ./jeannie oci-auth init or set LAB_OCI_TENANCY_ID." >&2
return 2
}
printf '%s\n' '== OCI status =='
printf 'region=%s profile=%s config=%s\n' "${region}" "${OCI_CLI_PROFILE:-DEFAULT}" "${OCI_CLI_CONFIG_FILE:-${HOME}/.oci/config}"
printf '%s\n' '-- compartments'
"${oci_bin}" iam compartment list --compartment-id "${tenancy}" \
--compartment-id-in-subtree true --all \
--query 'data[].{NAME:name,ID:id,STATE:"lifecycle-state"}' --output table 2>/dev/null || echo 'unavailable'
local compartment_ids resource_compartments current_compartment
compartment_ids="$("${oci_bin}" iam compartment list --compartment-id "${tenancy}" \
--compartment-id-in-subtree true --all --query 'data[].id' --raw-output 2>/dev/null || true)"
resource_compartments="${tenancy}"$'\n'"${compartment_ids}"
printf '%s\n' '-- compute instances (all compartments)'
while IFS= read -r current_compartment; do
[[ -n "${current_compartment}" ]] || continue
printf 'compartment=%s\n' "${current_compartment}"
"${oci_bin}" compute instance list --compartment-id "${current_compartment}" --all \
--query 'data[].{NAME:"display-name",SHAPE:shape,STATE:"lifecycle-state",AD:"availability-domain",ID:id}' \
--output table 2>/dev/null || echo 'unavailable'
done <<<"${resource_compartments}"
printf '%s\n' '-- networking (all compartments)'
while IFS= read -r current_compartment; do
[[ -n "${current_compartment}" ]] || continue
printf 'compartment=%s\n' "${current_compartment}"
"${oci_bin}" network vcn list --compartment-id "${current_compartment}" --all \
--query 'data[].{NAME:"display-name",CIDR:"cidr-block",STATE:"lifecycle-state",ID:id}' \
--output table 2>/dev/null || echo 'unavailable'
"${oci_bin}" network subnet list --compartment-id "${current_compartment}" --all \
--query 'data[].{NAME:"display-name",CIDR:"cidr-block",PUBLIC:"prohibit-public-ip-on-vnic",STATE:"lifecycle-state",ID:id}' \
--output table 2>/dev/null || echo 'unavailable'
done <<<"${resource_compartments}"
printf '%s\n' '-- boot volumes (all compartments)'
while IFS= read -r current_compartment; do
[[ -n "${current_compartment}" ]] || continue
printf 'compartment=%s\n' "${current_compartment}"
"${oci_bin}" bv boot-volume list --compartment-id "${current_compartment}" --all \
--query 'data[].{NAME:"display-name",SIZE_GB:"size-in-gbs",STATE:"lifecycle-state",AD:"availability-domain",ID:id}' \
--output table 2>/dev/null || echo 'unavailable'
done <<<"${resource_compartments}"
printf '%s\n' '-- service limits'
"${oci_bin}" limits service list --compartment-id "${tenancy}" --all \
--query 'data[].{NAME:name,DESCRIPTION:description}' --output table 2>/dev/null || echo 'unavailable'
printf '%s\n' '-- quotas'
while IFS= read -r current_compartment; do
[[ -n "${current_compartment}" ]] || continue
printf 'compartment=%s\n' "${current_compartment}"
"${oci_bin}" limits quota list --compartment-id "${current_compartment}" --all \
--query 'data[].{NAME:name,STATE:"lifecycle-state",STATEMENTS:statements}' --output table 2>/dev/null || echo 'unavailable'
done <<<"${resource_compartments}"
}
oci_doctor() {
require_debian_server "oci doctor"
oci_foundation_load_config
local oci_bin tenancy compartment region failures=0 states bad_state
oci_bin="$(oci_cli_resolve)" || {
echo 'FAIL OCI CLI is not installed; run ./jeannie oci-auth install.'
return 1
}
tenancy="${LAB_OCI_TENANCY_ID:-}"
compartment="${LAB_OCI_COMPARTMENT_ID:-${tenancy}}"
region="${LAB_OCI_REGION:-${OCI_CLI_REGION:-}}"
if [[ -z "${tenancy}" || -z "${region}" ]]; then
echo 'FAIL OCI tenancy/region is not configured.'
return 1
fi
if "${oci_bin}" iam region list --region "${region}" >/dev/null 2>&1; then
printf 'PASS OCI authentication and region: %s\n' "${region}"
else
echo 'FAIL OCI authentication or region access'
failures=$((failures + 1))
fi
if "${oci_bin}" iam compartment get --compartment-id "${compartment}" >/dev/null 2>&1; then
printf 'PASS compartment accessible: %s\n' "${compartment}"
else
echo 'FAIL configured compartment is not accessible'
failures=$((failures + 1))
fi
states="$("${oci_bin}" compute instance list --compartment-id "${compartment}" --all \
--query 'data[]."lifecycle-state"' --raw-output 2>/dev/null || true)"
if [[ -n "${states}" ]]; then
bad_state="$(printf '%s\n' "${states}" | grep -Ev '^(RUNNING|STOPPED|STOPPING|STARTING|TERMINATED|TERMINATING|PROVISIONING)$' || true)"
if [[ -n "${bad_state}" ]]; then
printf 'FAIL instance lifecycle states: %s\n' "${bad_state//$'\n'/, }"
failures=$((failures + 1))
else
printf 'PASS compute instances have known lifecycle states (%s listed)\n' "$(printf '%s\n' "${states}" | sed '/^$/d' | wc -l | tr -d ' ')"
fi
else
echo 'WARN no compute instances found or instance listing unavailable'
fi
local id label
for label in edge_instance vcn public_subnet email_subnet; do
case "${label}" in
edge_instance) id="${LAB_OCI_EDGE_EXISTING_INSTANCE_ID:-}"; [[ -n "${id}" ]] && "${oci_bin}" compute instance get --instance-id "${id}" >/dev/null 2>&1 && printf 'PASS %s exists\n' "${label}" || [[ -z "${id}" ]] || { printf 'FAIL %s is missing\n' "${label}"; failures=$((failures + 1)); } ;;
vcn) id="${LAB_OCI_EXISTING_VCN_ID:-}"; [[ -n "${id}" ]] && "${oci_bin}" network vcn get --vcn-id "${id}" >/dev/null 2>&1 && printf 'PASS %s exists\n' "${label}" || [[ -z "${id}" ]] || { printf 'FAIL %s is missing\n' "${label}"; failures=$((failures + 1)); } ;;
public_subnet) id="${LAB_OCI_EXISTING_PUBLIC_SUBNET_ID:-}"; [[ -n "${id}" ]] && "${oci_bin}" network subnet get --subnet-id "${id}" >/dev/null 2>&1 && printf 'PASS %s exists\n' "${label}" || [[ -z "${id}" ]] || { printf 'FAIL %s is missing\n' "${label}"; failures=$((failures + 1)); } ;;
email_subnet) id="${LAB_OCI_EXISTING_EMAIL_SUBNET_ID:-}"; [[ -n "${id}" ]] && "${oci_bin}" network subnet get --subnet-id "${id}" >/dev/null 2>&1 && printf 'PASS %s exists\n' "${label}" || [[ -z "${id}" ]] || { printf 'FAIL %s is missing\n' "${label}"; failures=$((failures + 1)); } ;;
esac
done
if "${oci_bin}" limits service list --compartment-id "${tenancy}" --all >/dev/null 2>&1; then
echo 'PASS OCI service limits are readable'
else
echo 'FAIL OCI service limits are not readable'
failures=$((failures + 1))
fi
if "${oci_bin}" limits quota list --compartment-id "${tenancy}" --all >/dev/null 2>&1; then
echo 'PASS OCI quotas are readable'
else
echo 'WARN OCI quota listing is unavailable or unsupported for this tenancy'
fi
if ((failures > 0)); then
printf 'OCI doctor: FAIL (%d check(s))\n' "${failures}"
return 1
fi
echo 'OCI doctor: PASS'
}
storage_status() {
require_debian_server "storage"
local kubeconfig="${KUBECONFIG_PATH}"