Suspend and Resume

This section introduces how to suspend and resume the workflow in KubeVela.

Suspend the Workflow

In KubeVela, you can choose to use the vela command to manually suspend the execution of the workflow, or use a built-in special step type suspend to automatically suspend the workflow.

Suspend Manually

If you have a running application and you want to suspend its execution, you can use vela workflow suspend to suspend the workflow.

  1. $ vela workflow suspend my-app
  2. Successfully suspend workflow: my-app

Use Suspend Step

Apply the following example:

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: suspend
  5. namespace: default
  6. spec:
  7. components:
  8. - name: comp1
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. - name: comp2
  14. type: webservice
  15. properties:
  16. image: crccheck/hello-world
  17. port: 8000
  18. workflow:
  19. steps:
  20. - name: apply1
  21. type: apply-component
  22. properties:
  23. component: comp1
  24. - name: suspend
  25. type: suspend
  26. - name: apply2
  27. type: apply-component
  28. properties:
  29. component: comp2

Use vela status to check the status of the Application:

  1. $ vela status suspend
  2. About:
  3. Name: suspend
  4. Namespace: default
  5. Created at: 2022-06-27 17:36:58 +0800 CST
  6. Status: workflowSuspending
  7. Workflow:
  8. mode: StepByStep
  9. finished: false
  10. Suspend: true
  11. Terminated: false
  12. Steps
  13. - id:yj9h29uv6v
  14. name:apply1
  15. type:apply-component
  16. phase:succeeded
  17. message:
  18. - id:xvmda4he5e
  19. name:suspend
  20. type:suspend
  21. phase:running
  22. message:
  23. Services:
  24. - Name: comp1
  25. Cluster: local Namespace: default
  26. Type: webservice
  27. Healthy Ready:1/1
  28. No trait applied

As you can see, when the first step is completed, the suspend step will be executed and this step will suspend the workflow.

Resume the Workflow

Resume Manually

Once the workflow is suspended, you can use the vela workflow resume command to manually resume the workflow.

Take the above suspended application as an example:

  1. $ vela workflow resume suspend
  2. Successfully resume workflow: suspend

After successfully continuing the workflow, view the status of the app:

  1. $ vela status suspend
  2. About:
  3. Name: suspend
  4. Namespace: default
  5. Created at: 2022-06-27 17:36:58 +0800 CST
  6. Status: running
  7. Workflow:
  8. mode: StepByStep
  9. finished: true
  10. Suspend: false
  11. Terminated: false
  12. Steps
  13. - id:yj9h29uv6v
  14. name:apply1
  15. type:apply-component
  16. phase:succeeded
  17. message:
  18. - id:xvmda4he5e
  19. name:suspend
  20. type:suspend
  21. phase:succeeded
  22. message:
  23. - id:66jonaxjef
  24. name:apply2
  25. type:apply-component
  26. phase:succeeded
  27. message:
  28. Services:
  29. - Name: comp2
  30. Cluster: local Namespace: default
  31. Type: webservice
  32. Healthy Ready:1/1
  33. No trait applied
  34. - Name: comp1
  35. Cluster: local Namespace: default
  36. Type: webservice
  37. Healthy Ready:1/1
  38. No trait applied

As you can see, the workflow has continued to execute.

Terminate Manually

If you want to terminate a workflow while it is suspended, you can use the vela workflow terminate command to terminate the workflow.

  1. $ vela workflow terminate my-app
  2. Successfully terminate workflow: my-app

Resume the Workflow Automatically

If you want the workflow to be continued automatically after a period of time has passed. Then, you can add a duration parameter to the suspend step. When the duration time elapses, the workflow will automatically continue execution.

Apply the following example:

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: auto-resume
  5. namespace: default
  6. spec:
  7. components:
  8. - name: comp1
  9. type: webservice
  10. properties:
  11. image: crccheck/hello-world
  12. port: 8000
  13. - name: comp2
  14. type: webservice
  15. properties:
  16. image: crccheck/hello-world
  17. port: 8000
  18. workflow:
  19. steps:
  20. - name: apply1
  21. type: apply-component
  22. properties:
  23. component: comp1
  24. - name: suspend
  25. type: suspend
  26. properties:
  27. duration: 5s
  28. - name: apply2
  29. type: apply-component
  30. properties:
  31. component: comp2

Use vela status to check the status of the Application:

  1. $ vela status auto-resume
  2. About:
  3. Name: auto-resume
  4. Namespace: default
  5. Created at: 2022-06-27 17:57:35 +0800 CST
  6. Status: running
  7. Workflow:
  8. mode: StepByStep
  9. finished: true
  10. Suspend: false
  11. Terminated: false
  12. Steps
  13. - id:q5jhm6mgwv
  14. name:apply1
  15. type:apply-component
  16. phase:succeeded
  17. message:
  18. - id:3xgfcp3cuj
  19. name:suspend
  20. type:suspend
  21. phase:succeeded
  22. message:
  23. - id:zjux8ud876
  24. name:apply2
  25. type:apply-component
  26. phase:succeeded
  27. message:
  28. Services:
  29. - Name: comp2
  30. Cluster: local Namespace: default
  31. Type: webservice
  32. Healthy Ready:1/1
  33. No trait applied
  34. - Name: comp1
  35. Cluster: local Namespace: default
  36. Type: webservice
  37. Healthy Ready:1/1
  38. No trait applied

As you can see, the suspend step is automatically executed successfully after five seconds, and the workflow is executed successfully.