From 95d730efae73d24e6b8157e3f1e988723cea3ea3 Mon Sep 17 00:00:00 2001 From: LiuLiqi <837397251@qq.com> Date: Fri, 24 Nov 2023 11:07:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9ci=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...roller_ci_build_batch_deploy_to_aliyun.yml | 121 +++++++++++++++++- 1 file changed, 116 insertions(+), 5 deletions(-) diff --git a/.github/workflows/module_controller_ci_build_batch_deploy_to_aliyun.yml b/.github/workflows/module_controller_ci_build_batch_deploy_to_aliyun.yml index 741da6fae..5f4da2fa2 100644 --- a/.github/workflows/module_controller_ci_build_batch_deploy_to_aliyun.yml +++ b/.github/workflows/module_controller_ci_build_batch_deploy_to_aliyun.yml @@ -336,14 +336,125 @@ jobs: - run: sleep 15 - - name: get module + - name: exist module run: | - kubectl get module -oyaml + moduleCount=$(kubectl get module | wc -l) + echo $moduleCount + if [[ $moduleCount -lt 3 ]]; then + echo "缩容失败" + exit 1 + fi - - name: exist module + - name: check moduledeployment pause then confirm + run: | + # 定义要等待的资源名称和字段值 + moduledeploymentname=$(kubectl get moduledeployment -o name) + desired_field_value=true + + # 定义等待的超时时间(以秒为单位) + timeout_seconds=300 + + start_time=$(date +%s) + end_time=$((start_time + timeout_seconds)) + + while true; do + current_time=$(date +%s) + if [ $current_time -gt $end_time ]; then + echo "等待超时" + exit 1 + fi + + # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 + field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + + if [ "$field_value" == "$desired_field_value" ]; then + echo "字段值已满足条件,执行分组确认" + kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + exit 0 + else + echo "等待字段值满足条件..." + sleep 5 # 等待一段时间后再次检查 + fi + done + + - name: exist module less then 2 run: | moduleCount=$(kubectl get module | wc -l) - if [[ $moduleCount -ge 2 ]]; then + echo $moduleCount + if [[ $moduleCount -lt 2 ]]; then echo "缩容失败" exit 1 - fi \ No newline at end of file + fi + + - name: check moduledeployment pause then confirm + run: | + # 定义要等待的资源名称和字段值 + moduledeploymentname=$(kubectl get moduledeployment -o name) + desired_field_value=true + + # 定义等待的超时时间(以秒为单位) + timeout_seconds=300 + + start_time=$(date +%s) + end_time=$((start_time + timeout_seconds)) + + while true; do + current_time=$(date +%s) + if [ $current_time -gt $end_time ]; then + echo "等待超时" + exit 1 + fi + + # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 + field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + + if [ "$field_value" == "$desired_field_value" ]; then + echo "字段值已满足条件,执行分组确认" + kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + exit 0 + else + echo "等待字段值满足条件..." + sleep 5 # 等待一段时间后再次检查 + fi + done + + - name: exist module less then 1 + run: | + moduleCount=$(kubectl get module | wc -l) + echo $moduleCount + if [[ $moduleCount -lt 1 ]]; then + echo "缩容失败" + exit 1 + fi + + - name: check moduledeployment pause then confirm + run: | + # 定义要等待的资源名称和字段值 + moduledeploymentname=$(kubectl get moduledeployment -o name) + desired_field_value=true + + # 定义等待的超时时间(以秒为单位) + timeout_seconds=300 + + start_time=$(date +%s) + end_time=$((start_time + timeout_seconds)) + + while true; do + current_time=$(date +%s) + if [ $current_time -gt $end_time ]; then + echo "等待超时" + exit 1 + fi + + # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 + field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + + if [ "$field_value" == "$desired_field_value" ]; then + echo "字段值已满足条件,执行分组确认" + kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + exit 0 + else + echo "等待字段值满足条件..." + sleep 5 # 等待一段时间后再次检查 + fi + done \ No newline at end of file