Skip to content

Commit

Permalink
feat: Customize workfow metadata from event data (#4783)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Albers <michael.john.albers@gmail.com>
  • Loading branch information
michaeljohnalbers committed Jan 2, 2021
1 parent 4eaae25 commit b73bd2b
Show file tree
Hide file tree
Showing 12 changed files with 809 additions and 470 deletions.
4 changes: 4 additions & 0 deletions api/jsonschema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,10 @@
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Arguments",
"description": "Arguments extracted from the event and then set as arguments to the workflow created."
},
"metadata": {
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta",
"description": "Metadata optional means to customize select fields of the workflow metadata"
},
"workflowTemplateRef": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.WorkflowTemplateRef",
"description": "WorkflowTemplateRef the workflow template to submit"
Expand Down
4 changes: 4 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3855,6 +3855,10 @@
"description": "Arguments extracted from the event and then set as arguments to the workflow created.",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.Arguments"
},
"metadata": {
"description": "Metadata optional means to customize select fields of the workflow metadata",
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta"
},
"workflowTemplateRef": {
"description": "WorkflowTemplateRef the workflow template to submit",
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.WorkflowTemplateRef"
Expand Down
2 changes: 1 addition & 1 deletion docs/access-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ echo $ARGO_TOKEN
Bearer ZXlKaGJHY2lPaUpTVXpJMU5pSXNJbXRwWkNJNkltS...
```

To that token with the CLI you need to set `ARGO_SERVER` (see `argo --help`).
To use that token with the CLI you need to set `ARGO_SERVER` (see `argo --help`).

Use that token in your API requests, e.g. to list workflows:

Expand Down
38 changes: 38 additions & 0 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,44 @@ curl $ARGO_SERVER/api/v1/events/argo/my-discriminator \
!!! Warning "Malformed Expressions"
If the expression is malformed, this is logged. It is not visible in logs or the UI.

### Customizing the Workflow Metadata
You can customize the name of the submitted workflow as well as add annotations and
labels. This is done by adding a `metadata` object to the submit object.

Normally the name of the workflow created from an event is simply the name of the
template with a timestamp appended. This can be customized by setting the name in the
`metadata` object.

Annotations and labels are added in the same fashion.

All the values for the name, annotations and labels are treated as expressions (see
below for details). The `metadata` object is the same `metadata` type as on all
Kubernetes resources and as such is parsed in the same manner. It is best to enclose
the expression in single quotes to avoid any problems when submitting the event
binding to Kubernetes.

This is an example snippet of how to set the name, annotations and labels. This is
based on the workflow binding from above, and the first event.
```yaml
submit:
metadata:
annotations:
anAnnotation: 'event.payload.message'
name: 'event.payload.message + "-world"'
labels:
someLabel: '"literal string"'
```
This will result in the workflow being named "hello-world" instead of
`my-wf-tmple-<timestamp>`. There will be an extra label with the key "someLabel" and
a value of "literal string". There will also be an extra annotation with the key
"anAnnotation" and a value of "hello"

Be careful when setting the name. If the name expression evaluates to that of a currently
existing workflow, the new workflow will fail to submit.

The name, annotation and label expression must evaluate to a string and follow the normal [Kubernetes naming
requirements](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/).

## Event Expression Syntax and the Event Expression Environment

**Event expressions** are expressions that are evaluated over the **event expression environment**.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ spec:
type: object
type: array
type: object
metadata:
type: object
workflowTemplateRef:
properties:
clusterScope:
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/workflow/v1alpha1/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type Submit struct {
// WorkflowTemplateRef the workflow template to submit
WorkflowTemplateRef WorkflowTemplateRef `json:"workflowTemplateRef" protobuf:"bytes,1,opt,name=workflowTemplateRef"`

// Metadata optional means to customize select fields of the workflow metadata
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,3,opt,name=metadata"`

// Arguments extracted from the event and then set as arguments to the workflow created.
Arguments *Arguments `json:"arguments,omitempty" protobuf:"bytes,2,opt,name=arguments"`
}

0 comments on commit b73bd2b

Please sign in to comment.