softplayer-controller/hooks/up.sh

38 lines
1.3 KiB
Bash
Executable File

#!/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 bootstrap configmaps getting created
apiVersion: v1
kind: ConfigMap
executeHookOnSynchronization: false
executeHookOnEvent: ["Added", "Modified"]
jqFilter: ".data"
labelSelector:
matchExpressions:
- key: "component"
operator: "In"
values: ["bootstrap"]
EOF
else
export $(jq -r .[0].object.data.vars $BINDING_CONTEXT_PATH)
if ! [ -f /tpls/${SP_PROVIDER}-${SP_KUBERNETES}.yaml ]; then
echo "ERROR: template not found for ${SP_PROVIDER}-${SP_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/${SP_PROVIDER}-${SP_KUBERNETES}.yaml | kubectl create -f -
kubectl patch configmap -n ${SP_CUSTOMER_ID} ${SP_ENVIRONMENT} \
-p '{"metadata":{"finalizers":["softplayer.net/bootstrapped"]}}' --type=merge
fi