From ce59e49ebe23d182d83a72cba19c3fdc48e2082c Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Sat, 16 Mar 2024 14:50:31 +0800 Subject: [PATCH] check_docker_registry_secret.sh: update --- scripts/check_docker_registry_secret.sh | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/check_docker_registry_secret.sh b/scripts/check_docker_registry_secret.sh index 40d0020..cd8c1f2 100644 --- a/scripts/check_docker_registry_secret.sh +++ b/scripts/check_docker_registry_secret.sh @@ -7,15 +7,27 @@ check_not_empty() { fi } -function run() -{ - - # 检查参数是否为空 +function run() { check_not_empty "$1" "cluster" && local cluster=$1 check_not_empty "$2" "namespace" && local namespace=$2 - check_not_empty "$3" "secret" && local secret=$3 kubectl config set-context --current --namespace $namespace - echo $cluster $namespace $secret + + for secret in $(kubectl get secrets -n $namespace -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep '\.dockerconfigjson$'); do + echo "$cluster $namespace $secret" + done +} + +function print_base64_data() { + local namespace=$1 + local secret=$2 + local cluster=$3 + echo "$cluster $namespace $secret" kubectl get secret $secret -n $namespace --output="jsonpath={.data.\.dockerconfigjson}" | base64 --decode || true } + +cluster="$1" +namespace="$2" + +run "$cluster" "$namespace" +print_base64_data "$namespace" "$secret" "$cluster"