From 2255b0a6c7bb1046c13fe8d3e97906d505ad6d2f Mon Sep 17 00:00:00 2001 From: barnettZQG Date: Mon, 24 Oct 2022 19:32:45 +0800 Subject: [PATCH] Feat: Refer to the generation when checking the application status (#4901) * Feat: Refer to the generation when checking the application status Signed-off-by: barnettZQG * Fix: add the test Signed-off-by: barnettZQG * Fix: the starting status overrided the deleting status Signed-off-by: barnettZQG Signed-off-by: barnettZQG --- pkg/apiserver/domain/service/application.go | 5 +++- .../domain/service/application_test.go | 5 ++++ references/cli/addon.go | 24 ++++++++++++------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/apiserver/domain/service/application.go b/pkg/apiserver/domain/service/application.go index 4183b2a7b..a8222cbd5 100644 --- a/pkg/apiserver/domain/service/application.go +++ b/pkg/apiserver/domain/service/application.go @@ -291,8 +291,11 @@ func (c *applicationServiceImpl) GetApplicationStatus(ctx context.Context, appmo } return nil, err } + if app.Generation > app.Status.ObservedGeneration { + app.Status.Phase = common.ApplicationStarting + } if !app.DeletionTimestamp.IsZero() { - app.Status.Phase = "deleting" + app.Status.Phase = common.ApplicationDeleting } return &app.Status, nil } diff --git a/pkg/apiserver/domain/service/application_test.go b/pkg/apiserver/domain/service/application_test.go index 2b5161c2e..fdb59d1ba 100644 --- a/pkg/apiserver/domain/service/application_test.go +++ b/pkg/apiserver/domain/service/application_test.go @@ -442,6 +442,11 @@ var _ = Describe("Test application service function", func() { Expect(err).Should(BeNil()) Expect(revision.DeployUser.Name).Should(Equal(model.DefaultAdminUserName)) Expect(revision.DeployUser.Alias).Should(Equal(model.DefaultAdminUserAlias)) + + appStats, err := appService.GetApplicationStatus(context.TODO(), appModel, "app-dev") + Expect(err).Should(BeNil()) + Expect(appStats.Phase).Should(Equal(common.ApplicationStarting)) + err = envBindingService.ApplicationEnvRecycle(context.TODO(), &model.Application{ Name: testApp, }, &model.EnvBinding{Name: "app-dev"}) diff --git a/references/cli/addon.go b/references/cli/addon.go index ea29ae145..c364af331 100644 --- a/references/cli/addon.go +++ b/references/cli/addon.go @@ -995,17 +995,23 @@ func waitApplicationRunning(k8sClient client.Client, addonName string) error { if err != nil { return client.IgnoreNotFound(err) } + phase := app.Status.Phase - switch app.Status.Phase { - case common2.ApplicationRunning: - return nil - case common2.ApplicationWorkflowSuspending: - fmt.Printf("Enabling suspend, please run \"vela workflow resume %s -n vela-system\" to continue", addonutil.Addon2AppName(addonName)) - return nil - case common2.ApplicationWorkflowTerminated, common2.ApplicationWorkflowFailed: - return errors.Errorf("Enabling failed, please run \"vela status %s -n vela-system\" to check the status of the addon", addonutil.Addon2AppName(addonName)) - default: + if app.Generation > app.Status.ObservedGeneration { + phase = common2.ApplicationStarting + } else { + switch app.Status.Phase { + case common2.ApplicationRunning: + return nil + case common2.ApplicationWorkflowSuspending: + fmt.Printf("Enabling suspend, please run \"vela workflow resume %s -n vela-system\" to continue", addonutil.Addon2AppName(addonName)) + return nil + case common2.ApplicationWorkflowTerminated, common2.ApplicationWorkflowFailed: + return errors.Errorf("Enabling failed, please run \"vela status %s -n vela-system\" to check the status of the addon", addonutil.Addon2AppName(addonName)) + default: + } } + timeConsumed := int(time.Since(start).Seconds()) applySpinnerNewSuffix(spinner, fmt.Sprintf("Waiting addon application running. It is now in phase: %s (timeout %d/%d seconds)...", phase, timeConsumed, int(timeout.Seconds())))