added argocd_apps_wait_sync.sh
9b91df72
Hari Sekhon
committed
1 changed file
argocd_apps_wait_sync.sh
/argocd_apps_wait_sync.sh+57
/argocd_apps_wait_sync.sh
Add comment 1 Plus  #!/usr/bin/env bash
Add comment 2 Plus  # vim:ts=4:sts=4:sw=4:et
Add comment 3 Plus  #
Add comment 4 Plus  # Author: Hari Sekhon
Add comment 5 Plus  # Date: 2023-05-08 20:31:59 +0100 (Mon, 08 May 2023)
Add comment 6 Plus  #
Add comment 7 Plus  # https://github.com/HariSekhon/DevOps-Bash-tools
Add comment 8 Plus  #
Add comment 9 Plus  # License: see accompanying Hari Sekhon LICENSE file
Add comment 10 Plus  #
Add comment 11 Plus  # If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
Add comment 12 Plus  #
Add comment 13 Plus  # https://www.linkedin.com/in/HariSekhon
Add comment 14 Plus  #
Add comment 15 Plus  
Add comment 16 Plus  set -euo pipefail
Add comment 17 Plus  [ -n "${DEBUG:-}" ] && set -x
Add comment 18 Plus  srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
Add comment 19 Plus  
Add comment 20 Plus  # shellcheck disable=SC1090,SC1091
Add comment 21 Plus  . "$srcdir/lib/utils.sh"
Add comment 22 Plus  
Add comment 23 Plus  # shellcheck disable=SC2034,SC2154
Add comment 24 Plus  usage_description="
Add comment 25 Plus  Sync all ArgoCD apps matching an optional given ERE regex filter
Add comment 26 Plus  
Add comment 27 Plus  Requires ArgoCD CLI to be installed and configured for authentication
Add comment 28 Plus  
Add comment 29 Plus  You may also want to set some environment variables such as:
Add comment 30 Plus  
Add comment 31 Plus   export ARGOCD_SERVER='argocd.domain.com'
Add comment 32 Plus   export ARGOCD_OPTS='--grpc-web --timeout 600'
Add comment 33 Plus  "
Add comment 34 Plus  
Add comment 35 Plus  # used by usage() in lib/utils.sh
Add comment 36 Plus  # shellcheck disable=SC2034
Add comment 37 Plus  usage_args="[<name_filter>]"
Add comment 38 Plus  
Add comment 39 Plus  help_usage "$@"
Add comment 40 Plus  
Add comment 41 Plus  max_args 1 "$@"
Add comment 42 Plus  
Add comment 43 Plus  filter="${1:-.*}"
Add comment 44 Plus  
Add comment 45 Plus  argocd app list |
Add comment 46 Plus  awk '{print $1}' |
Add comment 47 Plus  { grep -E "$filter" || : ; } |
Add comment 48 Plus  while read -r app; do
Add comment 49 Plus   echo "Syncing app '$app':"
Add comment 50 Plus   echo
Add comment 51 Plus   cmd=(argocd app wait "$app" --sync --operation --health)
Add comment 52 Plus   echo "${cmd[*]}"
Add comment 53 Plus   "${cmd[@]}"
Add comment 54 Plus   echo
Add comment 55 Plus   echo
Add comment 56 Plus  done
Add comment 57 Plus