From 37fccf13be40771b85742eedc732d5bcb0823e70 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Sun, 7 Dec 2025 15:37:46 -0600 Subject: [PATCH] Apply grafana dashboard sidecare --- k8s/README.md | 13 ++++++++++++ k8s/monitoring/values-production.yaml | 5 +++++ k8s/monitoring/values-staging.yaml | 5 +++++ scripts/deploy.sh | 30 ++++++++++++++++++++------- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/k8s/README.md b/k8s/README.md index 655d600..4a45b04 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -12,6 +12,19 @@ You should regenerate `all-crds.yaml` by running `scripts/update-crds.sh` when: 1. **Upgrading the `kube-prometheus-stack` Helm chart**: If you bump the chart version in `k8s/monitoring/Chart.yaml` and update the dependencies, you must also update the CRDs to match the new version. 2. **Missing CRD fields**: If you encounter errors like `field not declared in schema` during ArgoCD syncs, it likely means the installed CRDs are outdated. +3. **Apply the CRDs**: + Since Helm does not manage CRD upgrades, you must apply the updated CRDs manually. You may need `--force-conflicts` if ArgoCD previously managed these resources: + ```bash + kubectl apply --server-side --force-conflicts -f k8s/all-crds.yaml + ``` + +4. **Commit and Push**: + Commit the updated `k8s/all-crds.yaml` to the repository. + ```bash + git add k8s/all-crds.yaml + git commit -m "Update Prometheus CRDs" + git push + ``` ### How to update diff --git a/k8s/monitoring/values-production.yaml b/k8s/monitoring/values-production.yaml index 0db88e3..c65b5d7 100644 --- a/k8s/monitoring/values-production.yaml +++ b/k8s/monitoring/values-production.yaml @@ -184,6 +184,11 @@ kube-prometheus-stack: root_url: "%(protocol)s://%(domain)s/grafana/" enable_gzip: "true" serve_from_sub_path: true + sidecar: + dashboards: + enabled: true + label: grafana_dashboard + searchNamespace: ALL additionalDataSources: - name: Loki type: loki diff --git a/k8s/monitoring/values-staging.yaml b/k8s/monitoring/values-staging.yaml index 95c1666..74fe9b1 100644 --- a/k8s/monitoring/values-staging.yaml +++ b/k8s/monitoring/values-staging.yaml @@ -184,6 +184,11 @@ kube-prometheus-stack: root_url: "%(protocol)s://%(domain)s/grafana/" enable_gzip: "true" serve_from_sub_path: true + sidecar: + dashboards: + enabled: true + label: grafana_dashboard + searchNamespace: ALL additionalDataSources: - name: Loki type: loki diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 57b8ac8..a453fed 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -8,14 +8,23 @@ if [ -z "$ENVIRONMENT" ]; then exit 1 fi +# Define cleanup function to revert changes to applications.yaml +cleanup() { + if [ -f k8s/argocd/base/applications.yaml.bak ]; then + echo "Reverting k8s/argocd/base/applications.yaml..." + mv k8s/argocd/base/applications.yaml.bak k8s/argocd/base/applications.yaml + fi +} +trap cleanup EXIT + if [ "$ENVIRONMENT" == "staging" ]; then echo "Deploying to STAGING..." # Source activation script - if [ -f ~/bin/activate_stg ]; then - source ~/bin/activate_stg + if [ -f ~/bin/activate-stg ]; then + source ~/bin/activate-stg else - echo "Error: ~/bin/activate_stg not found." + echo "Error: ~/bin/activate-stg not found." exit 1 fi @@ -26,10 +35,15 @@ if [ "$ENVIRONMENT" == "staging" ]; then fi echo "Using branch: $BITBUCKET_BRANCH" + # Template argocd/base/applications.yaml # Template argocd/base/applications.yaml echo "Templating k8s/argocd/base/applications.yaml..." - envsubst < k8s/argocd/base/applications.yaml > k8s/argocd/base/applications.yaml.tmp - mv k8s/argocd/base/applications.yaml.tmp k8s/argocd/base/applications.yaml + + # Backup original file + cp k8s/argocd/base/applications.yaml k8s/argocd/base/applications.yaml.bak + + # Perform substitution + envsubst < k8s/argocd/base/applications.yaml.bak > k8s/argocd/base/applications.yaml # Apply Kustomize echo "Applying Kustomize for staging..." @@ -46,10 +60,10 @@ elif [ "$ENVIRONMENT" == "production" ]; then echo "Deploying to PRODUCTION..." # Source activation script - if [ -f ~/bin/activate_prd ]; then - source ~/bin/activate_prd + if [ -f ~/bin/activate-prd ]; then + source ~/bin/activate-prd else - echo "Error: ~/bin/activate_prd not found." + echo "Error: ~/bin/activate-prd not found." exit 1 fi