From c3ae3fedf347efd82aae9a415e78daaded46dafd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:02:55 +0800 Subject: [PATCH] [Backport release-1.8] Feat: add mode in steps for step group (#5802) Co-authored-by: FogDong --- .../core.oam.dev_applicationrevisions.yaml | 10 ++ .../crds/core.oam.dev_applications.yaml | 5 + .../core.oam.dev_applicationrevisions.yaml | 10 ++ .../crds/core.oam.dev_applications.yaml | 5 + go.mod | 2 +- go.sum | 4 +- .../core.oam.dev_applicationrevisions.yaml | 10 ++ .../crds/core.oam.dev_applications.yaml | 5 + .../application_controller_test.go | 105 ++++++++++++++++++ 9 files changed, 153 insertions(+), 3 deletions(-) diff --git a/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml b/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml index f92692936..f6af7a0a6 100644 --- a/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml +++ b/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml @@ -2306,6 +2306,11 @@ spec: alias: type: string type: object + mode: + description: Mode is only valid for sub steps, it + defines the mode of the sub steps + nullable: true + type: string name: description: Name is the unique name of the workflow step. @@ -4168,6 +4173,11 @@ spec: alias: type: string type: object + mode: + description: Mode is only valid for sub steps, it defines + the mode of the sub steps + nullable: true + type: string name: description: Name is the unique name of the workflow step. type: string diff --git a/charts/vela-core/crds/core.oam.dev_applications.yaml b/charts/vela-core/crds/core.oam.dev_applications.yaml index 55c06a97f..a75d24075 100644 --- a/charts/vela-core/crds/core.oam.dev_applications.yaml +++ b/charts/vela-core/crds/core.oam.dev_applications.yaml @@ -1068,6 +1068,11 @@ spec: alias: type: string type: object + mode: + description: Mode is only valid for sub steps, it defines + the mode of the sub steps + nullable: true + type: string name: description: Name is the unique name of the workflow step. type: string diff --git a/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml b/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml index f92692936..f6af7a0a6 100644 --- a/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_applicationrevisions.yaml @@ -2306,6 +2306,11 @@ spec: alias: type: string type: object + mode: + description: Mode is only valid for sub steps, it + defines the mode of the sub steps + nullable: true + type: string name: description: Name is the unique name of the workflow step. @@ -4168,6 +4173,11 @@ spec: alias: type: string type: object + mode: + description: Mode is only valid for sub steps, it defines + the mode of the sub steps + nullable: true + type: string name: description: Name is the unique name of the workflow step. type: string diff --git a/charts/vela-minimal/crds/core.oam.dev_applications.yaml b/charts/vela-minimal/crds/core.oam.dev_applications.yaml index 55c06a97f..a75d24075 100644 --- a/charts/vela-minimal/crds/core.oam.dev_applications.yaml +++ b/charts/vela-minimal/crds/core.oam.dev_applications.yaml @@ -1068,6 +1068,11 @@ spec: alias: type: string type: object + mode: + description: Mode is only valid for sub steps, it defines + the mode of the sub steps + nullable: true + type: string name: description: Name is the unique name of the workflow step. type: string diff --git a/go.mod b/go.mod index 2e219bc77..d1a420c0c 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,7 @@ require ( github.com/imdario/mergo v0.3.13 github.com/kubevela/pkg v0.0.0-20230316114047-e2b41b377bac github.com/kubevela/prism v1.7.0-alpha.1 - github.com/kubevela/workflow v0.5.0 + github.com/kubevela/workflow v0.5.1-0.20230404061444-a4f3ec81fca7 github.com/kyokomi/emoji v2.2.4+incompatible github.com/mitchellh/hashstructure/v2 v2.0.2 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/go.sum b/go.sum index 5b4588ee7..615777b07 100644 --- a/go.sum +++ b/go.sum @@ -954,8 +954,8 @@ github.com/kubevela/pkg v0.0.0-20230316114047-e2b41b377bac h1:TLQchMx+BRTnHyebDp github.com/kubevela/pkg v0.0.0-20230316114047-e2b41b377bac/go.mod h1:GilLxt+9L4sU2tLeZAGHga8wiYmjjfPX/Q6JkyuuXSM= github.com/kubevela/prism v1.7.0-alpha.1 h1:oeZFn1Oy6gxSSFzMTfsWjLOCKaaooMVm1JGNK4j4Mlo= github.com/kubevela/prism v1.7.0-alpha.1/go.mod h1:AJSDfdA+RkRSnWx3xEcogbmOTpX+l7RSIwqVHxwUtaI= -github.com/kubevela/workflow v0.5.0 h1:1C3v8q7xuNQRww/pD/uu2ywTX0xOG0jb+rQsM1sjhwU= -github.com/kubevela/workflow v0.5.0/go.mod h1:l1zZpJEJmI/ieI3vM3TTGOfZSPFDl5Ax7MWfbR6It98= +github.com/kubevela/workflow v0.5.1-0.20230404061444-a4f3ec81fca7 h1:iYsJLZRD/eLZkVxUgM3AdbHpsMHKxhf5YhsQDolEZ/U= +github.com/kubevela/workflow v0.5.1-0.20230404061444-a4f3ec81fca7/go.mod h1:+Ah40fwzX9fi/xeWdphew9J4kqfJiGwXw5MDeGPq3IU= github.com/kylelemons/godebug v0.0.0-20160406211939-eadb3ce320cb/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml index c9e40326d..6cccaf38d 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml @@ -2306,6 +2306,11 @@ spec: alias: type: string type: object + mode: + description: Mode is only valid for sub steps, it + defines the mode of the sub steps + nullable: true + type: string name: description: Name is the unique name of the workflow step. @@ -4168,6 +4173,11 @@ spec: alias: type: string type: object + mode: + description: Mode is only valid for sub steps, it defines + the mode of the sub steps + nullable: true + type: string name: description: Name is the unique name of the workflow step. type: string diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_applications.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_applications.yaml index 79b883cd0..9fd44da3e 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_applications.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_applications.yaml @@ -1068,6 +1068,11 @@ spec: alias: type: string type: object + mode: + description: Mode is only valid for sub steps, it defines + the mode of the sub steps + nullable: true + type: string name: description: Name is the unique name of the workflow step. type: string diff --git a/pkg/controller/core.oam.dev/v1alpha2/application/application_controller_test.go b/pkg/controller/core.oam.dev/v1alpha2/application/application_controller_test.go index d650114ac..94b844a45 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/application/application_controller_test.go +++ b/pkg/controller/core.oam.dev/v1alpha2/application/application_controller_test.go @@ -1434,6 +1434,111 @@ var _ = Describe("Test Application Controller", func() { Expect(checkApp.Status.Workflow.Mode).Should(BeEquivalentTo(fmt.Sprintf("%s-%s", workflowv1alpha1.WorkflowModeDAG, workflowv1alpha1.WorkflowModeStep))) }) + It("application with mode in workflow step group", func() { + ns := corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: "app-with-group-mode", + }, + } + Expect(k8sClient.Create(ctx, &ns)).Should(BeNil()) + healthComponentDef := &v1beta1.ComponentDefinition{} + hCDefJson, _ := yaml.YAMLToJSON([]byte(cdDefWithHealthStatusYaml)) + Expect(json.Unmarshal(hCDefJson, healthComponentDef)).Should(BeNil()) + healthComponentDef.Name = "worker-with-health" + healthComponentDef.Namespace = "app-with-group-mode" + Expect(k8sClient.Create(ctx, healthComponentDef)).Should(BeNil()) + app := &v1beta1.Application{ + TypeMeta: metav1.TypeMeta{ + Kind: "Application", + APIVersion: "core.oam.dev/v1beta1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "app-with-group-mode", + Namespace: "app-with-group-mode", + }, + Spec: v1beta1.ApplicationSpec{ + Components: []common.ApplicationComponent{ + { + Name: "myweb1", + Type: "worker-with-health", + Properties: &runtime.RawExtension{Raw: []byte(`{"cmd":["sleep","1000"],"image":"busybox","lives": "i am lives","enemies": "empty"}`)}, + }, + { + Name: "myweb3", + Type: "worker", + Properties: &runtime.RawExtension{Raw: []byte(`{"cmd":["sleep","1000"],"image":"busybox"}`)}, + }, + { + Name: "myweb2", + Type: "worker-with-health", + Properties: &runtime.RawExtension{Raw: []byte(`{"cmd":["sleep","1000"],"image":"busybox","lives": "i am lives","enemies": "empty"}`)}, + }, + }, + Workflow: &v1beta1.Workflow{ + Mode: &workflowv1alpha1.WorkflowExecuteMode{ + Steps: workflowv1alpha1.WorkflowModeDAG, + }, + Steps: []workflowv1alpha1.WorkflowStep{ + { + WorkflowStepBase: workflowv1alpha1.WorkflowStepBase{ + Name: "myweb1", + Type: "apply-component", + Properties: &runtime.RawExtension{Raw: []byte(`{"component":"myweb1"}`)}, + }, + }, + { + WorkflowStepBase: workflowv1alpha1.WorkflowStepBase{ + Name: "myweb2", + Type: "step-group", + }, + Mode: workflowv1alpha1.WorkflowModeStep, + SubSteps: []workflowv1alpha1.WorkflowStepBase{ + { + Name: "myweb2-sub1", + Type: "apply-component", + Properties: &runtime.RawExtension{Raw: []byte(`{"component":"myweb2"}`)}, + }, + { + Name: "myweb2-sub2", + Type: "apply-component", + Properties: &runtime.RawExtension{Raw: []byte(`{"component":"myweb3"}`)}, + }, + }, + }, + }, + }, + }, + } + + Expect(k8sClient.Create(context.Background(), app)).Should(BeNil()) + appKey := types.NamespacedName{Namespace: ns.Name, Name: app.Name} + testutil.ReconcileOnceAfterFinalizer(reconciler, reconcile.Request{NamespacedName: appKey}) + + expDeployment := &v1.Deployment{} + web3Key := types.NamespacedName{Namespace: ns.Name, Name: "myweb3"} + Expect(k8sClient.Get(ctx, web3Key, expDeployment)).Should(util.NotFoundMatcher{}) + + web1Key := types.NamespacedName{Namespace: ns.Name, Name: "myweb1"} + Expect(k8sClient.Get(ctx, web1Key, expDeployment)).Should(BeNil()) + expDeployment.Status.Replicas = 1 + expDeployment.Status.ReadyReplicas = 1 + Expect(k8sClient.Status().Update(ctx, expDeployment)).Should(BeNil()) + web2Key := types.NamespacedName{Namespace: ns.Name, Name: "myweb2"} + Expect(k8sClient.Get(ctx, web2Key, expDeployment)).Should(BeNil()) + expDeployment.Status.Replicas = 1 + expDeployment.Status.ReadyReplicas = 1 + Expect(k8sClient.Status().Update(ctx, expDeployment)).Should(BeNil()) + + testutil.ReconcileOnce(reconciler, reconcile.Request{NamespacedName: appKey}) + + Expect(k8sClient.Get(ctx, web3Key, expDeployment)).Should(BeNil()) + + checkApp := &v1beta1.Application{} + Expect(k8sClient.Get(ctx, appKey, checkApp)).Should(BeNil()) + Expect(checkApp.Status.Phase).Should(BeEquivalentTo(common.ApplicationRunning)) + Expect(checkApp.Status.Workflow.Mode).Should(BeEquivalentTo(fmt.Sprintf("%s-%s", workflowv1alpha1.WorkflowModeDAG, workflowv1alpha1.WorkflowModeDAG))) + }) + It("application with sub steps", func() { ns := corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{