2024-05-04 17:54:14 +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 application configmaps getting created
|
|
|
|
apiVersion: v1
|
2024-05-10 11:03:04 +00:00
|
|
|
kind: Secret
|
2024-05-04 17:54:14 +00:00
|
|
|
executeHookOnSynchronization: false
|
|
|
|
executeHookOnEvent: ["Added", "Modified"]
|
|
|
|
jqFilter: ".data"
|
|
|
|
labelSelector:
|
|
|
|
matchExpressions:
|
|
|
|
- key: "component"
|
|
|
|
operator: "In"
|
|
|
|
values: ["install"]
|
|
|
|
EOF
|
|
|
|
else
|
|
|
|
export $(jq -r .[0].object.data.vars $BINDING_CONTEXT_PATH)
|
|
|
|
export SP_CUSTOMER_ID=$(jq -r .[0].object.metadata.namespace $BINDING_CONTEXT_PATH)
|
2024-05-10 11:27:52 +00:00
|
|
|
export SP_CONFIG_NAME=$(jq -r .[0].object.metadata.name $BINDING_CONTEXT_PATH)
|
2024-05-10 13:51:10 +00:00
|
|
|
export SP_APPLICATION=$(jq -r '.[0].object.data."values.yaml"' $BINDING_CONTEXT_PATH | base64 -d | yq '.helm.release')
|
2024-05-10 13:56:24 +00:00
|
|
|
export SP_ENVIRONMENT_ID=$(jq -r .[0].object.metadata.labels.environment)
|
2024-05-10 11:18:06 +00:00
|
|
|
|
|
|
|
flux create source helm $SP_APPLICATION \
|
2024-05-10 11:23:06 +00:00
|
|
|
--namespace=$SP_CUSTOMER_ID \
|
2024-05-10 11:18:06 +00:00
|
|
|
--url=oci://registry.badhouseplants.net/softplayer/helm
|
|
|
|
|
|
|
|
flux create helmrelease $SP_APPLICATION \
|
|
|
|
--source=HelmRepository/$SP_APPLICATION \
|
|
|
|
--namespace=$SP_CUSTOMER_ID \
|
|
|
|
--chart=helmrelease \
|
2024-05-10 11:27:52 +00:00
|
|
|
--values-from Secret/$SP_CONFIG_NAME \
|
2024-05-10 13:56:24 +00:00
|
|
|
--kubeconfig-secret-ref=$SP_ENVIRONMENT_ID-config \
|
2024-05-10 11:18:06 +00:00
|
|
|
--target-namespace=default --export \
|
|
|
|
| yq '.spec.storageNamespace="helm-installations"' \
|
2024-05-10 13:45:12 +00:00
|
|
|
| kubectl apply -f -
|
2024-05-10 11:27:52 +00:00
|
|
|
flux reconcile helmrelease --namespace=$SP_CUSTOMER_ID $SP_APPLICATION
|
2024-05-10 11:18:06 +00:00
|
|
|
|
2024-05-04 17:54:14 +00:00
|
|
|
fi
|
|
|
|
|