softplayer-controller/hooks/up.sh

36 lines
1.2 KiB
Bash
Raw Normal View History

2024-04-02 15:21:21 +00:00
#!/usr/bin/env bash
# ---------------------------------------------------------------------
# This script should bootstrap a new environment, or update
# existing ones
# Get the configmap name and namespace to prepare the
# ---------------------------------------------------------------------
if [[ $1 == "--config" ]] ; then
cat <<EOF
configVersion: v1
kubernetes:
- name: Watch softplayer configmaps
apiVersion: v1
kind: ConfigMap
executeHookOnEvent: ["Added"]
labelSelector:
matchExpressions:
- key: "component"
operator: "In"
values: ["bootstrap"]
EOF
else
cmName=$(jq -r .[0].object.metadata.name $BINDING_CONTEXT_PATH)
echo "ConfigMap '${cmName}' added"
PROVIDER=$(jq -r .[0].object.data.provider $BINDING_CONTEXT_PATH)
KUBERNETES=$(jq -r .[0].object.data.kubernetes $BINDING_CONTEXT_PATH)
if ! [ -f /tpls/${PROVIDER}-${KUBERNETES}.yaml ]; then
echo "ERROR: template not found for ${PROVIDER}-${KUBERNETES}"
exit 1
fi
export SP_CUSTOMER_ID=$(jq -r .[0].object.metadata.namespace $BINDING_CONTEXT_PATH)
export SP_ENVIRONMENT=$(jq -r .[0].object.metadata.name $BINDING_CONTEXT_PATH)
envsubst < /tpls/${PROVIDER}-${KUBERNETES}.yaml | kubectl create -f -
fi