softplayer-controller/hooks/up.sh

38 lines
1.3 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:
2024-04-02 16:23:10 +00:00
- name: Watch bootstrap configmaps getting created
2024-04-02 15:21:21 +00:00
apiVersion: v1
kind: ConfigMap
2024-04-03 07:50:45 +00:00
executeHookOnSynchronization: false
2024-04-02 16:59:16 +00:00
executeHookOnEvent: ["Added", "Modified"]
2024-04-02 16:51:42 +00:00
jqFilter: ".data"
2024-04-02 15:21:21 +00:00
labelSelector:
matchExpressions:
- key: "component"
operator: "In"
values: ["bootstrap"]
EOF
else
2024-04-03 07:56:47 +00:00
PROVIDER=$(jq -r .[0].object.data.provider $BINDING_CONTEXT_PATH)
KUBERNETES=$(jq -r .[0].object.data.kubernetes $BINDING_CONTEXT_PATH)
2024-04-02 15:21:21 +00:00
if ! [ -f /tpls/${PROVIDER}-${KUBERNETES}.yaml ]; then
echo "ERROR: template not found for ${PROVIDER}-${KUBERNETES}"
exit 1
fi
2024-04-03 07:56:47 +00:00
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)
2024-04-02 15:21:21 +00:00
envsubst < /tpls/${PROVIDER}-${KUBERNETES}.yaml | kubectl create -f -
2024-04-02 16:39:10 +00:00
kubectl patch configmap -n ${SP_CUSTOMER_ID} ${SP_ENVIRONMENT} \
2024-04-02 16:43:01 +00:00
-p '{"metadata":{"finalizers":["softplayer.net/bootstrapped"]}}' --type=merge
2024-04-02 15:21:21 +00:00
fi