Skip to content

Commit

Permalink
feat: add support of submit from existing resource (#1908) (#1941)
Browse files Browse the repository at this point in the history
Signed-off-by: shirou <[email protected]>
  • Loading branch information
shirou authored and whynowy committed Jun 9, 2022
1 parent 8a3cdf6 commit e80ab9f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion controllers/sensor/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func validateArgoWorkflowTrigger(trigger *v1alpha1.ArgoWorkflowTrigger) error {
}

switch trigger.Operation {
case v1alpha1.Submit, v1alpha1.Suspend, v1alpha1.Retry, v1alpha1.Resume, v1alpha1.Resubmit, v1alpha1.Terminate, v1alpha1.Stop:
case v1alpha1.Submit, v1alpha1.SubmitFrom, v1alpha1.Suspend, v1alpha1.Retry, v1alpha1.Resume, v1alpha1.Resubmit, v1alpha1.Terminate, v1alpha1.Stop:
default:
return errors.Errorf("unknown operation type %s", string(trigger.Operation))
}
Expand Down
13 changes: 8 additions & 5 deletions docs/sensors/triggers/argo-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ Although the sensor defined above lets you trigger an Argo workflow, it doesn't
provided by the Argo CLI such as,

1. Submit
2. Resubmit
3. Resume
4. Retry
5. Suspend
2. Submit --from
3. Resubmit
4. Resume
5. Retry
6. Suspend
7. Terminate
8. Stop

To make use of Argo CLI operations, The sensor provides the `argoWorkflow` trigger template,

argoWorkflow:
operation: submit # submit, resubmit, resume, retry, suspend, terminate or stop
operation: submit # submit, submit-from, resubmit, resume, retry, suspend, terminate or stop

Complete example is available [here](https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/special-workflow-trigger.yaml).
22 changes: 22 additions & 0 deletions examples/sensors/specia-workflow-trigger-submit-existing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
name: webhook
spec:
template:
serviceAccountName: operate-workflow-sa
dependencies:
- name: test-dep
eventSourceName: webhook
eventName: example
triggers:
- template:
name: argo-workflow-trigger
argoWorkflow:
operation: submit-from
source:
resource:
apiVersion: argoproj.io/v1alpha1
kind: CronWorkflow
metadata:
name: special-trigger
15 changes: 8 additions & 7 deletions pkg/apis/sensor/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ type ArgoWorkflowOperation string

// possible values for ArgoWorkflowOperation
const (
Submit ArgoWorkflowOperation = "submit" // submit a workflow
Suspend ArgoWorkflowOperation = "suspend" // suspends a workflow
Resubmit ArgoWorkflowOperation = "resubmit" // resubmit a workflow
Retry ArgoWorkflowOperation = "retry" // retry a workflow
Resume ArgoWorkflowOperation = "resume" // resume a workflow
Terminate ArgoWorkflowOperation = "terminate" // terminate a workflow
Stop ArgoWorkflowOperation = "stop" // stop a workflow
Submit ArgoWorkflowOperation = "submit" // submit a workflow
SubmitFrom ArgoWorkflowOperation = "submit-from" // submit from existing resource
Suspend ArgoWorkflowOperation = "suspend" // suspends a workflow
Resubmit ArgoWorkflowOperation = "resubmit" // resubmit a workflow
Retry ArgoWorkflowOperation = "retry" // retry a workflow
Resume ArgoWorkflowOperation = "resume" // resume a workflow
Terminate ArgoWorkflowOperation = "terminate" // terminate a workflow
Stop ArgoWorkflowOperation = "stop" // stop a workflow
)

// Comparator refers to the comparator operator for a data filter
Expand Down
13 changes: 13 additions & 0 deletions sensors/triggers/argo-workflow/argo-workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"os/exec"
"strconv"
"strings"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -160,6 +161,18 @@ func (t *ArgoWorkflowTrigger) Execute(ctx context.Context, events map[string]*v1
return nil, errors.Wrapf(err, "failed to write workflow json %s to the temp file %s", name, file.Name())
}
cmd = exec.Command("argo", "-n", namespace, "submit", file.Name())
case v1alpha1.SubmitFrom:
wf := obj.GetKind()
switch strings.ToLower(wf) {
case "cronworkflow":
wf = "cronwf"
case "workflow":
wf = "wf"
default:
return nil, errors.Errorf("invalid kind %s", wf)
}
fromArg := fmt.Sprintf("%s/%s", wf, name)
cmd = exec.Command("argo", "-n", namespace, "submit", "--from", fromArg)
case v1alpha1.Resubmit:
cmd = exec.Command("argo", "-n", namespace, "resubmit", name)
case v1alpha1.Resume:
Expand Down

0 comments on commit e80ab9f

Please sign in to comment.