#!/usr/bin/env bash
# Illustrative commands, not an automatic release pipeline.
# Prerequisites: publisher/compatibility gates passed; kubectl, curl, jq;
# runner inside the cluster network; actual API implements this test fixture.
set -euo pipefail

# R1 (api-blue) remains ready while R2 (api-green) is validated.
kubectl -n domain-a rollout status deployment/api-green --timeout=300s
curl --fail --silent --show-error \
  http://api-preview.domain-a.svc.cluster.local/catalog/items/demo \
  | jq -e '.id == "demo"' >/dev/null

# Compare-and-change one Service selector; conflicting promotions fail closed.
kubectl -n domain-a patch service api-active --type=json --patch='[
  {"op":"test","path":"/spec/selector/release","value":"R1"},
  {"op":"replace","path":"/spec/selector/release","value":"R2"}
]'

# Observe representative post-promotion behavior separately. Do not delete Blue
# or its immutable files before the drain and rollback-retention gate passes.

# Rollback is a SEPARATE action, only after checking retained Blue and confirming
# data/configuration compatibility. Run these commands only when rollback is chosen:
# kubectl -n domain-a rollout status deployment/api-blue --timeout=300s
# kubectl -n domain-a patch service api-active --type=json --patch='[
#   {"op":"test","path":"/spec/selector/release","value":"R2"},
#   {"op":"replace","path":"/spec/selector/release","value":"R1"}
# ]'
