# Multi-cluster GitOps Scripts Note: these scripts operate on local repos and do not commit changes or push to remotes. Commits and pushes must be done separately. ## Workload cluster management ### add-cluster.sh Usage: ``` add-cluster.sh ``` Updates the local repo for `gitops-system` to add a new workload cluster. This is achieved by copying the required template folders into new folders for the cluster to be added, and updating the cluster name. The `kustomization.yaml` file in `clusters-config` is also updated to add the new cluster. ### remove-cluster.sh Usage: ``` remove-cluster.sh ``` This removes the specified cluster from `cluster-configs/kustomization.yaml`, which triggers crossplane to remove the cluster. It also removes all cluster configuration files from the local repos for `gitops-system` and `gitops-workloads`. ## Application management ### add-cluster-app.sh Usage: ``` add-cluster-app.sh ``` Adds the application `app-name` to the cluster `cluster-name`, using the following steps: - creates a new folder for the app under the correct workloads cluster folder and copies the app template - updates the folder content with the correct cluster name and app name - creates a sealed secret `gitops-secret.yaml` using the supplied template, keys, and known_hosts string - updates `kustomization.yaml` in the workloads cluster folder. It is assumed that a repo called `app-name-manifests` exists. ### remove-cluster-app.sh ``` remove-cluster-app.sh ``` Removes the application from `kustomization.yaml` and deletes the application folder from the workloads cluster folder. ### add-app-cluster-overlay Usage: ``` add-app-cluster-overlay cluster_name ``` ## Example sequence Create a `commercial-staging` cluster: ``` add-cluster.sh ./gitops-system commercial-staging ``` Commit and push: ``` cd gitops-system git add . git commit -m "Added cluster" git push ``` Create an application manifests repo: ``` cd ~/environment gh repo create --private --clone product-catalog-fe-manifests cp -r multi-cluster-gitops/repos/apps-manifests/product-catalog-fe-manifests/* product-catalog-fe-manifests/ cd product-catalog-fe-manifests git add . git commit -m "baseline version" git branch -M main git push --set-upstream origin main ``` Add the app `product-catalog-fe` to the `commercial-staging` cluster: ``` add-cluster-app.sh \ ./gitops-workloads \ commercial-staging product-catalog-fe \ multi-cluster-gitops/initial-setup/secrets-template/git-credentials.yaml \ ~/.ssh/gitops ~/.ssh/gitops.pub \ "github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=" \ ./sealed-secrets-keypair-public.pem ``` Commit and push: ``` cd gitops-workloads git add . git commit -m "Added pc-fe to staging" git push ```