Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add mode in steps for step group #153

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ type WorkflowList struct {
// WorkflowStep defines how to execute a workflow step.
type WorkflowStep struct {
WorkflowStepBase `json:",inline"`
SubSteps []WorkflowStepBase `json:"subSteps,omitempty"`
// Mode is only valid for sub steps, it defines the mode of the sub steps
// +nullable
Mode WorkflowMode `json:"mode,omitempty"`
SubSteps []WorkflowStepBase `json:"subSteps,omitempty"`
}

// WorkflowStepMeta contains the meta data of a workflow step
Expand Down
5 changes: 5 additions & 0 deletions charts/vela-workflow/crds/core.oam.dev_workflowruns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,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
Expand Down
5 changes: 5 additions & 0 deletions charts/vela-workflow/crds/core.oam.dev_workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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
Expand Down
74 changes: 74 additions & 0 deletions controllers/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,80 @@ var _ = Describe("Test Workflow", func() {
}))
})

It("test workflow run with mode in step groups", func() {
wr := wrTemplate.DeepCopy()
wr.Name = "wr-group-mode"
wr.Spec.WorkflowSpec.Steps = []v1alpha1.WorkflowStep{
{
WorkflowStepBase: v1alpha1.WorkflowStepBase{
Name: "step1",
Type: "test-apply",
Properties: &runtime.RawExtension{Raw: []byte(`{"cmd":["sleep","1000"],"image":"busybox"}`)},
},
},
{
WorkflowStepBase: v1alpha1.WorkflowStepBase{
Name: "group",
Type: "step-group",
},
Mode: v1alpha1.WorkflowModeStep,
SubSteps: []v1alpha1.WorkflowStepBase{
{
Name: "step2",
Type: "test-apply",
Properties: &runtime.RawExtension{Raw: []byte(`{"cmd":["sleep","1000"],"image":"busybox"}`)},
},
{
Name: "step3",
Type: "test-apply",
Properties: &runtime.RawExtension{Raw: []byte(`{"cmd":["sleep","1000"],"image":"busybox"}`)},
},
},
},
}
wr.Spec.Mode = &v1alpha1.WorkflowExecuteMode{
Steps: v1alpha1.WorkflowModeDAG,
}

Expect(k8sClient.Create(context.Background(), wr)).Should(BeNil())
wrKey := types.NamespacedName{Namespace: wr.Namespace, Name: wr.Name}

tryReconcile(reconciler, wr.Name, wr.Namespace)

expDeployment := &appsv1.Deployment{}
step3Key := types.NamespacedName{Namespace: wr.Namespace, Name: "step3"}
Expect(k8sClient.Get(ctx, step3Key, expDeployment)).Should(utils.NotFoundMatcher{})

checkRun := &v1alpha1.WorkflowRun{}
Expect(k8sClient.Get(ctx, wrKey, checkRun)).Should(BeNil())
step1Key := types.NamespacedName{Namespace: wr.Namespace, Name: "step1"}
Expect(k8sClient.Get(ctx, step1Key, expDeployment)).Should(BeNil())
expDeployment.Status.Replicas = 1
expDeployment.Status.ReadyReplicas = 1
Expect(k8sClient.Status().Update(ctx, expDeployment)).Should(BeNil())
step2Key := types.NamespacedName{Namespace: wr.Namespace, Name: "step2"}
Expect(k8sClient.Get(ctx, step2Key, expDeployment)).Should(BeNil())
expDeployment.Status.Replicas = 1
expDeployment.Status.ReadyReplicas = 1
Expect(k8sClient.Status().Update(ctx, expDeployment)).Should(BeNil())

tryReconcile(reconciler, wr.Name, wr.Namespace)

Expect(k8sClient.Get(ctx, step3Key, expDeployment)).Should(BeNil())
expDeployment.Status.Replicas = 1
expDeployment.Status.ReadyReplicas = 1
Expect(k8sClient.Status().Update(ctx, expDeployment)).Should(BeNil())

tryReconcile(reconciler, wr.Name, wr.Namespace)

Expect(k8sClient.Get(ctx, wrKey, checkRun)).Should(BeNil())
Expect(checkRun.Status.Phase).Should(BeEquivalentTo(v1alpha1.WorkflowStateSucceeded))
Expect(checkRun.Status.Mode).Should(BeEquivalentTo(v1alpha1.WorkflowExecuteMode{
Steps: v1alpha1.WorkflowModeDAG,
SubSteps: v1alpha1.WorkflowModeDAG,
}))
})

It("test sub steps", func() {
wr := wrTemplate.DeepCopy()
wr.Name = "wr-substeps"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/onsi/gomega v1.20.2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/common v0.32.1
github.com/robfig/cron/v3 v3.0.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
Expand Down Expand Up @@ -172,7 +173,6 @@ require (
github.com/pjbgf/sha1cd v0.2.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rivo/uniseg v0.4.2 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ func generateTaskRunner(ctx context.Context,
if instance.Mode != nil {
options.SubStepExecuteMode = instance.Mode.SubSteps
}
if step.Mode != "" {
options.SubStepExecuteMode = step.Mode
}
}

genTask, err := taskDiscover.GetTaskGenerator(ctx, step.Type)
Expand Down