feat: add scripts/update-argo.sh
This commit is contained in:
parent
542dae2045
commit
c8cc8e3f20
2 changed files with 133 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v5.0.0
|
rev: v6.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
|
|
@ -15,18 +15,18 @@ repos:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
|
|
||||||
- repo: https://github.com/antonbabenko/pre-commit-terraform
|
- repo: https://github.com/antonbabenko/pre-commit-terraform
|
||||||
rev: v1.92.1
|
rev: v1.105.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: terraform_fmt
|
- id: terraform_fmt
|
||||||
|
|
||||||
- repo: https://github.com/adrienverge/yamllint.git
|
- repo: https://github.com/adrienverge/yamllint.git
|
||||||
rev: v1.35.1
|
rev: v1.38.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: yamllint
|
- id: yamllint
|
||||||
args: [--format, parsable, --strict]
|
args: [--format, parsable, --strict]
|
||||||
|
|
||||||
- repo: https://github.com/shellcheck-py/shellcheck-py
|
- repo: https://github.com/shellcheck-py/shellcheck-py
|
||||||
rev: v0.10.0.1
|
rev: v0.11.0.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: shellcheck
|
- id: shellcheck
|
||||||
files: \.sh
|
files: \.sh
|
||||||
|
|
|
||||||
129
scripts/update-argo.sh
Executable file
129
scripts/update-argo.sh
Executable file
|
|
@ -0,0 +1,129 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
check_kubectl() {
|
||||||
|
if ! command -v kubectl &>/dev/null; then
|
||||||
|
echo "Error: kubectl is not installed or not in PATH" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
log_info "kubectl found at $(command -v kubectl)"
|
||||||
|
}
|
||||||
|
|
||||||
|
VERBOSE=0
|
||||||
|
|
||||||
|
log_debug() { [[ $VERBOSE -ge 3 ]] && echo "[DEBUG] $*" || true; }
|
||||||
|
log_verbose() { [[ $VERBOSE -ge 2 ]] && echo "[VERBOSE] $*" || true; }
|
||||||
|
log_info() { [[ $VERBOSE -ge 1 ]] && echo "[INFO] $*" || true; }
|
||||||
|
log_error() { echo "[ERROR] $*" >&2; }
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $(basename "$0") [OPTIONS] [VERSION]
|
||||||
|
|
||||||
|
Upgrade ArgoCD to a new version. Requires an existing ArgoCD installation.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
$(basename "$0") # queries the current argo version and tries to update to the immediate newest version
|
||||||
|
$(basename "$0") v4.3.0 # incrementally update to target version
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help Show this help message
|
||||||
|
--dry-run Show what would be done without making changes
|
||||||
|
-v Verbose output (info level)
|
||||||
|
-vv More verbose output (info + verbose level)
|
||||||
|
-vvv Debug output (all log levels)
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
DRY_RUN=false
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
--dry-run)
|
||||||
|
DRY_RUN=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-v|-vv|-vvv)
|
||||||
|
case "$1" in
|
||||||
|
-v) VERBOSE=1 ;;
|
||||||
|
-vv) VERBOSE=2 ;;
|
||||||
|
-vvv) VERBOSE=3 ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
echo "Error: Unknown option: $1" >&2
|
||||||
|
usage >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
TARGET_VERSION="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
log_debug "Script started with target version: ${TARGET_VERSION:-auto}"
|
||||||
|
|
||||||
|
check_kubectl
|
||||||
|
|
||||||
|
log_info "Checking current kubectl context"
|
||||||
|
CURRENT_CONTEXT=$(kubectl config current-context 2>/dev/null)
|
||||||
|
log_verbose "Current context: $CURRENT_CONTEXT"
|
||||||
|
|
||||||
|
log_info "Checking for ArgoCD installation"
|
||||||
|
if ! kubectl get ns argocd &>/dev/null; then
|
||||||
|
log_error "ArgoCD namespace not found. This script only upgrades existing installations."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
log_verbose "ArgoCD namespace found"
|
||||||
|
|
||||||
|
log_info "Checking current ArgoCD version"
|
||||||
|
CURRENT_VERSION=$(kubectl get deployment argocd-server -n argocd -o jsonpath='{.spec.template.spec.containers[0].image}' 2>/dev/null)
|
||||||
|
if [[ -n "$CURRENT_VERSION" ]]; then
|
||||||
|
CURRENT_VERSION=$(echo "$CURRENT_VERSION" | sed 's/.*argocd:v\?//' | tr -d ' \n')
|
||||||
|
if [[ -n "$CURRENT_VERSION" ]]; then
|
||||||
|
CURRENT_VERSION="${CURRENT_VERSION#v}"
|
||||||
|
log_verbose "Current ArgoCD version: $CURRENT_VERSION"
|
||||||
|
else
|
||||||
|
log_error "Could not extract ArgoCD version from image: $CURRENT_VERSION"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$TARGET_VERSION" ]]; then
|
||||||
|
log_info "No target version specified, querying for latest version"
|
||||||
|
log_verbose "Fetching latest release from GitHub"
|
||||||
|
LATEST_VERSION=$(curl -s https://api.github.com/repos/argoproj/argo-cd/releases/latest | grep -oP '"tag_name":\s*"\K[^"]+' | sed 's/^v//')
|
||||||
|
if [[ -n "$LATEST_VERSION" ]]; then
|
||||||
|
log_verbose "Latest version available: $LATEST_VERSION"
|
||||||
|
TARGET_VERSION="$LATEST_VERSION"
|
||||||
|
else
|
||||||
|
echo "Error: Could not fetch latest version" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_info "Target version: $TARGET_VERSION"
|
||||||
|
|
||||||
|
log_debug "Determining update path from $CURRENT_VERSION to $TARGET_VERSION"
|
||||||
|
|
||||||
|
log_info "Applying ArgoCD manifests"
|
||||||
|
log_verbose "Downloading manifest from https://raw.githubusercontent.com/argoproj/argo-cd/v${TARGET_VERSION}/manifests/install.yaml"
|
||||||
|
curl -sLO "https://raw.githubusercontent.com/argoproj/argo-cd/v${TARGET_VERSION}/manifests/install.yaml"
|
||||||
|
|
||||||
|
log_debug "Applying manifest with kubectl"
|
||||||
|
if [[ "$DRY_RUN" == true ]]; then
|
||||||
|
log_verbose "Dry-run mode: would apply manifest"
|
||||||
|
kubectl apply -n argocd -f install.yaml --dry-run=client
|
||||||
|
else
|
||||||
|
kubectl apply -n argocd -f install.yaml
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_verbose "Cleaning up downloaded manifest"
|
||||||
|
rm -f install.yaml
|
||||||
|
|
||||||
|
log_info "Update to ArgoCD $TARGET_VERSION initiated"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue