Skip to content

Commit

Permalink
test: Add additional resource template test (#5166)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec committed Feb 24, 2021
1 parent a46ff82 commit 8a8759f
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 35 deletions.
3 changes: 2 additions & 1 deletion cmd/argo/commands/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
)

func verifyWorkflows(ctx context.Context, serviceClient workflowpkg.WorkflowServiceClient, namespace string, workflowNames []string) {
_, _ = fmt.Fprintln(os.Stderr, "verifying workflows...")
_, _ = fmt.Fprintln(os.Stdout)
_, _ = fmt.Fprintln(os.Stdout, "VERIFICATION")
failAtEnd := false
for _, name := range workflowNames {
wf, err := serviceClient.GetWorkflow(ctx, &workflowpkg.WorkflowGetRequest{
Expand Down
29 changes: 22 additions & 7 deletions docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ Workflow is the definition of a workflow resource

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

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

- [`k8s-set-owner-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-set-owner-reference.yaml)

- [`k8s-wait-wf.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-wait-wf.yaml)
Expand Down Expand Up @@ -481,6 +483,8 @@ WorkflowSpec is the specification of a Workflow.

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

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

- [`k8s-set-owner-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-set-owner-reference.yaml)

- [`k8s-wait-wf.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-wait-wf.yaml)
Expand Down Expand Up @@ -844,6 +848,8 @@ CronWorkflowSpec is the specification of a CronWorkflow

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

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

- [`k8s-set-owner-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-set-owner-reference.yaml)

- [`k8s-wait-wf.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-wait-wf.yaml)
Expand Down Expand Up @@ -1165,6 +1171,8 @@ WorkflowTemplateSpec is a spec of WorkflowTemplate.

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

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

- [`k8s-set-owner-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-set-owner-reference.yaml)

- [`k8s-wait-wf.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-wait-wf.yaml)
Expand Down Expand Up @@ -1812,6 +1820,8 @@ Template is a reusable and composable unit of execution in a workflow

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

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

- [`k8s-set-owner-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-set-owner-reference.yaml)

- [`k8s-wait-wf.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-wait-wf.yaml)
Expand Down Expand Up @@ -2871,6 +2881,8 @@ ResourceTemplate is a template subtype to manipulate kubernetes resources

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

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

- [`k8s-set-owner-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-set-owner-reference.yaml)

- [`k8s-wait-wf.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-wait-wf.yaml)
Expand Down Expand Up @@ -3568,6 +3580,10 @@ MetricLabel is a single label for a prometheus metric

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

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

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

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

- [`pod-metadata-wf-field.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/pod-metadata-wf-field.yaml)
Expand Down Expand Up @@ -4008,6 +4024,8 @@ ObjectMeta is metadata that all persisted resources must have, which includes al

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

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

- [`k8s-set-owner-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-set-owner-reference.yaml)

- [`k8s-wait-wf.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-wait-wf.yaml)
Expand Down Expand Up @@ -4561,6 +4579,8 @@ A single application container that you want to run within a pod.

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

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

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

- [`key-only-artifact.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/key-only-artifact.yaml)
Expand Down Expand Up @@ -4958,13 +4978,6 @@ ManagedFieldsEntry is a workflow-id, a FieldSet and the group version of the res

OwnerReference contains enough information to let you identify an owning object. An owning object must be in the same namespace as the dependent, or be cluster-scoped, so there is no namespace field.

<details>
<summary>Examples with this field (click to open)</summary>
<br>

- [`k8s-owner-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-owner-reference.yaml)
</details>

### Fields
| Field Name | Field Type | Description |
|:----------:|:----------:|---------------|
Expand Down Expand Up @@ -5197,6 +5210,8 @@ PersistentVolumeClaimSpec describes the common attributes of storage devices and

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

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

- [`k8s-set-owner-reference.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-set-owner-reference.yaml)

- [`k8s-wait-wf.yaml`](https://github.com/argoproj/argo-workflows/blob/master/examples/k8s-wait-wf.yaml)
Expand Down
53 changes: 29 additions & 24 deletions examples/k8s-owner-reference.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
# This example creates a Kubernetes resource that will be deleted
# when the workflow is deleted via Kubernetes GC.
#
# A configmap is used for this example, but the same approach would apply
# to other more interesting resource types.
#
# https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: k8s-owner-reference-
labels:
workflows.argoproj.io/test: "true"
annotations:
workflows.argoproj.io/description: |
This example creates a Kubernetes resource that will be deleted
when the workflow is deleted via Kubernetes GC.
A workflow is used for this example, but the same approach would apply
to other resource types.
https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/
workflows.argoproj.io/verify.py: |
assert status["phase"] == "Succeeded"
spec:
entrypoint: k8s-owner-reference
entrypoint: main
templates:
- name: k8s-owner-reference
resource:
action: create
manifest: |
apiVersion: v1
kind: ConfigMap
metadata:
generateName: owned-eg-
ownerReferences:
- apiVersion: argoproj.io/v1alpha1
blockOwnerDeletion: true
kind: Workflow
name: "{{workflow.name}}"
uid: "{{workflow.uid}}"
data:
some: value
- name: main
resource:
action: create
setOwnerReference: true
manifest: |
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: owned-eg-
spec:
entrypoint: main
templates:
- name: main
container:
image: argoproj/argosay:v2
25 changes: 25 additions & 0 deletions examples/k8s-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: k8s-patch-
labels:
workflows.argoproj.io/test: "true"
annotations:
workflows.argoproj.io/description: |
This example patches
workflows.argoproj.io/verify.py: |
assert status["phase"] == "Succeeded"
spec:
entrypoint: main
templates:
- name: main
resource:
action: patch
mergeStrategy: json
flags:
- pod
- "{{pod.name}}"
manifest: |
- op: add
path: /metadata/annotations/foo
value: bar
5 changes: 3 additions & 2 deletions manifests/quick-start/base/workflow-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ metadata:
name: workflow-role
rules:
# pod get/watch is used to identify the container IDs of the current pod
# pod patch is used to annotate the step's outputs back to controller (e.g. artifact location)
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- watch
# pod patch is used to annotate the step's outputs back to controller (e.g. artifact location)
# This is ONLY needed if the step/task has outputs that are used by another step or task.
- patch
# logs get/watch are used to get the pods logs for script outputs, and for log archival
- apiGroups:
Expand All @@ -23,7 +24,7 @@ rules:
- get
- watch
# This allows one workflow to create another.
# Not needed for the majority of use cases.
# This is only needed for resource templates.
- apiGroups:
- argoproj.io
resources:
Expand Down
3 changes: 2 additions & 1 deletion workflow/verify/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func Workflow(wf *wfv1.Workflow) error {
nodes[n.DisplayName] = n
}
return python.Run(verify, map[string]interface{}{
"metadata": wf,
"metadata": wf.ObjectMeta,
"spec": wf.Spec,
"nodes": nodes,
"status": wf.Status,
})
Expand Down

0 comments on commit 8a8759f

Please sign in to comment.