From 69e2dd2796a2a9856bdadbce93072228fefe2a26 Mon Sep 17 00:00:00 2001 From: Greg Haynes Date: Mon, 28 Oct 2024 17:08:48 +0000 Subject: [PATCH] Add vcluster-multi-env stack The vcluster-multi-env stack configures a set of vclusters managed by the CNOE ArgoCD which are then enrolled in the CNOE ArgoCD. This enables developing multi-environment workflows on top of CNOE. Signed-off-by: Greg Haynes --- vcluster-multi-env/README.md | 41 ++++++++++ vcluster-multi-env/add-vclusters.sh | 48 ++++++++++++ .../vcluster/application-vcluster.yaml | 39 ++++++++++ vcluster-multi-env/vcluster/ingress.yaml | 27 +++++++ .../vcluster/kustomization.yaml | 3 + vcluster-multi-env/vclusters.yaml | 78 +++++++++++++++++++ 6 files changed, 236 insertions(+) create mode 100644 vcluster-multi-env/README.md create mode 100755 vcluster-multi-env/add-vclusters.sh create mode 100644 vcluster-multi-env/vcluster/application-vcluster.yaml create mode 100644 vcluster-multi-env/vcluster/ingress.yaml create mode 100644 vcluster-multi-env/vcluster/kustomization.yaml create mode 100644 vcluster-multi-env/vclusters.yaml diff --git a/vcluster-multi-env/README.md b/vcluster-multi-env/README.md new file mode 100644 index 0000000..42dceba --- /dev/null +++ b/vcluster-multi-env/README.md @@ -0,0 +1,41 @@ +# IDP Builder Multi-Environment + +Multi-environment emulation on top of CNOE. + +# Configuring Clusters + +By default, this stack creates two vclusters (staging and production). If you +desire a different configuration you can edit the following list in +`vclusters.yaml`: + +```yaml + generators: + - list: + elements: + - name: staging + - name: production +``` + +# Running + +```bash +# Create CNOE deployment with vcluster-multi-env stack +idpbuilder create -p vcluster-multi-env + +# Enroll vclusters in ArgoCD +./vcluster-multi-env/add-vclusters.sh +``` + +# Using + +Your CNOE ArgoCD should now have a cluster enrolled for each configured +vcluster (staging and production by default). These clusters will have the +following labels for your use: + +```yaml + cnoe.io/vclusterMultiEnv/clusterClass: "app-runtime" + cnoe.io/vclusterMultiEnv/clusterName: "${cluster_name}" +``` + +You may now target them using, for example, an ArgoCD ApplicationSet cluster +generator which matches these labels. diff --git a/vcluster-multi-env/add-vclusters.sh b/vcluster-multi-env/add-vclusters.sh new file mode 100755 index 0000000..78d6d96 --- /dev/null +++ b/vcluster-multi-env/add-vclusters.sh @@ -0,0 +1,48 @@ +#! /bin/bash + +set -eu + +vcluster_app_names=$(kubectl get application -A -l cnoe.io/applicationName=vcluster-package,cnoe.io/stackName=vcluster-multi-env --no-headers -o custom-columns=":metadata.name") +environments=$(echo "$vcluster_app_names" | cut -f 1 -d '-') + +for env in $environments; do + cluster_name=$env + + echo "Checking readiness for ${cluster_name} vcluster..." + + until kubectl get secret -n ${cluster_name}-vcluster vc-${cluster_name}-vcluster-helm &> /dev/null; do + echo "Waiting for ${cluster_name} vcluster secret to be ready..." + sleep 10 + done + + echo "${cluster_name} vcluster is ready. Retrieving credentials..." + client_key=$(kubectl get secret -n ${cluster_name}-vcluster vc-${cluster_name}-vcluster-helm --template='{{index .data "client-key" }}') + client_certificate=$(kubectl get secret -n ${cluster_name}-vcluster vc-${cluster_name}-vcluster-helm --template='{{index .data "client-certificate" }}') + certificate_authority=$(kubectl get secret -n ${cluster_name}-vcluster vc-${cluster_name}-vcluster-helm --template='{{index .data "certificate-authority" }}') + + kubectl apply -f - <