From 083dc6d6e3e5be40306153c79c9b646c884eb908 Mon Sep 17 00:00:00 2001 From: LiuLiqi <837397251@qq.com> Date: Mon, 18 Dec 2023 15:58:57 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0confirm=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E6=8C=87=E5=AE=9A=E5=88=86=E6=89=B9=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E8=AF=81=E5=B9=82=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1alpha1/moduledeployment_types.go | 3 +++ .../serverless.alipay.com_moduledeployments.yaml | 4 ++++ .../controller/moduledeployment_controller.go | 12 +++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/module-controller/api/v1alpha1/moduledeployment_types.go b/module-controller/api/v1alpha1/moduledeployment_types.go index f47b0237f..eb6f202ae 100644 --- a/module-controller/api/v1alpha1/moduledeployment_types.go +++ b/module-controller/api/v1alpha1/moduledeployment_types.go @@ -171,6 +171,9 @@ type ModuleDeploymentSpec struct { OperationStrategy ModuleOperationStrategy `json:"operationStrategy,omitempty"` SchedulingStrategy ModuleSchedulingStrategy `json:"schedulingStrategy,omitempty"` + + // +kubebuilder:validation:Minimum=0 + CurrentGroupConfirmation int32 `json:"currentGroupConfirmation,omitempty"` } // ModuleDeploymentStatus defines the observed state of ModuleDeployment diff --git a/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml b/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml index 1fe788c00..ce9ed0e0a 100644 --- a/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml +++ b/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml @@ -41,6 +41,10 @@ spec: Important: Run "make" to regenerate code after modifying this file' minLength: 1 type: string + currentGroupConfirmation: + format: int32 + minimum: 0 + type: integer minReadySeconds: format: int32 type: integer diff --git a/module-controller/internal/controller/moduledeployment_controller.go b/module-controller/internal/controller/moduledeployment_controller.go index 9361768cb..9a8f1d4f1 100644 --- a/module-controller/internal/controller/moduledeployment_controller.go +++ b/module-controller/internal/controller/moduledeployment_controller.go @@ -152,6 +152,14 @@ func (r *ModuleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{}, err } } + + if moduleDeployment.Spec.CurrentGroupConfirmation > 0 { + moduleDeployment.Spec.CurrentGroupConfirmation = 0 + if err := utils.UpdateResource(r.Client, ctx, moduleDeployment); err != nil { + return ctrl.Result{}, err + } + } + case v1alpha1.ModuleDeploymentReleaseProgressWaitingForConfirmation: moduleDeployment.Spec.Pause = true if err := r.Update(ctx, moduleDeployment); err != nil { @@ -164,7 +172,9 @@ func (r *ModuleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{}, utils.Error(err, "update moduleDeployment releaseStatus progress to paused failed") } case v1alpha1.ModuleDeploymentReleaseProgressPaused: - if !moduleDeployment.Spec.Pause && time.Since(moduleDeployment.Status.ReleaseStatus.NextReconcileTime.Time) >= 0 { + if !moduleDeployment.Spec.Pause && time.Since(moduleDeployment.Status.ReleaseStatus.NextReconcileTime.Time) >= 0 && + moduleDeployment.Spec.CurrentGroupConfirmation == moduleDeployment.Status.ReleaseStatus.CurrentBatch-1 { + moduleDeployment.Status.ReleaseStatus.Progress = v1alpha1.ModuleDeploymentReleaseProgressExecuting log.Log.Info("update moduleDeployment progress from paused to executing", "moduleDeploymentName", moduleDeployment.Name) if err := utils.UpdateStatus(r.Client, ctx, moduleDeployment); err != nil { From db18705a6063cc278f872c1a9d2eb04d9d14e4e0 Mon Sep 17 00:00:00 2001 From: LiuLiqi <837397251@qq.com> Date: Tue, 19 Dec 2023 15:54:33 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0confirm=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E6=8C=87=E5=AE=9A=E5=88=86=E6=89=B9=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E8=AF=81=E5=B9=82=E7=AD=89=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4pause=E7=A1=AE=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1alpha1/moduledeployment_types.go | 9 ++--- ...rverless.alipay.com_moduledeployments.yaml | 6 +--- .../controller/moduledeployment_controller.go | 19 +++++----- ...controller_operation_strategy_suit_test.go | 35 +++++++++++++++---- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/module-controller/api/v1alpha1/moduledeployment_types.go b/module-controller/api/v1alpha1/moduledeployment_types.go index eb6f202ae..5ef511b70 100644 --- a/module-controller/api/v1alpha1/moduledeployment_types.go +++ b/module-controller/api/v1alpha1/moduledeployment_types.go @@ -163,17 +163,12 @@ type ModuleDeploymentSpec struct { ProgressDeadlineSeconds int32 `json:"progressDeadlineSeconds,omitempty"` - // Indicates that the moduleDeployment is paused and will not be processed by the - // moduleDeployment controller. - // +optional - Pause bool `json:"pause,omitempty"` + // +kubebuilder:validation:Minimum=0 + ConfirmBatchNum int32 `json:"confirmBatchNum,omitempty"` OperationStrategy ModuleOperationStrategy `json:"operationStrategy,omitempty"` SchedulingStrategy ModuleSchedulingStrategy `json:"schedulingStrategy,omitempty"` - - // +kubebuilder:validation:Minimum=0 - CurrentGroupConfirmation int32 `json:"currentGroupConfirmation,omitempty"` } // ModuleDeploymentStatus defines the observed state of ModuleDeployment diff --git a/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml b/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml index ce9ed0e0a..baa2324af 100644 --- a/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml +++ b/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml @@ -41,7 +41,7 @@ spec: Important: Run "make" to regenerate code after modifying this file' minLength: 1 type: string - currentGroupConfirmation: + confirmBatchNum: format: int32 minimum: 0 type: integer @@ -79,10 +79,6 @@ spec: useBeta: type: boolean type: object - pause: - description: Indicates that the moduleDeployment is paused and will - not be processed by the moduleDeployment controller. - type: boolean progressDeadlineSeconds: format: int32 type: integer diff --git a/module-controller/internal/controller/moduledeployment_controller.go b/module-controller/internal/controller/moduledeployment_controller.go index 9a8f1d4f1..29bd51156 100644 --- a/module-controller/internal/controller/moduledeployment_controller.go +++ b/module-controller/internal/controller/moduledeployment_controller.go @@ -97,7 +97,10 @@ func (r *ModuleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req event.PublishModuleDeploymentCreateEvent(r.Client, ctx, moduleDeployment) } - if moduleDeployment.Spec.Pause { + if moduleDeployment.Status.ReleaseStatus != nil && + moduleDeployment.Spec.ConfirmBatchNum < moduleDeployment.Status.ReleaseStatus.CurrentBatch && + moduleDeployment.Status.ReleaseStatus.Progress == v1alpha1.ModuleDeploymentReleaseProgressPaused { + return ctrl.Result{}, nil } @@ -153,18 +156,14 @@ func (r *ModuleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req } } - if moduleDeployment.Spec.CurrentGroupConfirmation > 0 { - moduleDeployment.Spec.CurrentGroupConfirmation = 0 + if moduleDeployment.Spec.ConfirmBatchNum > 0 { + moduleDeployment.Spec.ConfirmBatchNum = 0 if err := utils.UpdateResource(r.Client, ctx, moduleDeployment); err != nil { return ctrl.Result{}, err } } case v1alpha1.ModuleDeploymentReleaseProgressWaitingForConfirmation: - moduleDeployment.Spec.Pause = true - if err := r.Update(ctx, moduleDeployment); err != nil { - return ctrl.Result{}, err - } moduleDeployment.Status.ReleaseStatus.Progress = v1alpha1.ModuleDeploymentReleaseProgressPaused log.Log.Info("update moduleDeployment releaseStatus progress to paused", "moduleDeploymentName", moduleDeployment.Name) @@ -172,9 +171,10 @@ func (r *ModuleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{}, utils.Error(err, "update moduleDeployment releaseStatus progress to paused failed") } case v1alpha1.ModuleDeploymentReleaseProgressPaused: - if !moduleDeployment.Spec.Pause && time.Since(moduleDeployment.Status.ReleaseStatus.NextReconcileTime.Time) >= 0 && - moduleDeployment.Spec.CurrentGroupConfirmation == moduleDeployment.Status.ReleaseStatus.CurrentBatch-1 { + if time.Since(moduleDeployment.Status.ReleaseStatus.NextReconcileTime.Time) >= 0 && + moduleDeployment.Spec.ConfirmBatchNum == moduleDeployment.Status.ReleaseStatus.CurrentBatch { + moduleDeployment.Status.ReleaseStatus.CurrentBatch += 1 moduleDeployment.Status.ReleaseStatus.Progress = v1alpha1.ModuleDeploymentReleaseProgressExecuting log.Log.Info("update moduleDeployment progress from paused to executing", "moduleDeploymentName", moduleDeployment.Name) if err := utils.UpdateStatus(r.Client, ctx, moduleDeployment); err != nil { @@ -462,7 +462,6 @@ func (r *ModuleDeploymentReconciler) updateModuleReplicaSet(ctx context.Context, } } // TODO update current batch - moduleDeployment.Status.ReleaseStatus.CurrentBatch += 1 moduleDeployment.Status.ReleaseStatus.BatchProgress = v1alpha1.ModuleDeploymentReleaseProgressExecuting log.Log.Info("update moduleDeployment batch progress to executing", "moduleDeploymentName", moduleDeployment.Name) err = utils.UpdateStatus(r.Client, ctx, moduleDeployment) diff --git a/module-controller/internal/controller/moduledeployment_controller_operation_strategy_suit_test.go b/module-controller/internal/controller/moduledeployment_controller_operation_strategy_suit_test.go index 886127daf..6c8121a9b 100644 --- a/module-controller/internal/controller/moduledeployment_controller_operation_strategy_suit_test.go +++ b/module-controller/internal/controller/moduledeployment_controller_operation_strategy_suit_test.go @@ -216,7 +216,7 @@ var _ = Describe("ModuleDeployment Controller OperationStrategy Test", func() { return err } - if !moduleDeployment.Spec.Pause { + if moduleDeployment.Spec.ConfirmBatchNum != 0 { return fmt.Errorf("the deployment is not paused") } @@ -231,18 +231,22 @@ var _ = Describe("ModuleDeployment Controller OperationStrategy Test", func() { Eventually(func() bool { Expect(k8sClient.Get(context.TODO(), nn, &moduleDeployment)).Should(Succeed()) - moduleDeployment.Spec.Pause = false + moduleDeployment.Spec.ConfirmBatchNum = 1 return Expect(k8sClient.Update(context.TODO(), &moduleDeployment)).Should(Succeed()) }, timeout, interval).Should(BeTrue()) }) + It("wait moduleDeployment Completed", func() { + waitModuleDeploymentCompleted(moduleDeploymentName, namespace) + }) + It("4. check if the moduleDeployment status is completed", func() { Eventually(func() bool { if k8sClient.Get(context.TODO(), nn, &moduleDeployment) != nil { return false } - if moduleDeployment.Spec.Pause != false { + if moduleDeployment.Spec.ConfirmBatchNum != 0 { return false } @@ -266,7 +270,7 @@ var _ = Describe("ModuleDeployment Controller OperationStrategy Test", func() { return err } - if !moduleDeployment.Spec.Pause { + if moduleDeployment.Spec.ConfirmBatchNum != 0 { return fmt.Errorf("the deployment is not paused") } @@ -281,18 +285,22 @@ var _ = Describe("ModuleDeployment Controller OperationStrategy Test", func() { Eventually(func() bool { Expect(k8sClient.Get(context.TODO(), nn, &moduleDeployment)).Should(Succeed()) - moduleDeployment.Spec.Pause = false + moduleDeployment.Spec.ConfirmBatchNum = 1 return Expect(k8sClient.Update(context.TODO(), &moduleDeployment)).Should(Succeed()) }, timeout, interval).Should(BeTrue()) }) + It("wait moduleDeployment Completed", func() { + waitModuleDeploymentTerminated(moduleDeploymentName, namespace) + }) + It("9. check if the moduleDeployment status is Terminated", func() { Eventually(func() error { if err := k8sClient.Get(context.TODO(), nn, &moduleDeployment); err != nil { return err } - if moduleDeployment.Spec.Pause != false { + if moduleDeployment.Spec.ConfirmBatchNum != 1 { return fmt.Errorf("the module-deployment is paused") } @@ -431,3 +439,18 @@ func waitModuleDeploymentCompleted(moduleDeploymentName string, namespace string time.Sleep(5 * time.Second) waitModuleDeploymentCompleted(moduleDeploymentName, namespace) } + +func waitModuleDeploymentTerminated(moduleDeploymentName string, namespace string) { + key := types.NamespacedName{ + Name: moduleDeploymentName, + Namespace: namespace, + } + newModuleDeployment := &v1alpha1.ModuleDeployment{} + Expect(k8sClient.Get(context.TODO(), key, newModuleDeployment)).Should(Succeed()) + progress := newModuleDeployment.Status.ReleaseStatus.Progress + if progress == v1alpha1.ModuleDeploymentReleaseProgressTerminated { + return + } + time.Sleep(5 * time.Second) + waitModuleDeploymentTerminated(moduleDeploymentName, namespace) +} From aed700c49aad15a2356572510389e11f1414a87a Mon Sep 17 00:00:00 2001 From: LiuLiqi <837397251@qq.com> Date: Tue, 19 Dec 2023 16:07:53 +0800 Subject: [PATCH 3/5] =?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 | 42 ++++++++----------- ...caleup_then_scaledown_deploy_to_aliyun.yml | 21 ++++------ 2 files changed, 27 insertions(+), 36 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 2fb63e0ae..03dd7778f 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 @@ -167,7 +167,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -183,11 +182,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 else echo "等待字段值满足条件..." @@ -213,7 +212,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -229,11 +227,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "1" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":2}}' --type=merge exit 0 else echo "等待字段值满足条件..." @@ -353,7 +351,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -369,11 +366,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 else echo "等待字段值满足条件..." @@ -400,7 +397,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -416,11 +412,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "1" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":2}}' --type=merge exit 0 else echo "等待字段值满足条件..." @@ -496,7 +492,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -512,11 +507,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 else echo "等待字段值满足条件..." @@ -579,7 +574,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -595,11 +589,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "1" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":2}}' --type=merge exit 0 else echo "等待字段值满足条件..." diff --git a/.github/workflows/module_controller_ci_build_batch_scaleup_then_scaledown_deploy_to_aliyun.yml b/.github/workflows/module_controller_ci_build_batch_scaleup_then_scaledown_deploy_to_aliyun.yml index c8cc1b711..3e00b2e54 100644 --- a/.github/workflows/module_controller_ci_build_batch_scaleup_then_scaledown_deploy_to_aliyun.yml +++ b/.github/workflows/module_controller_ci_build_batch_scaleup_then_scaledown_deploy_to_aliyun.yml @@ -167,7 +167,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -183,11 +182,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 else echo "等待字段值满足条件..." @@ -579,7 +578,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -595,11 +593,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 else echo "等待字段值满足条件..." @@ -738,7 +736,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -754,11 +751,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 else echo "等待字段值满足条件..." From 853771823595f0642c2e37143de8e45d313cd85e Mon Sep 17 00:00:00 2001 From: LiuLiqi <837397251@qq.com> Date: Wed, 17 Jan 2024 13:42:52 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=95=E6=B5=8B?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0ConfirmBatchNum=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=E4=B8=BA0=E7=9A=84=E6=B3=A8=E9=87=8A=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E4=B8=BA0=E6=97=B6=E4=B9=9F=E5=9C=A8yaml?= =?UTF-8?q?=E4=B8=AD=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1alpha1/moduledeployment_types.go | 1 + .../serverless.alipay.com_moduledeployments.yaml | 1 + ...nt_controller_operation_strategy_suit_test.go | 16 ++++++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/module-controller/api/v1alpha1/moduledeployment_types.go b/module-controller/api/v1alpha1/moduledeployment_types.go index 5ef511b70..afe5e91e4 100644 --- a/module-controller/api/v1alpha1/moduledeployment_types.go +++ b/module-controller/api/v1alpha1/moduledeployment_types.go @@ -163,6 +163,7 @@ type ModuleDeploymentSpec struct { ProgressDeadlineSeconds int32 `json:"progressDeadlineSeconds,omitempty"` + // +kubebuilder:default:=0 // +kubebuilder:validation:Minimum=0 ConfirmBatchNum int32 `json:"confirmBatchNum,omitempty"` diff --git a/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml b/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml index baa2324af..78f4e4af9 100644 --- a/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml +++ b/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml @@ -42,6 +42,7 @@ spec: minLength: 1 type: string confirmBatchNum: + default: 0 format: int32 minimum: 0 type: integer diff --git a/module-controller/internal/controller/moduledeployment_controller_operation_strategy_suit_test.go b/module-controller/internal/controller/moduledeployment_controller_operation_strategy_suit_test.go index 2f2aad225..e9171b3f1 100644 --- a/module-controller/internal/controller/moduledeployment_controller_operation_strategy_suit_test.go +++ b/module-controller/internal/controller/moduledeployment_controller_operation_strategy_suit_test.go @@ -578,7 +578,7 @@ var _ = Describe("ModuleDeployment Controller OperationStrategy Test", func() { return err } - if !moduleDeployment.Spec.Pause { + if moduleDeployment.Spec.ConfirmBatchNum > 0 { return fmt.Errorf("the deployment is not paused") } @@ -593,18 +593,22 @@ var _ = Describe("ModuleDeployment Controller OperationStrategy Test", func() { Eventually(func() bool { Expect(k8sClient.Get(context.TODO(), nn, &moduleDeployment)).Should(Succeed()) - moduleDeployment.Spec.Pause = false + moduleDeployment.Spec.ConfirmBatchNum = 1 return Expect(k8sClient.Update(context.TODO(), &moduleDeployment)).Should(Succeed()) }, timeout, interval).Should(BeTrue()) }) + It("wait moduleDeployment Completed", func() { + waitModuleDeploymentCompleted(moduleDeploymentName, namespace) + }) + It("4. check if the moduleDeployment status is completed", func() { Eventually(func() bool { if k8sClient.Get(context.TODO(), nn, &moduleDeployment) != nil { return false } - if moduleDeployment.Spec.Pause != false { + if moduleDeployment.Spec.ConfirmBatchNum != 0 { return false } @@ -627,7 +631,7 @@ var _ = Describe("ModuleDeployment Controller OperationStrategy Test", func() { return err } - if !moduleDeployment.Spec.Pause { + if moduleDeployment.Spec.ConfirmBatchNum > 0 { return fmt.Errorf("the deployment is not paused") } @@ -642,7 +646,7 @@ var _ = Describe("ModuleDeployment Controller OperationStrategy Test", func() { Eventually(func() bool { Expect(k8sClient.Get(context.TODO(), nn, &moduleDeployment)).Should(Succeed()) - moduleDeployment.Spec.Pause = false + moduleDeployment.Spec.ConfirmBatchNum = 1 return Expect(k8sClient.Update(context.TODO(), &moduleDeployment)).Should(Succeed()) }, timeout, interval).Should(BeTrue()) }) @@ -653,7 +657,7 @@ var _ = Describe("ModuleDeployment Controller OperationStrategy Test", func() { return err } - if moduleDeployment.Spec.Pause != false { + if moduleDeployment.Spec.ConfirmBatchNum != 1 { return fmt.Errorf("the module-deployment is paused") } From 302fde178f8671cb749097a1b4abf5a7719f8614 Mon Sep 17 00:00:00 2001 From: LiuLiqi <837397251@qq.com> Date: Wed, 17 Jan 2024 16:39:23 +0800 Subject: [PATCH 5/5] ci test fix --- ..._controller_ci_build_batch_deploy_to_aliyun.yml | 6 +++--- ...tch_scaleup_then_scaledown_deploy_to_aliyun.yml | 6 +++--- ...r_ci_build_batch_symmetric_deploy_to_aliyun.yml | 14 ++++++-------- 3 files changed, 12 insertions(+), 14 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 03dd7778f..8f0cb7d87 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 @@ -184,7 +184,7 @@ jobs: # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "" ]; then + if [ "$field_value" == "0" ]; then echo "字段值已满足条件,执行分组确认" kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 @@ -368,7 +368,7 @@ jobs: # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "" ]; then + if [ "$field_value" == "0" ]; then echo "字段值已满足条件,执行分组确认" kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 @@ -509,7 +509,7 @@ jobs: # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "" ]; then + if [ "$field_value" == "0" ]; then echo "字段值已满足条件,执行分组确认" kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 diff --git a/.github/workflows/module_controller_ci_build_batch_scaleup_then_scaledown_deploy_to_aliyun.yml b/.github/workflows/module_controller_ci_build_batch_scaleup_then_scaledown_deploy_to_aliyun.yml index 3e00b2e54..7dfad5f87 100644 --- a/.github/workflows/module_controller_ci_build_batch_scaleup_then_scaledown_deploy_to_aliyun.yml +++ b/.github/workflows/module_controller_ci_build_batch_scaleup_then_scaledown_deploy_to_aliyun.yml @@ -184,7 +184,7 @@ jobs: # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "" ]; then + if [ "$field_value" == "0" ]; then echo "字段值已满足条件,执行分组确认" kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 @@ -595,7 +595,7 @@ jobs: # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "" ]; then + if [ "$field_value" == "0" ]; then echo "字段值已满足条件,执行分组确认" kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 @@ -753,7 +753,7 @@ jobs: # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "" ]; then + if [ "$field_value" == "0" ]; then echo "字段值已满足条件,执行分组确认" kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 diff --git a/.github/workflows/module_controller_ci_build_batch_symmetric_deploy_to_aliyun.yml b/.github/workflows/module_controller_ci_build_batch_symmetric_deploy_to_aliyun.yml index 3a831315f..af3f184f3 100644 --- a/.github/workflows/module_controller_ci_build_batch_symmetric_deploy_to_aliyun.yml +++ b/.github/workflows/module_controller_ci_build_batch_symmetric_deploy_to_aliyun.yml @@ -167,7 +167,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -183,11 +182,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "0" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":1}}' --type=merge exit 0 else echo "等待字段值满足条件..." @@ -213,7 +212,6 @@ jobs: run: | # 定义要等待的资源名称和字段值 moduledeploymentname=$(kubectl get moduledeployment -o name) - desired_field_value=true # 定义等待的超时时间(以秒为单位) timeout_seconds=300 @@ -229,11 +227,11 @@ jobs: fi # 使用 kubectl get 命令获取资源对象的详细信息,并提取自定义字段的值 - field_value=$(kubectl get $moduledeploymentname -o custom-columns=PAUSE:.spec.pause --no-headers) + field_value=$(kubectl get $moduledeploymentname -o custom-columns=CONFIRMBATCHNUM:.spec.confirmBatchNum --no-headers) - if [ "$field_value" == "$desired_field_value" ]; then + if [ "$field_value" == "1" ]; then echo "字段值已满足条件,执行分组确认" - kubectl patch $moduledeploymentname -p '{"spec":{"pause":false}}' --type=merge + kubectl patch $moduledeploymentname -p '{"spec":{"confirmBatchNum":2}}' --type=merge exit 0 else echo "等待字段值满足条件..."