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

Why can’t utils.SuspendWorkflow() pause a workflowrun that has a step-group? #179

Open
moruikang opened this issue Dec 4, 2023 · 2 comments

Comments

@moruikang
Copy link

moruikang commented Dec 4, 2023

Describe the bug

I found that in the previous version of the SDK(vela cli 1.7), SuspendWorkflow() would only set run.Status.Suspend = true.

However, the new version of the SDK(vela 1.9) will set sub-step’s sub Phase to: v1alpha1.WorkflowStepPhaseSuspending. This could lead to the workflowrun Suspending state finally being set to state=Executing in Reconcile().

please tell me why? and how can i use utils.SuspendWorkflow() to stop my workflowrun?

To Reproduce

my demo workflow yaml:

apiVersion: core.oam.dev/v1alpha1
kind: WorkflowRun
metadata:
  name: dependency-ng
  namespace: default
spec:
  mode:
    steps: DAG
  workflowSpec:
    steps:
      - name: step1
        type: apply-deployment
        dependsOn:
          - step2
          - step3
        properties:
          image: 10.113.xx.x:31104/library/nginx:v1.23.2
      - name: step2
        type: apply-deployment
        properties:
          image: 10.113.xx.x:31104/library/nginx:v1.23.2
      - name: step3
        type: apply-deployment
        properties:
          image: 10.113.xx.x:31104/library/nginx:v1.23.2
      - name: step-gg
        type: step-group
        subSteps:
          - name: apply-sub-step1
            type: apply-deployment
            properties:
              image: 10.113.xx.x:31104/library/nginx:v1.23.2
          - name: apply-sub-step2
            type: apply-deployment
            properties:
              image: nginx:v1.23.2

The following is the official source code call (workflow 0.6):

clientN := mgr.GetClient()

run := &wfv1alpha1.WorkflowRun{}
ctx := context.Background()
key := types.NamespacedName{Namespace: "default", Name: "dependency-ng"}
err = clientN.Get(ctx, key, run)
if err != nil {
    fmt.Println("err1")
    panic(err)
}

err = utils.SuspendWorkflow(ctx, clientN, run, "")

if err != nil {
    fmt.Println("err2")
    panic(err)
}

workflowrun cant not suspend

$ kubectl get workflowruns.core.oam.dev
dependency-ng   executing   23m

The following is my custom call based on the workflow source code of the previous version(workflow 0.4-):

	//Manually try to pause the task
	stepName := ""
	run.Status.Suspend = true
	steps := run.Status.Steps
	found := stepName == ""

	for i, step := range steps {
		if step.Phase == wfv1alpha1.WorkflowStepPhaseRunning {
			if stepName == "" {
				utils.OperateSteps(steps, i, -1, wfv1alpha1.WorkflowStepPhaseRunning)
			} else if stepName == step.Name {
				utils.OperateSteps(steps, i, -1, wfv1alpha1.WorkflowStepPhaseRunning)
				found = true
				break
			}
		}
		for j, sub := range step.SubStepsStatus {
			if sub.Phase == wfv1alpha1.WorkflowStepPhaseRunning {
				if stepName == "" {
					utils.OperateSteps(steps, i, j, wfv1alpha1.WorkflowStepPhaseRunning)
				} else if stepName == sub.Name {
					utils.OperateSteps(steps, i, j, wfv1alpha1.WorkflowStepPhaseRunning)
					found = true
					break
				}
			}
		}
	}
    if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
		return clientN.Status().Patch(ctx, run, client.Merge)
	}); err != nil {
		fmt.Println(err)
	}

workflowrun Suspend work

$ kubectl get workflowruns.core.oam.dev
dependency-ng   suspending   23m

Expected behavior

Screenshots

Workflow Version

v0.6.0

Cluster information

Additional context

@FogDong
Copy link
Member

FogDong commented Dec 5, 2023

Can you provide more detail of this?

@moruikang
Copy link
Author

Can you provide more detail of this?

As above, I have provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants