chenlei3641 pushed module-controller code #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Module Controller Integration Test scaleup then scaledown batch deploy | |
run-name: ${{ github.actor }} pushed module-controller code | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- 'module-controller/**' | |
pull_request: | |
branches: | |
- master | |
paths: | |
- 'module-controller/**' | |
# enable manually running the workflow | |
workflow_dispatch: | |
env: | |
CGO_ENABLED: 0 | |
GOOS: linux | |
WORK_DIR: module-controller | |
TAG: ci-test-master-latest | |
DOCKERHUB_REGISTRY: serverless-registry.cn-shanghai.cr.aliyuncs.com | |
MODULE_CONTROLLER_IMAGE_PATH: opensource/test/module-controller | |
INTEGRATION_TESTS_IMAGE_PATH: opensource/test/module-controller-integration-tests | |
POD_NAMESPACE: default | |
defaults: | |
run: | |
working-directory: module-controller | |
jobs: | |
unit-test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Docker login | |
uses: docker/login-action@v2.2.0 | |
with: | |
registry: ${{ env.DOCKERHUB_REGISTRY }} | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
logout: false | |
- name: Set up Docker buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ hashFiles('${{ env.WORK_DIR }}/*Dockerfile') }} | |
- name: Build and push module-controller Docker images | |
uses: docker/build-push-action@v4.1.1 | |
with: | |
context: ${{ env.WORK_DIR }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache | |
file: ${{ env.WORK_DIR }}/Dockerfile | |
platforms: linux/amd64 | |
push: true | |
tags: ${{ env.DOCKERHUB_REGISTRY }}/${{ env.MODULE_CONTROLLER_IMAGE_PATH }}:${{ env.TAG }} | |
- run: sleep 30 | |
- name: Set up Minikube | |
run: | | |
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 | |
sudo install minikube-linux-amd64 /usr/local/bin/minikube | |
- name: Start Minikube | |
run: minikube start | |
- name: Prepare development env | |
run: | | |
kubectl apply -f config/crd/bases/serverless.alipay.com_moduledeployments.yaml | |
kubectl apply -f config/crd/bases/serverless.alipay.com_modulereplicasets.yaml | |
kubectl apply -f config/crd/bases/serverless.alipay.com_modules.yaml | |
kubectl apply -f config/crd/bases/serverless.alipay.com_moduletemplates.yaml | |
kubectl apply -f config/rbac/role.yaml | |
kubectl apply -f config/rbac/role_binding.yaml | |
kubectl apply -f config/rbac/service_account.yaml | |
kubectl apply -f config/samples/ci/dynamic-stock-batch-deployment.yaml | |
kubectl apply -f config/samples/ci/module-deployment-controller.yaml | |
kubectl apply -f config/samples/ci/dynamic-stock-service.yaml | |
- run: sleep 60 | |
- name: minikube logs | |
run: minikube logs | |
- name: get pod | |
run: | | |
kubectl get pod | |
- name: wait base pod available | |
run: | | |
kubectl wait --for=condition=available deployment/dynamic-stock-deployment --timeout=300s | |
- name: get module controller pod available | |
run: | | |
kubectl wait --for=condition=available deployment/module-controller --timeout=300s | |
- name: apply moduledeployment batch release | |
run: | | |
kubectl apply -f config/samples/ci/module-deployment_v1alpha1_moduledeployment_batch_scaleup_then_scaledown_provider.yaml | |
- name: get moduledeployment | |
run: | | |
kubectl get moduledeployment | |
- name: get modulereplicaset | |
run: | | |
kubectl get modulereplicaset | |
- run: sleep 15 | |
- name: get module | |
run: | | |
kubectl get module -oyaml | |
- name: exist module | |
run: | | |
moduleCount=$(kubectl get module | wc -l) | |
if [[ $moduleCount -lt 1 ]]; then | |
echo "ERROR: 不存在module" | |
exit 1 | |
fi | |
- name: wait module available | |
run: | | |
# 定义要等待的资源名称和字段值 | |
modulename=$(kubectl get module -o name) | |
desired_field_value="Available" | |
# 定义等待的超时时间(以秒为单位) | |
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 $modulename -o custom-columns=STATUS:.status.status --no-headers) | |
if [ "$field_value" == "$desired_field_value" ]; then | |
echo "字段值已满足条件" | |
exit 0 | |
else | |
echo "等待字段值满足条件..." | |
sleep 5 # 等待一段时间后再次检查 | |
fi | |
done | |
- name: check moduledeployment pause | |
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 | |
- run: sleep 15 | |
- name: get module | |
run: | | |
kubectl get module | |
- name: exist module more then 1 | |
run: | | |
moduleCount=$(kubectl get module | wc -l) | |
echo $moduleCount | |
if [[ $moduleCount -lt 2 ]]; then | |
echo "ERROR: 未达到指定module数量" | |
exit 1 | |
fi | |
- name: get module | |
run: | | |
kubectl get module | |
- name: wait module available | |
run: | | |
# 定义要等待的资源类型和期望的字段值 | |
moduletype="module" | |
desired_field_value="Available" | |
# 定义等待的超时时间(以秒为单位) | |
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 | |
# 获取所有的资源对象名,并循环处理 | |
for modulename in $(kubectl get $moduletype -o name); do | |
# 使用 kubectl get 命令获取每个资源对象的详细信息,并提取自定义字段的值 | |
field_value=$(kubectl get $modulename -o custom-columns=STATUS:.status.status --no-headers) | |
# 检查字段值是否满足期望 | |
if [ "$field_value" != "$desired_field_value" ]; then | |
echo "等待字段值满足条件..." | |
sleep 5 # 等待一段时间后再次检查 | |
continue 2 # 如果字段值未满足,则跳出循环,进入下一轮等待 | |
fi | |
done | |
# 如果所有资源对象的字段值都满足期望,则结束脚本 | |
echo "字段值已满足条件" | |
exit 0 | |
done | |
- name: batch release successfully then check module install | |
run: | | |
label_selector="app=dynamic-stock" | |
max_attempts=10 | |
timeout=300 | |
interval=30 | |
for ((i=0; i<$max_attempts; i++)); do | |
echo "尝试 $((i+1))" | |
# 获取满足标签选择器条件的所有Pod | |
podnames=($(kubectl get pods -l $label_selector -o jsonpath='{.items[*].metadata.name}')) | |
totalcount=0 | |
# 遍历所有Pod进行日志检索 | |
for podname in "${podnames[@]}"; do | |
log_entry=$(kubectl exec -it $podname -- sh -c 'grep "Install Biz: provider:1.0.2 success" ~/logs/sofa-ark/*.log || true' 2>/dev/null) | |
echo "totalcount:$totalcount" | |
if [ -n "$log_entry" ]; then | |
totalcount=$((totalcount + 1)) | |
fi | |
done | |
if [ $totalcount -eq 2 ]; then | |
echo "所有Pod都满足条件。" | |
exit 0 | |
fi | |
# 如果这不是最后一次尝试,则等待一段时间后继续 | |
if [ $i -lt $((max_attempts-1)) ]; then | |
echo "有些Pod未满足条件。等待 $interval 秒后进行下一次尝试。" | |
sleep $interval | |
else | |
# 如果是最后一次尝试,则输出超时消息 | |
echo "已达到最大尝试次数。有些Pod未满足条件。" | |
exit 1 | |
fi | |
done | |
- name: random delete module then wait module available and delete base pod clean logs | |
run: | | |
resource_name=$(kubectl get module -o name | sort -R | head -n 1) | |
base_instance_name=$(kubectl get $resource_name -o jsonpath='{.metadata.labels.serverless\.alipay\.com/base-instance-name}') | |
echo "要删除的资源名称: $resource_name" | |
echo "base-instance-name 的值: $base_instance_name" | |
kubectl delete $resource_name | |
timeout_seconds=300 | |
start_time=$(date +%s) | |
end_time=$((start_time + timeout_seconds)) | |
while true; do | |
moduleCount=$(kubectl get $resource_name | wc -l) | |
current_time=$(date +%s) | |
if [ $current_time -gt $end_time ]; then | |
echo "等待超时" | |
exit 1 | |
fi | |
if [[ $moduleCount -lt 1 ]]; then | |
echo "module已缩容" | |
break | |
else | |
echo "等待module删除" | |
sleep 5 | |
fi | |
done | |
kubectl delete pod $base_instance_name | |
timeout_seconds=300 | |
start_time=$(date +%s) | |
end_time=$((start_time + timeout_seconds)) | |
while true; do | |
podcount=$(kubectl get pod $base_instance_name | wc -l) | |
current_time=$(date +%s) | |
if [ $current_time -gt $end_time ]; then | |
echo "等待超时" | |
exit 1 | |
fi | |
if [[ $podcount -lt 1 ]]; then | |
echo "pod已清理" | |
exit 0 | |
else | |
echo "等待pod删除" | |
sleep 5 | |
fi | |
done | |
- name: delete module then check exist module more then 1 | |
run: | | |
moduleCount=$(kubectl get module | wc -l) | |
echo $moduleCount | |
if [[ $moduleCount -lt 2 ]]; then | |
echo "ERROR: 未达到指定module数量" | |
exit 1 | |
fi | |
- name: get module | |
run: | | |
kubectl get module | |
- name: wait module available | |
run: | | |
# 定义要等待的资源类型和期望的字段值 | |
moduletype="module" | |
desired_field_value="Available" | |
# 定义等待的超时时间(以秒为单位) | |
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 | |
# 获取所有的资源对象名,并循环处理 | |
for modulename in $(kubectl get $moduletype -o name); do | |
# 使用 kubectl get 命令获取每个资源对象的详细信息,并提取自定义字段的值 | |
field_value=$(kubectl get $modulename -o custom-columns=STATUS:.status.status --no-headers) | |
# 检查字段值是否满足期望 | |
if [ "$field_value" != "$desired_field_value" ]; then | |
echo "等待字段值满足条件..." | |
sleep 5 # 等待一段时间后再次检查 | |
continue 2 # 如果字段值未满足,则跳出循环,进入下一轮等待 | |
fi | |
done | |
# 如果所有资源对象的字段值都满足期望,则结束脚本 | |
echo "字段值已满足条件" | |
exit 0 | |
done | |
- name: get pod | |
run: | | |
kubectl get pod -o yaml | |
- name: delete module then check module install | |
run: | | |
label_selector="app=dynamic-stock" | |
max_attempts=10 | |
timeout=300 | |
interval=30 | |
for ((i=0; i<$max_attempts; i++)); do | |
echo "尝试 $((i+1))" | |
# 获取满足标签选择器条件的所有Pod | |
podnames=($(kubectl get pods -l $label_selector -o jsonpath='{.items[*].metadata.name}')) | |
totalcount=0 | |
# 遍历所有Pod进行日志检索 | |
for podname in "${podnames[@]}"; do | |
log_entry=$(kubectl exec -it $podname -- sh -c 'grep "Install Biz: provider:1.0.2 success" ~/logs/sofa-ark/*.log || true' 2>/dev/null) | |
if [ -n "$log_entry" ]; then | |
totalcount=$((totalcount + 1)) | |
fi | |
echo "totalcount:$totalcount" | |
done | |
if [ $totalcount -eq 2 ]; then | |
echo "所有Pod都满足条件。" | |
exit 0 | |
fi | |
# 如果这不是最后一次尝试,则等待一段时间后继续 | |
if [ $i -lt $((max_attempts-1)) ]; then | |
echo "有些Pod未满足条件。等待 $interval 秒后进行下一次尝试。" | |
sleep $interval | |
else | |
# 如果是最后一次尝试,则输出超时消息 | |
echo "已达到最大尝试次数。有些Pod未满足条件。" | |
exit 1 | |
fi | |
done | |
- name: random delete pod | |
run: | | |
resource_name=$(kubectl get module -o name | sort -R | head -n 1) | |
base_instance_name=$(kubectl get $resource_name -o jsonpath='{.metadata.labels.serverless\.alipay\.com/base-instance-name}') | |
echo "要删除的资源名称: $resource_name" | |
echo "base-instance-name 的值: $base_instance_name" | |
kubectl delete pod $base_instance_name | |
timeout_seconds=300 | |
start_time=$(date +%s) | |
end_time=$((start_time + timeout_seconds)) | |
while true; do | |
moduleCount=$(kubectl get $resource_name | wc -l) | |
current_time=$(date +%s) | |
if [ $current_time -gt $end_time ]; then | |
echo "等待超时" | |
exit 1 | |
fi | |
if [[ $moduleCount -lt 1 ]]; then | |
echo "module已缩容" | |
break | |
else | |
echo "等待module删除" | |
sleep 5 | |
fi | |
done | |
timeout_seconds=300 | |
start_time=$(date +%s) | |
end_time=$((start_time + timeout_seconds)) | |
while true; do | |
podcount=$(kubectl get pod $base_instance_name | wc -l) | |
current_time=$(date +%s) | |
if [ $current_time -gt $end_time ]; then | |
echo "等待超时" | |
exit 1 | |
fi | |
if [[ $podcount -lt 1 ]]; then | |
echo "pod已清理" | |
exit 0 | |
else | |
echo "等待pod删除" | |
sleep 5 | |
fi | |
done | |
- name: wait base pod available | |
run: | | |
kubectl wait --for=condition=available deployment/dynamic-stock-deployment --timeout=300s | |
- name: delete pod then wait module available | |
run: | | |
# 定义要等待的资源类型和期望的字段值 | |
moduletype="module" | |
desired_field_value="Available" | |
# 定义等待的超时时间(以秒为单位) | |
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 | |
# 获取所有的资源对象名,并循环处理 | |
for modulename in $(kubectl get $moduletype -o name); do | |
# 使用 kubectl get 命令获取每个资源对象的详细信息,并提取自定义字段的值 | |
field_value=$(kubectl get $modulename -o custom-columns=STATUS:.status.status --no-headers) | |
# 检查字段值是否满足期望 | |
if [ "$field_value" != "$desired_field_value" ]; then | |
echo "等待字段值满足条件..." | |
sleep 5 # 等待一段时间后再次检查 | |
continue 2 # 如果字段值未满足,则跳出循环,进入下一轮等待 | |
fi | |
done | |
# 如果所有资源对象的字段值都满足期望,则结束脚本 | |
echo "字段值已满足条件" | |
exit 0 | |
done | |
- name: delete pod then check module install | |
run: | | |
label_selector="app=dynamic-stock" | |
max_attempts=10 | |
timeout=300 | |
interval=30 | |
for ((i=0; i<$max_attempts; i++)); do | |
echo "尝试 $((i+1))" | |
# 获取满足标签选择器条件的所有Pod | |
podnames=($(kubectl get pods -l $label_selector -o jsonpath='{.items[*].metadata.name}')) | |
totalcount=0 | |
# 遍历所有Pod进行日志检索 | |
for podname in "${podnames[@]}"; do | |
log_entry=$(kubectl exec -it $podname -- sh -c 'grep "Install Biz: provider:1.0.2 success" ~/logs/sofa-ark/*.log || true' 2>/dev/null) | |
if [ -n "$log_entry" ]; then | |
totalcount=$((totalcount + 1)) | |
fi | |
echo "totalcount:$totalcount" | |
done | |
if [ $totalcount -eq 2 ]; then | |
echo "所有Pod都满足条件。" | |
exit 0 | |
fi | |
# 如果这不是最后一次尝试,则等待一段时间后继续 | |
if [ $i -lt $((max_attempts-1)) ]; then | |
echo "有些Pod未满足条件。等待 $interval 秒后进行下一次尝试。" | |
sleep $interval | |
else | |
# 如果是最后一次尝试,则输出超时消息 | |
echo "已达到最大尝试次数。有些Pod未满足条件。" | |
exit 1 | |
fi | |
done | |
- name: batch scaledown | |
run: | | |
kubectl apply -f config/samples/ci/module-deployment_v1alpha1_moduledeployment_batch_scaledown_scaleup_then_scaledown_provider.yaml | |
- run: sleep 15 | |
- name: get module | |
run: | | |
kubectl get 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 | |
- run: sleep 15 | |
- name: exist module less then 1 | |
run: | | |
# 定义等待的超时时间(以秒为单位) | |
timeout_seconds=300 | |
start_time=$(date +%s) | |
end_time=$((start_time + timeout_seconds)) | |
while true; do | |
moduleCount=$(kubectl get module | wc -l) | |
current_time=$(date +%s) | |
kubectl get module | |
echo "moduleCount:$moduleCount" | |
if [ $current_time -gt $end_time ]; then | |
echo "等待超时" | |
exit 1 | |
fi | |
if [[ $moduleCount -lt 1 ]]; then | |
echo "缩容完成" | |
exit 0 | |
else | |
echo "等待字段值满足条件..." | |
sleep 5 # 等待一段时间后再次检查 | |
fi | |
done | |
- name: delete pod clean log | |
run: | | |
label_selector="app=dynamic-stock" | |
max_attempts=10 | |
timeout=300 | |
interval=30 | |
for ((i=0; i<$max_attempts; i++)); do | |
podnames=($(kubectl get pods -l $label_selector -o jsonpath='{.items[*].metadata.name}')) | |
for podname in "${podnames[@]}"; do | |
kubectl delete pod -n default $podname | |
timeout_seconds=300 | |
start_time=$(date +%s) | |
end_time=$((start_time + timeout_seconds)) | |
while true; do | |
podcount=$(kubectl get pod $podname | wc -l) | |
echo "podcount:$podcount" | |
current_time=$(date +%s) | |
if [ $current_time -gt $end_time ]; then | |
echo "等待超时" | |
exit 1 | |
fi | |
if [ $podcount -lt 1 ]; then | |
echo "所有pod已清理" | |
break | |
else | |
echo "等待pod删除" | |
sleep $interval | |
fi | |
done | |
done | |
done | |
- name: clean pod then wait base pod available | |
run: | | |
kubectl wait --for=condition=available deployment/dynamic-stock-deployment --timeout=300s | |
- name: batch scaleup | |
run: | | |
kubectl apply -f config/samples/ci/module-deployment_v1alpha1_moduledeployment_batch_scaleup_then_scaledown_provider.yaml | |
- name: get module | |
run: | | |
kubectl get module | |
- name: exist module more then 1 | |
run: | | |
moduleCount=$(kubectl get module | wc -l) | |
echo $moduleCount | |
if [[ $moduleCount -lt 1 ]]; then | |
echo "ERROR: 未达到指定module数量" | |
exit 1 | |
fi | |
- name: batch scaleup then wait module available | |
run: | | |
# 定义要等待的资源类型和期望的字段值 | |
moduletype="module" | |
desired_field_value="Available" | |
# 定义等待的超时时间(以秒为单位) | |
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 | |
# 获取所有的资源对象名,并循环处理 | |
for modulename in $(kubectl get $moduletype -o name); do | |
# 使用 kubectl get 命令获取每个资源对象的详细信息,并提取自定义字段的值 | |
field_value=$(kubectl get $modulename -o custom-columns=STATUS:.status.status --no-headers) | |
# 检查字段值是否满足期望 | |
if [ "$field_value" != "$desired_field_value" ]; then | |
echo "等待字段值满足条件..." | |
sleep 5 # 等待一段时间后再次检查 | |
continue 2 # 如果字段值未满足,则跳出循环,进入下一轮等待 | |
fi | |
done | |
# 如果所有资源对象的字段值都满足期望,则结束脚本 | |
echo "字段值已满足条件" | |
exit 0 | |
done | |
- name: check moduledeployment pause | |
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 | |
- run: sleep 15 | |
- name: get module | |
run: | | |
kubectl get module | |
- name: exist module more then 1 | |
run: | | |
moduleCount=$(kubectl get module | wc -l) | |
echo $moduleCount | |
if [[ $moduleCount -lt 2 ]]; then | |
echo "ERROR: 未达到指定module数量" | |
exit 1 | |
fi | |
- name: get module | |
run: | | |
kubectl get module | |
- name: batch scaleup then wait module available | |
run: | | |
# 定义要等待的资源类型和期望的字段值 | |
moduletype="module" | |
desired_field_value="Available" | |
# 定义等待的超时时间(以秒为单位) | |
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 | |
# 获取所有的资源对象名,并循环处理 | |
for modulename in $(kubectl get $moduletype -o name); do | |
# 使用 kubectl get 命令获取每个资源对象的详细信息,并提取自定义字段的值 | |
field_value=$(kubectl get $modulename -o custom-columns=STATUS:.status.status --no-headers) | |
# 检查字段值是否满足期望 | |
if [ "$field_value" != "$desired_field_value" ]; then | |
echo "等待字段值满足条件..." | |
sleep 5 # 等待一段时间后再次检查 | |
continue 2 # 如果字段值未满足,则跳出循环,进入下一轮等待 | |
fi | |
done | |
# 如果所有资源对象的字段值都满足期望,则结束脚本 | |
echo "字段值已满足条件" | |
exit 0 | |
done | |
- name: batch scaleup successfully then check module install | |
run: | | |
label_selector="app=dynamic-stock" | |
max_attempts=10 | |
timeout=300 | |
interval=30 | |
for ((i=0; i<$max_attempts; i++)); do | |
echo "尝试 $((i+1))" | |
# 获取满足标签选择器条件的所有Pod | |
podnames=($(kubectl get pods -l $label_selector -o jsonpath='{.items[*].metadata.name}')) | |
totalcount=0 | |
# 遍历所有Pod进行日志检索 | |
for podname in "${podnames[@]}"; do | |
log_entry=$(kubectl exec -it $podname -- sh -c 'grep "Install Biz: provider:1.0.2 success" ~/logs/sofa-ark/*.log || true' 2>/dev/null) | |
if [ -n "$log_entry" ]; then | |
totalcount=$((totalcount + 1)) | |
fi | |
echo "totalcount:$totalcount" | |
done | |
if [ $totalcount -eq 2 ]; then | |
echo "所有Pod都满足条件。" | |
exit 0 | |
fi | |
# 如果这不是最后一次尝试,则等待一段时间后继续 | |
if [ $i -lt $((max_attempts-1)) ]; then | |
echo "有些Pod未满足条件。等待 $interval 秒后进行下一次尝试。" | |
sleep $interval | |
else | |
# 如果是最后一次尝试,则输出超时消息 | |
echo "已达到最大尝试次数。有些Pod未满足条件。" | |
exit 1 | |
fi | |
done |