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

docs: add json destructuring example #6250

Merged
merged 6 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/conditional-artifacts-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ under step/DAG level output parameter. Both use the
* [Steps parameter example](examples/conditional-parameters.yaml)
* [DAG parameter example](examples/dag-conditional-parameters.yaml)

## Build-In Functions
## Built-In Functions

Convenient functions added to support more use cases:

Expand Down
24 changes: 24 additions & 0 deletions docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ Workflow is the definition of a workflow resource

- [`exit-handlers.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handlers.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`expression-tag-template-workflow.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-tag-template-workflow.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)
Expand Down Expand Up @@ -505,6 +507,8 @@ WorkflowSpec is the specification of a Workflow.

- [`exit-handlers.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handlers.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`expression-tag-template-workflow.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-tag-template-workflow.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)
Expand Down Expand Up @@ -911,6 +915,8 @@ CronWorkflowSpec is the specification of a CronWorkflow

- [`exit-handlers.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handlers.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`expression-tag-template-workflow.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-tag-template-workflow.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)
Expand Down Expand Up @@ -1274,6 +1280,8 @@ WorkflowTemplateSpec is a spec of WorkflowTemplate.

- [`exit-handlers.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handlers.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`expression-tag-template-workflow.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-tag-template-workflow.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)
Expand Down Expand Up @@ -1604,6 +1612,8 @@ Arguments to a template

- [`exit-handler-with-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handler-with-param.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`expression-tag-template-workflow.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-tag-template-workflow.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)
Expand Down Expand Up @@ -2324,6 +2334,8 @@ Parameter indicate a passed string parameter to a service template with an optio

- [`exit-handler-with-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handler-with-param.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`expression-tag-template-workflow.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-tag-template-workflow.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)
Expand Down Expand Up @@ -2826,6 +2838,8 @@ Inputs are the mechanism for passing parameters, artifacts, volumes from one tem

- [`exit-handler-with-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handler-with-param.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`expression-tag-template-workflow.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-tag-template-workflow.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)
Expand Down Expand Up @@ -3027,6 +3041,8 @@ ScriptTemplate is a template subtype to enable scripting through code steps

- [`exit-handler-with-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handler-with-param.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)

- [`loops-param-result.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/loops-param-result.yaml)
Expand Down Expand Up @@ -3962,6 +3978,8 @@ DataSource sources external data into a data template

- [`exit-handler-with-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handler-with-param.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)

- [`loops-param-result.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/loops-param-result.yaml)
Expand Down Expand Up @@ -4476,6 +4494,8 @@ ObjectMeta is metadata that all persisted resources must have, which includes al

- [`exit-handlers.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handlers.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`expression-tag-template-workflow.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-tag-template-workflow.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)
Expand Down Expand Up @@ -5338,6 +5358,8 @@ EnvVar represents an environment variable present in a Container.

- [`colored-logs.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/colored-logs.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`secrets.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/secrets.yaml)

- [`sidecar-dind.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/sidecar-dind.yaml)
Expand Down Expand Up @@ -5733,6 +5755,8 @@ PersistentVolumeClaimSpec describes the common attributes of storage devices and

- [`exit-handlers.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/exit-handlers.yaml)

- [`expression-destructure-json.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-destructure-json.yaml)

- [`expression-tag-template-workflow.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/expression-tag-template-workflow.yaml)

- [`fibonacci-seq-conditional-param.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/fibonacci-seq-conditional-param.yaml)
Expand Down
6 changes: 6 additions & 0 deletions docs/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ Convert to a JSON string (needed for `withParam`):
toJson([1, 2])
```

Extract data from JSON:

```
jsonpath(inputs.parameters.json, '$.some.path')
```

You can also use [Sprig functions](http://masterminds.github.io/sprig/):

Trim a string:
Expand Down
34 changes: 34 additions & 0 deletions examples/expression-destructure-json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: expression-destructure-json-
annotations:
workflows.argoproj.io/version: ">= 3.1.0"
spec:
arguments:
parameters:
- name: config
value: '{"a": "1", "b": "2", "c": "3"}'
entrypoint: main
templates:
- name: main
inputs:
parameters:
- name: a
value: "{{=jsonpath(workflow.parameters.config, '$.a')}}"
- name: b
value: "{{=jsonpath(workflow.parameters.config, '$.b')}}"
- name: c
value: "{{=jsonpath(workflow.parameters.config, '$.c')}}"
script:
env:
- name: A
value: "{{inputs.parameters.a}}"
- name: B
value: "{{inputs.parameters.b}}"
- name: C
value: "{{inputs.parameters.c}}"
image: debian:9.4
command: [bash]
source: |
echo "$A$B$C"
2 changes: 1 addition & 1 deletion workflow/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
// Who created this workflow.
LabelKeyCreator = workflow.WorkflowFullName + "/creator"
LabelKeyCreatorEmail = workflow.WorkflowFullName + "/creator-email"
// LabelKeyCompleted is the metadata label applied on worfklows and workflow pods to indicates if resource is completed
// LabelKeyCompleted is the metadata label applied on workflows and workflow pods to indicates if resource is completed
// Workflows and pods with a completed=true label will be ignored by the controller.
// See also `LabelKeyWorkflowArchivingStatus`.
LabelKeyCompleted = workflow.WorkflowFullName + "/completed"
Expand Down
2 changes: 1 addition & 1 deletion workflow/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,7 @@ spec:
args: ["name: {{inputs.parameters.name}} namespace: {{inputs.parameters.namespace}} serviceAccountName: {{inputs.parameters.serviceAccountName}} uid: {{inputs.parameters.uid}} priority: {{inputs.parameters.priority}}"]
`

func TestWorfklowGlobalVariables(t *testing.T) {
func TestWorkflowGlobalVariables(t *testing.T) {
_, err := validate(globalVariables)
assert.NoError(t, err)
}
Expand Down