feat(scripts): add create, delete, and recreate actions for CloudNative-PG initialization

- Introduced new script commands to manage CloudNative-PG clusters (`create`, `delete`, `recreate`).
- Updated default namespace to `prole` and refined variable handling for cluster name.
- Adjusted kustomization.yaml to reference `prole-db.yaml` for consistency in manifests.
This commit is contained in:
chrisfu 2025-12-24 03:02:57 -08:00
parent 940a48a237
commit 528e362d95
2 changed files with 25 additions and 4 deletions

View File

@ -43,8 +43,8 @@ if [[ -z "${PROLE_SERVICE:-}" ]]; then
fi fi
ACTION=${1:-} ACTION=${1:-}
NAMESPACE=${NAMESPACE:-default} CNPG_CLUSTER_NAME=${2:-${CNPG_CLUSTER_NAME:-prole-db}}
CNPG_CLUSTER_NAME=${CNPG_CLUSTER_NAME:-prole-db} NAMESPACE=${NAMESPACE:-prole}
OPENBAO_NAME=${OPENBAO_NAME:-openbao} OPENBAO_NAME=${OPENBAO_NAME:-openbao}
REALM=${REALM:-PROLE.ORG} REALM=${REALM:-PROLE.ORG}
DOMAIN=${DOMAIN:-prole.org} DOMAIN=${DOMAIN:-prole.org}
@ -214,6 +214,27 @@ update_reload() {
} }
case "$ACTION" in case "$ACTION" in
recreate)
ensure_tools
"$0" delete "$CNPG_CLUSTER_NAME"
"$0" create "$CNPG_CLUSTER_NAME"
;;
create)
ensure_tools
echo "Installing CloudNative-PG operator ..."
kubectl apply --server-side -f https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release-1.27/releases/cnpg-1.27.0.yaml
echo "Creating CloudNative-PG cluster and resources for '$CNPG_CLUSTER_NAME' ..."
kubectl apply -k "$SCRIPT_DIR/../k8s/prole"
echo "Initializing and patching cluster ..."
initialize
;;
delete)
ensure_tools
echo "Deleting all resources for '$CNPG_CLUSTER_NAME' ..."
kubectl delete -k "$SCRIPT_DIR/../k8s/prole" --ignore-not-found
;;
start) start)
ensure_tools ensure_tools
if [[ ! -f "$CNPG_MANIFEST" ]]; then if [[ ! -f "$CNPG_MANIFEST" ]]; then
@ -260,7 +281,7 @@ case "$ACTION" in
update_reload update_reload
;; ;;
*) *)
echo "Usage: $0 {start|stop|status|restart|initialize|update|reload}" >&2 echo "Usage: $0 {create|delete|recreate|start|stop|status|restart|initialize|update|reload} [dbname]" >&2
exit 2 exit 2
;; ;;
esac esac

View File

@ -5,7 +5,7 @@ namespace: prole
resources: resources:
- namespace.yaml - namespace.yaml
- ../../cloudnative-pg-prole-dB.yaml - prole-db.yaml
- prole-configmap.yaml - prole-configmap.yaml
- prole-deployment.yaml - prole-deployment.yaml
- prole-service.yaml - prole-service.yaml