Created
March 31, 2023 08:24
-
-
Save imranismail/0c9c82844b75bbfc596895c4a9931744 to your computer and use it in GitHub Desktop.
Add argocd manifest generation path to all applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# This script is used to patch all argocd apps in a cluster | |
# the patch will add a new annotation to all apps | |
# the annotation will be used to prevent the app from being refreshed unnecessarily | |
# the following annotation will be added to all apps | |
# argocd.argoproj.io/manifest-generate-paths: . | |
set -euo pipefail | |
function usage { | |
echo "Usage: mg [subcommand]" | |
echo "Subcommands:" | |
echo " patch: Patch all argocd apps" | |
echo " help: Show this help message" | |
} | |
function main { | |
# get all argocd apps | |
apps=$(kubectl get applications -n argocd -o jsonpath='{.items[*].metadata.name}') | |
# loop through all apps | |
for app in $apps; do | |
# get the current annotations | |
annotations=$(kubectl get applications "$app" -n argocd -o jsonpath='{.metadata.annotations}') | |
# check if the annotation already exists | |
if [[ $annotations == *"argocd.argoproj.io/manifest-generate-paths"* ]]; then | |
echo "app $app already patched" | |
else | |
# add the annotation | |
kubectl patch applications "$app" -n argocd --type=merge -p '{"metadata":{"annotations":{"argocd.argoproj.io/manifest-generate-paths":"."}}}' | |
echo "app $app patched" | |
fi | |
done | |
} | |
case "$1" in | |
"patch") | |
main | |
;; | |
"help") | |
usage | |
;; | |
*) | |
usage | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment