From b4d0007ace492be514823066f061c9c5136c612e Mon Sep 17 00:00:00 2001 From: KingsonKai <562419972@qq.com> Date: Fri, 27 Oct 2023 15:56:27 +0800 Subject: [PATCH] feat: support reload images to registry --- chaosmeta-deploy/deploy.sh | 133 ++++++++++-------- chaosmeta-deploy/retag_image.sh | 53 +++++++ .../templates/chaosmeta-daemon-template.yaml | 2 +- .../templates/chaosmeta-flow-template.yaml | 2 +- .../templates/chaosmeta-inject-template.yaml | 2 +- .../templates/chaosmeta-measure-template.yaml | 2 +- .../chaosmeta-platform-template.yaml | 6 +- .../chaosmeta-workflow-template.yaml | 7 +- 8 files changed, 140 insertions(+), 67 deletions(-) create mode 100644 chaosmeta-deploy/retag_image.sh diff --git a/chaosmeta-deploy/deploy.sh b/chaosmeta-deploy/deploy.sh index 41ce5b1..4f94502 100644 --- a/chaosmeta-deploy/deploy.sh +++ b/chaosmeta-deploy/deploy.sh @@ -8,32 +8,81 @@ COMPONENT_INJECT="inject" COMPONENT_DAEMON="daemon" COMPONENT_MEASURE="measure" COMPONENT_FLOW="flow" - OP_INSTALL="install" OP_UNINSTALL="uninstall" - NAMESPACE_REPLACE="DEPLOYNAMESPACE" +REGISTRY_REPLACE="DEPLOYREGISTRY" +NAMESPACE="chaosmeta" +OP="install" +REGISTRY="registry.cn-hangzhou.aliyuncs.com/chaosmeta" +COMPONENT="all" + BASE_DIR=$( cd $(dirname $0) pwd ) +# function define +function installComponent() { + TARGET_REGISTRY=${REGISTRY//\//\\/} + sed "s/${NAMESPACE_REPLACE}/$NAMESPACE/g; s/${REGISTRY_REPLACE}/$TARGET_REGISTRY/g" ${BASE_DIR}/templates/chaosmeta-$1-template.yaml >${BASE_DIR}/yamls/chaosmeta-$1.yaml + if [[ "$OP" == "$OP_INSTALL" ]]; then + kubectl apply -f ${BASE_DIR}/yamls/chaosmeta-$1.yaml + if [[ "$1" != "$COMPONENT_PLATFORM" && "$1" != "$COMPONENT_DAEMON" && "$1" != "$COMPONENT_WORKFLOW" ]]; then + sh tools/build.sh $1 $NAMESPACE + fi + else + kubectl delete -f ${BASE_DIR}/yamls/chaosmeta-$1.yaml + if [[ "$1" != "$COMPONENT_PLATFORM" && "$1" != "$COMPONENT_DAEMON" && "$1" != "$COMPONENT_WORKFLOW" ]]; then + kubectl delete secret chaosmeta-$1-webhook-server-cert -n $NAMESPACE + fi + fi +} + +function process_args() { + while getopts ":n:o:c:r:h" opt; do + case $opt in + n) + NAMESPACE=$OPTARG + ;; + o) + OP=$OPTARG + ;; + c) + COMPONENT=$OPTARG + ;; + r) + REGISTRY=$OPTARG + ;; + h) + echo "-n:existed namespace of kubernetes" + echo "-r:image registry" + echo "-o:install、uninstall" + echo "-c:all、$COMPONENT_PLATFORM、$COMPONENT_WORKFLOW、$COMPONENT_INJECT、$COMPONENT_DAEMON、$COMPONENT_MEASURE、$COMPONENT_FLOW" + exit 1 + ;; + \?) + echo "invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "option -$OPTARG need an args" >&2 + exit 1 + ;; + esac + done +} + +process_args "$@" +echo "namespace:$NAMESPACE" +echo "operation:$OP" +echo "image registry:$REGISTRY" +echo "component:$COMPONENT" +echo "================================================================" +sleep 3s + mkdir -p ${BASE_DIR}/yamls # param check -OP=$1 -NAMESPACE=$2 -COMPONENT_LIST=() -for ((i = 3; i <= $#; i++)); do - COMPONENT_LIST+=("${!i}") -done - -if [ "$OP" == "-h" ] || [ "$OP" == "--help" ] || [ -z "$OP" ] || [ ${#COMPONENT_LIST[@]} -eq 0 ]; then - echo -e "\nformat: sh deploy.sh [operation] [namespace] [component list]" - echo -e "example: sh deploy.sh install default ${COMPONENT_PLATFORM} ${COMPONENT_WORKFLOW} ${COMPONENT_INJECT} ${COMPONENT_DAEMON}\n" - echo "operation support: ${OP_INSTALL} ${OP_UNINSTALL}" - echo -e "component support: ${COMPONENT_ALL} ${COMPONENT_PLATFORM} ${COMPONENT_WORKFLOW} ${COMPONENT_INJECT} ${COMPONENT_MEASURE} ${COMPONENT_FLOW} ${COMPONENT_DAEMON}\n" - exit 1 -fi if [[ "$OP" != "$OP_INSTALL" && "$OP" != "$OP_UNINSTALL" ]]; then echo "not support operation: $OP" @@ -52,45 +101,13 @@ if [[ $(kubectl get ns $NAMESPACE | wc -l) -eq 0 ]]; then exit 2 fi -for COMPONENT in "${COMPONENT_LIST[@]}"; do - if [ ${#COMPONENT_LIST[@]} -ne 1 ] && [ "$COMPONENT" == "$COMPONENT_ALL" ]; then - echo "component[$COMPONENT_ALL] should not in list with other components" - exit 3 - fi - - if [[ "$COMPONENT" != "$COMPONENT_WORKFLOW" && "$COMPONENT" != "$COMPONENT_DAEMON" && "$COMPONENT" != "$COMPONENT_ALL" && "$COMPONENT" != "$COMPONENT_PLATFORM" && "$COMPONENT" != "$COMPONENT_INJECT" && "$COMPONENT" != "$COMPONENT_MEASURE" && "$COMPONENT" != "$COMPONENT_FLOW" ]]; then - echo "not support component: $COMPONENT" - echo "component support: ${COMPONENT_ALL} ${COMPONENT_PLATFORM} ${COMPONENT_WORKFLOW} ${COMPONENT_INJECT} ${COMPONENT_MEASURE} ${COMPONENT_FLOW} ${COMPONENT_DAEMON}" - echo "example: sh deploy.sh install default ${COMPONENT_PLATFORM} ${COMPONENT_WORKFLOW} ${COMPONENT_INJECT} ${COMPONENT_DAEMON}" - exit 1 - fi -done - -function installComponent() { - sed "s/${NAMESPACE_REPLACE}/$2/g" ${BASE_DIR}/templates/chaosmeta-$1-template.yaml >${BASE_DIR}/yamls/chaosmeta-$1.yaml - if [[ "$OP" == "$OP_INSTALL" ]]; then - kubectl apply -f ${BASE_DIR}/yamls/chaosmeta-$1.yaml - if [[ "$1" != "$COMPONENT_PLATFORM" && "$1" != "$COMPONENT_DAEMON" && "$1" != "$COMPONENT_WORKFLOW" ]]; then - sh tools/build.sh $1 $2 - fi - else - kubectl delete -f ${BASE_DIR}/yamls/chaosmeta-$1.yaml - if [[ "$1" != "$COMPONENT_PLATFORM" && "$1" != "$COMPONENT_DAEMON" && "$1" != "$COMPONENT_WORKFLOW" ]]; then - kubectl delete secret chaosmeta-$1-webhook-server-cert -n $2 - fi - fi -} - -# execute install -for COMPONENT in "${COMPONENT_LIST[@]}"; do - if [[ "$COMPONENT" == "$COMPONENT_ALL" ]]; then - installComponent $COMPONENT_PLATFORM $NAMESPACE - installComponent $COMPONENT_WORKFLOW $NAMESPACE - installComponent $COMPONENT_INJECT $NAMESPACE - installComponent $COMPONENT_DAEMON $NAMESPACE - installComponent $COMPONENT_MEASURE $NAMESPACE - installComponent $COMPONENT_FLOW $NAMESPACE - else - installComponent $COMPONENT $NAMESPACE - fi -done +if [[ "$COMPONENT" == "$COMPONENT_ALL" ]]; then + installComponent $COMPONENT_PLATFORM + installComponent $COMPONENT_WORKFLOW + installComponent $COMPONENT_INJECT + installComponent $COMPONENT_DAEMON + installComponent $COMPONENT_MEASURE + installComponent $COMPONENT_FLOW +else + installComponent $COMPONENT +fi diff --git a/chaosmeta-deploy/retag_image.sh b/chaosmeta-deploy/retag_image.sh new file mode 100644 index 0000000..0cfed91 --- /dev/null +++ b/chaosmeta-deploy/retag_image.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +BASE_DIR=$( + cd $(dirname $0) + pwd +) +source_registry="registry.cn-hangzhou.aliyuncs.com/chaosmeta" +target_registry="" +REGISTRY_REPLACE="DEPLOYREGISTRY" +function process_args() { + while getopts ":r:h" opt; do + case $opt in + r) + target_registry=$OPTARG + ;; + h) + echo "-r:target image registry" + exit 1 + ;; + \?) + echo "invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "option -$OPTARG need an args" >&2 + exit 1 + ;; + esac + done +} + +process_args "$@" +if [[ -z "$target_registry" ]]; then + echo "please provide args: -r" + exit 1 +fi + +echo "target registry: $target_registry" +image_list=$(cat templates/* | grep 'image:' | awk -F'image: ' '{print $2}' | tr '\n' ',') +IFS=',' +image_array=($image_list) +source_registry=${source_registry//\//\\/} +target_registry=${target_registry//\//\\/} + +for image in "${image_array[@]}"; do + source_image=$(echo "$image" | sed "s/$REGISTRY_REPLACE/$source_registry/g") + dst_image=$(echo "$image" | sed "s/$REGISTRY_REPLACE/$target_registry/g") + echo "source image: $source_image" + echo "target image: $dst_image" + docker pull $source_image + docker tag $source_image $dst_image + docker push $dst_image +done diff --git a/chaosmeta-deploy/templates/chaosmeta-daemon-template.yaml b/chaosmeta-deploy/templates/chaosmeta-daemon-template.yaml index 906a2d3..7857c18 100644 --- a/chaosmeta-deploy/templates/chaosmeta-daemon-template.yaml +++ b/chaosmeta-deploy/templates/chaosmeta-daemon-template.yaml @@ -19,7 +19,7 @@ spec: # chaos-role.chaosmeta.io: chaosmeta-daemon containers: - name: chaosmeta-daemon - image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-daemon:v0.3.9 + image: DEPLOYREGISTRY/chaosmeta-daemon:v0.3.9 securityContext: privileged: true volumeMounts: diff --git a/chaosmeta-deploy/templates/chaosmeta-flow-template.yaml b/chaosmeta-deploy/templates/chaosmeta-flow-template.yaml index 3c017a9..d0c5c79 100644 --- a/chaosmeta-deploy/templates/chaosmeta-flow-template.yaml +++ b/chaosmeta-deploy/templates/chaosmeta-flow-template.yaml @@ -303,7 +303,7 @@ spec: - --leader-elect command: - /manager - image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-flow-controller:v0.0.2 + image: DEPLOYREGISTRY/chaosmeta-flow-controller:v0.0.2 livenessProbe: httpGet: path: /healthz diff --git a/chaosmeta-deploy/templates/chaosmeta-inject-template.yaml b/chaosmeta-deploy/templates/chaosmeta-inject-template.yaml index e3223eb..d927b54 100644 --- a/chaosmeta-deploy/templates/chaosmeta-inject-template.yaml +++ b/chaosmeta-deploy/templates/chaosmeta-inject-template.yaml @@ -386,7 +386,7 @@ spec: - --leader-elect command: - /manager - image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-inject-controller:v0.1.1 + image: DEPLOYREGISTRY/chaosmeta-inject-controller:v0.1.1 livenessProbe: httpGet: path: /healthz diff --git a/chaosmeta-deploy/templates/chaosmeta-measure-template.yaml b/chaosmeta-deploy/templates/chaosmeta-measure-template.yaml index c889a47..9fd6bbc 100644 --- a/chaosmeta-deploy/templates/chaosmeta-measure-template.yaml +++ b/chaosmeta-deploy/templates/chaosmeta-measure-template.yaml @@ -320,7 +320,7 @@ spec: - --leader-elect command: - /manager - image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-measure-controller:v0.0.6 + image: DEPLOYREGISTRY/chaosmeta-measure-controller:v0.0.6 livenessProbe: httpGet: path: /healthz diff --git a/chaosmeta-deploy/templates/chaosmeta-platform-template.yaml b/chaosmeta-deploy/templates/chaosmeta-platform-template.yaml index 14601b5..b644860 100644 --- a/chaosmeta-deploy/templates/chaosmeta-platform-template.yaml +++ b/chaosmeta-deploy/templates/chaosmeta-platform-template.yaml @@ -89,7 +89,7 @@ spec: serviceAccountName: chaosmeta-platform containers: - name: chaosmeta-platform - image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-platform:v0.0.7 + image: DEPLOYREGISTRY/chaosmeta-platform:v0.6.0 resources: requests: cpu: "1" @@ -101,7 +101,7 @@ spec: - name: chaosmeta-config mountPath: /home/admin/conf - name: chaosmeta-platform-frontend - image: registry.cn-hangzhou.aliyuncs.com/chaosmeta/chaosmeta-platform-frontend:v0.0.4 + image: DEPLOYREGISTRY/chaosmeta-platform-frontend:v0.6.0 ports: - containerPort: 8000 volumes: @@ -144,7 +144,7 @@ spec: spec: serviceAccountName: chaosmeta-platform containers: - - image: mysql:8.0 + - image: DEPLOYREGISTRY/mysql:8.0 name: chaosmeta-mysql env: - name: MYSQL_DATABASE diff --git a/chaosmeta-deploy/templates/chaosmeta-workflow-template.yaml b/chaosmeta-deploy/templates/chaosmeta-workflow-template.yaml index fddb3cc..d1b5a26 100644 --- a/chaosmeta-deploy/templates/chaosmeta-workflow-template.yaml +++ b/chaosmeta-deploy/templates/chaosmeta-workflow-template.yaml @@ -1217,6 +1217,9 @@ kind: ConfigMap metadata: name: workflow-controller-configmap namespace: DEPLOYNAMESPACE +data: + executor: | + image: DEPLOYREGISTRY/argoexec:v3.4.10 --- apiVersion: v1 kind: Service @@ -1255,7 +1258,7 @@ spec: - args: - server env: [] - image: quay.io/argoproj/argocli:v3.4.10 + image: DEPLOYREGISTRY/argocli:v3.4.10 name: argo-server ports: - containerPort: 2746 @@ -1310,7 +1313,7 @@ spec: fieldRef: apiVersion: v1 fieldPath: metadata.name - image: quay.io/argoproj/workflow-controller:v3.4.10 + image: DEPLOYREGISTRY/workflow-controller:v3.4.10 livenessProbe: failureThreshold: 3 httpGet: