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

Workflow and Template status change notification/trigger using Lifecycle Hook #7073

Closed
Tracked by #6943
sarabala1979 opened this issue Oct 26, 2021 · 3 comments
Closed
Tracked by #6943
Assignees
Labels

Comments

@sarabala1979
Copy link
Member

sarabala1979 commented Oct 26, 2021

Summary

Inspiration from #4355. We can add workflow and template lifecycle hook

Example:
Lifecycle hook (Workflow level and Template level)
Option 1:

  hooks:
    running:
      template: notify
      arguments:
        parameters:
          - name: status
            value: "{{workflows.status}}"
    failed:
      template: notify-failed
      arguments:
        parameters:
          - name: status
            value: "{{workflows.status}}"
    succeed:
      template: notify-success
      arguments:
        parameters:
          - name: status
            value: "{{workflows.status}}"
    errored:
      template: notify-errord
      arguments:
        parameters:
          - name: status
            value: "{{workflows.status}}"

Option2:

  hooks:
   statusUpdate:
      template: notify
      arguments:
        parameters:
          - name: status
            value: "{{workflows.status}}"
@sarabala1979 sarabala1979 added the type/feature Feature request label Oct 26, 2021
@sarabala1979 sarabala1979 changed the title Lifecycle status update Hook for workflow and Template state update Workflow and Template state notification/trigger using Lifecycle Hook Oct 27, 2021
@sarabala1979 sarabala1979 changed the title Workflow and Template state notification/trigger using Lifecycle Hook Workflow and Template status change notification/trigger using Lifecycle Hook Oct 27, 2021
@alexec alexec mentioned this issue Nov 15, 2021
15 tasks
@alexec
Copy link
Contributor

alexec commented Nov 15, 2021

Just a thought: make consistent with pod hooks:

https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/

@sarabala1979
Copy link
Member Author

Sample workflow

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: lifecycle-hook-
spec:
  entrypoint: diamond
  hooks:
    running:
      expression: "{{workflow.status}} == Running"
      template: http
  templates:
    - name: diamond
      dag:
        tasks:
          - name: A
            hooks:
              exit:
                template: http
              success:
                expression: "{{tasks.A.status}} == Succeeded"
                template: http
              failure:
                expression: "{{tasks.A.status}} == Failed"
                template: http
              error:
                expression: "{{tasks.A.status}} == Error"
                template: http
            template: coinflip
          - name: B
            hooks:
              success:
                expression: "{{tasks.B.status}} == Succeeded"
                template: http
            depends: "A"
            template: coinflip
          - name: C
            hooks:
              success:
                expression: "{{tasks.C.status}} == Succeeded"
                template: heads
            depends: "A"
            template: coinflip
          - name: D
            hooks:
              success:
                expression: "{{tasks.D.status}} == Succeeded"
                template: heads
            depends: "B && C"
            template: coinflip
    
    - name: coinflip
      steps:
        #    - - name: flip-coin-1
        #        template: prestart
        - - name: flip-coin
            hooks:
              success:
                expression: "{{steps.flip-coin.status}} == Succeeded"
                template: http
              condition:
                expression: "{{steps.flip-coin.status}} == Succeeded"
                template: http
            template: flip-coin
        - - name: heads
            hooks:
              success:
                expression: "{{steps.flip-coin.outputs.result}} == heads"
                template: heads
            template: http
            when: "{{steps.flip-coin.outputs.result}} == heads"
          - name: tails
      
            template: heads
            when: "{{steps.flip-coin.outputs.result}} == tails"
    
    - name: flip-coin
      script:
        image: python:alpine3.6
        command: [python]
        source: |
          import random
          result = "heads" if random.randint(0,1) == 0 else "tails"
          print(result)
    
    - name: heads
      container:
        image: alpine:3.6
        command: [sh, -c]
        args: ["echo \"it was heads\""]

    - name: http
      http:
        # url: http://dummy.restapiexample.com/api/v1/employees
        url: "https://raw.githubusercontent.com/argoproj/argo-workflows/4e450e250168e6b4d51a126b784e90b11a0162bc/pkg/apis/workflow/v1alpha1/generated.swagger.json"

@sarabala1979 sarabala1979 self-assigned this Nov 22, 2021
@alexec
Copy link
Contributor

alexec commented Feb 7, 2022

Fixed I think?

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

No branches or pull requests

3 participants