diff --git a/scripts/backup_docker_registry_secret.sh b/scripts/backup_docker_registry_secret.sh new file mode 100644 index 0000000..685b26a --- /dev/null +++ b/scripts/backup_docker_registry_secret.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +check_not_empty() { + if [[ -z $1 ]]; then + echo "Error: $2 is empty. Please provide a value." + exit 1 + fi +} + +function backup_docker_registry_secret() +{ + + # 检查参数是否为空 + check_not_empty "$1" "cluster" && local cluster=$1 + check_not_empty "$2" "namespace" && local namespace=$2 + check_not_empty "$3" "secret" && local secret=$3 + + mkdir -pv ~/Backups/ + kubectl config set-context --current --namespace $namespace + kubectl get secret $secret -n $namespace -o yaml > ~/Backups/$cluster-$namespace-$secret.yaml +} diff --git a/scripts/check_docker_registry_secret.sh b/scripts/check_docker_registry_secret.sh new file mode 100644 index 0000000..40d0020 --- /dev/null +++ b/scripts/check_docker_registry_secret.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +check_not_empty() { + if [[ -z $1 ]]; then + echo "Error: $2 is empty. Please provide a value." + exit 1 + fi +} + +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 + kubectl get secret $secret -n $namespace --output="jsonpath={.data.\.dockerconfigjson}" | base64 --decode || true +} diff --git a/scripts/list_cluster_namespace_map.sh b/scripts/list_cluster_namespace_map.sh new file mode 100644 index 0000000..119cf0a --- /dev/null +++ b/scripts/list_cluster_namespace_map.sh @@ -0,0 +1,6 @@ +clusters=( $(ls) ) + +for cluster in "${clusters[@]}"; do + namespaces=$(grep -ir namespace $cluster | awk -Fnamespace: '{print $2}' | sort | uniq) + echo "$cluster $namespaces" +done diff --git a/scripts/renew_docker_registry_secret_with_kubectl.sh b/scripts/renew_docker_registry_secret_with_kubectl.sh new file mode 100644 index 0000000..31eff3f --- /dev/null +++ b/scripts/renew_docker_registry_secret_with_kubectl.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +check_not_empty() { + if [[ -z $1 ]]; then + echo "Error: $2 is empty. Please provide a value." + exit 1 + fi +} + +function renew_docker_registry_secret() +{ + + # 检查参数是否为空 + check_not_empty "$1" "cluster" && local cluster=$1 + check_not_empty "$2" "namespace" && local namespace=$2 + check_not_empty "$3" "secret" && local secret=$3 + check_not_empty "$4" "username" && local username=$4 + check_not_empty "$5" "password" && local password=$5 + + fuze k8s clusters connect $cluster && kubectl config set-context --current --namespace $namespace + kubectl delete secret $secret -n $namespace || true + kubectl create secret docker-registry $secret \ + --docker-server=artifact.onwalk.net \ + --docker-username=$username \ + --docker-password=$password \ + --docker-email=manbzuhe2009@qq.com \ + -n $namespace + + kubectl get secret $secret -n $namespace --output="jsonpath={.data.\.dockerconfigjson}" | base64 --decode || true +} diff --git a/scripts/rollout_docker_registry_secret.sh b/scripts/rollout_docker_registry_secret.sh new file mode 100644 index 0000000..7836ffe --- /dev/null +++ b/scripts/rollout_docker_registry_secret.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +check_not_empty() { + if [[ -z $1 ]]; then + echo "Error: $2 is empty. Please provide a value." + exit 1 + fi +} + +function rollout_docker_registry_secret() +{ + + # 检查参数是否为空 + check_not_empty "$1" "cluster" && local cluster=$1 + check_not_empty "$2" "namespace" && local namespace=$2 + check_not_empty "$3" "secret" && local secret=$3 + + mkdir -pv ~/Backups/ + kubectl config set-context --current --namespace $namespace + kubectl apply -f ~/Backups/~/Backups/$cluster-$namespace-$secret.yaml +} diff --git a/scripts/verify_rew_docker_registry_secret.sh b/scripts/verify_rew_docker_registry_secret.sh new file mode 100644 index 0000000..eaf1680 --- /dev/null +++ b/scripts/verify_rew_docker_registry_secret.sh @@ -0,0 +1,63 @@ + +#!/bin/sh + +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' + +check_not_empty() { + if [[ -z $1 ]]; then + echo "Error: $2 is empty. Please provide a value." + exit 1 + fi +} + +function verify_docker_registry_secret() +{ + + # 检查参数是否为空 + 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 + kubectl get secret $secret -n $namespace --output="jsonpath={.data.\.dockerconfigjson}" | base64 --decode || true + +cat <