Skip to content

Commit

Permalink
feat: support reload images to registry
Browse files Browse the repository at this point in the history
  • Loading branch information
KingsonKai committed Oct 27, 2023
1 parent 19eec17 commit b4d0007
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 67 deletions.
133 changes: 75 additions & 58 deletions chaosmeta-deploy/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
53 changes: 53 additions & 0 deletions chaosmeta-deploy/retag_image.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion chaosmeta-deploy/templates/chaosmeta-daemon-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion chaosmeta-deploy/templates/chaosmeta-flow-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chaosmeta-deploy/templates/chaosmeta-inject-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chaosmeta-deploy/templates/chaosmeta-measure-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions chaosmeta-deploy/templates/chaosmeta-platform-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions chaosmeta-deploy/templates/chaosmeta-workflow-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b4d0007

Please sign in to comment.