From 542dae20453408aa86ef9713935ac793d9b7cce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C4=83t=C4=83lin?= Date: Mon, 20 Apr 2026 10:25:34 +0200 Subject: [PATCH 1/3] feat: add scripts/k3scale.sh --- scripts/k3scale.sh | 162 +++++++++++++++++++++++++++++++++++++++ scripts/proxmox-power.sh | 0 2 files changed, 162 insertions(+) create mode 100755 scripts/k3scale.sh mode change 100644 => 100755 scripts/proxmox-power.sh diff --git a/scripts/k3scale.sh b/scripts/k3scale.sh new file mode 100755 index 0000000..945990f --- /dev/null +++ b/scripts/k3scale.sh @@ -0,0 +1,162 @@ +#!/usr/bin/env bash + + +usage() { + cat <&2 + usage >&2 + exit 1 + ;; + *) + if [[ -z "$REPLICAS" ]]; then + REPLICAS="$1" + else + RESOURCES+=("$1") + fi + shift + ;; + esac +done + +if [[ -z "$REPLICAS" ]]; then + echo "Error: REPLICAS is required" >&2 + usage >&2 + exit 1 +fi + +if [[ "$ALL" == false && "$ALL_NAMESPACES" == false && ${#RESOURCES[@]} -eq 0 ]]; then + echo "Error: Must specify --all, --all-namespaces, or at least one RESOURCE" >&2 + usage >&2 + exit 1 +fi + +NAMESPACE_ARG=() +if [[ -n "$NAMESPACE" ]]; then + NAMESPACE_ARG=("-n" "$NAMESPACE") +fi + +DRY_RUN_ARG=() +if [[ "$DRY_RUN" == true ]]; then + DRY_RUN_ARG=("--dry-run=client") +fi + +KUBECTL_BASE=(kubectl) +if [[ -n "$KUBECTL_V" ]]; then + KUBECTL_BASE+=( "$KUBECTL_V" ) +fi +KUBECTL_BASE+=( "${NAMESPACE_ARG[@]}" ) +KUBECTL_BASE+=( "${DRY_RUN_ARG[@]}" ) + +scale_resource() { + local resource="$1" + local ns name + + if [[ "$resource" == */* ]]; then + ns="${resource%%/*}" + name="${resource#*/}" + else + ns="${NAMESPACE:-$(kubectl "${NAMESPACE_ARG[@]}" config view --minify --output jsonpath='{.contexts[0].context.namespace}' 2>/dev/null || echo "default")}" + name="$resource" + fi + + for kind in deployment statefulset; do + if "${KUBECTL_BASE[@]}" get "$kind" "$name" -n "$ns" &>/dev/null; then + echo "Scaling $kind/$ns/$name to $REPLICAS replicas${DRY_RUN:+ (dry-run)}" + "${KUBECTL_BASE[@]}" scale "$kind" "$name" -n "$ns" --replicas="$REPLICAS" + return 0 + fi + done + + echo "Error: Resource '$resource' not found as deployment or statefulset" >&2 + return 1 +} + +get_resources() { + local ns_flag=() + if [[ "$ALL_NAMESPACES" == true ]]; then + ns_flag=("--all-namespaces") + elif [[ -n "$NAMESPACE" ]]; then + ns_flag=("-n" "$NAMESPACE") + fi + + "${KUBECTL_BASE[@]}" get "${ns_flag[@]}" deployment,statefulset -o jsonpath='{range .items[*]}{.metadata.namespace}/{.kind}/{.metadata.name}{"\n"}{end}' 2>/dev/null | while IFS=/ read -r ns kind name; do + echo "$ns/$name" + done +} + +if [[ "$ALL" == true || "$ALL_NAMESPACES" == true ]]; then + while IFS= read -r resource; do + [[ -n "$resource" ]] && scale_resource "$resource" + done < <(get_resources) +else + for resource in "${RESOURCES[@]}"; do + scale_resource "$resource" + done +fi diff --git a/scripts/proxmox-power.sh b/scripts/proxmox-power.sh old mode 100644 new mode 100755 From c8cc8e3f20b854519e21abee39506a92d3ab3a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C4=83t=C4=83lin?= Date: Wed, 22 Apr 2026 13:27:37 +0200 Subject: [PATCH 2/3] feat: add scripts/update-argo.sh --- .pre-commit-config.yaml | 8 +-- scripts/update-argo.sh | 129 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 4 deletions(-) create mode 100755 scripts/update-argo.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c2bed7c..fc7cc6a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -15,18 +15,18 @@ repos: - id: trailing-whitespace - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.92.1 + rev: v1.105.0 hooks: - id: terraform_fmt - repo: https://github.com/adrienverge/yamllint.git - rev: v1.35.1 + rev: v1.38.0 hooks: - id: yamllint args: [--format, parsable, --strict] - repo: https://github.com/shellcheck-py/shellcheck-py - rev: v0.10.0.1 + rev: v0.11.0.1 hooks: - id: shellcheck files: \.sh diff --git a/scripts/update-argo.sh b/scripts/update-argo.sh new file mode 100755 index 0000000..fbdd1da --- /dev/null +++ b/scripts/update-argo.sh @@ -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 <&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" From 375113b7c813507e909e7064353d8a8415fe5a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C4=83t=C4=83lin?= Date: Wed, 22 Apr 2026 13:28:10 +0200 Subject: [PATCH 3/3] feat: update oxicloud to 0.5.6 --- k8s/argo-apps/oxicloud.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/argo-apps/oxicloud.yaml b/k8s/argo-apps/oxicloud.yaml index 8e23128..2e2ba46 100644 --- a/k8s/argo-apps/oxicloud.yaml +++ b/k8s/argo-apps/oxicloud.yaml @@ -18,7 +18,7 @@ spec: image: repository: diocrafts/oxicloud pullPolicy: Always - tag: "0.5.5" + tag: "0.5.6" persistence: enabled: true storageClass: "truenas-nfs-csi"