-
Notifications
You must be signed in to change notification settings - Fork 1
Add example workflows #44
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
Draft
JimMadge
wants to merge
17
commits into
main
Choose a base branch
from
examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
29c8c4d
Add example of curl to an external endpoint
JimMadge 9b873c6
Add example python analysis
JimMadge 8b812e1
add r script example with input and output artifacts
craddm 77e78ea
Add custom image example
craddm 23db3b4
add additional script for test workflow
craddm 6fae9c5
Merge remote-tracking branch 'upstream/main' into examples
craddm 4316175
Update example to succeed on failed DNS resolution
JimMadge 787438d
Add whoami example
JimMadge 718fa51
Add attempt to create an independent pod using a workflow
craddm 27e02d2
Add example of curl via IP (without DNS)
JimMadge 947236a
Merge branch 'main' into examples
craddm c63f6b2
Deploy example Argo Workflow template
craddm c70871b
update local yaml files
craddm f4876db
Merge remote-tracking branch 'upstream/main'
craddm 4ced64b
Merge branch 'main' into examples
craddm acffa0f
Move example after argo_workflows resource creation
craddm 33d513d
Import all examples using ConfigGroup
craddm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| metadata: | ||
| name: example-curl-external | ||
| namespace: argo-workflows | ||
| spec: | ||
| serviceAccountName: argo-workflow | ||
| entrypoint: steps | ||
| arguments: | ||
| parameters: | ||
| - name: url | ||
| value: ipinfo.io | ||
| - name: ip | ||
| value: 34.117.59.81 | ||
| templates: | ||
| - name: steps | ||
| steps: | ||
| - - name: FQDN | ||
| template: curl-fqdn | ||
| - name: IP | ||
| template: curl-ip | ||
| - name: curl-fqdn | ||
| inputs: | ||
| parameters: | ||
| - name: url | ||
| value: "{{workflow.parameters.url}}" | ||
| script: | ||
| name: main | ||
| image: alpine/curl | ||
| command: | ||
| - sh | ||
| source: | | ||
| curl -s https://{{inputs.parameters.url}} | ||
| # exit code 6 - Could not resolve host | ||
| test $? -eq 6 | ||
| - name: curl-ip | ||
| inputs: | ||
| parameters: | ||
| - name: url | ||
| value: "{{workflow.parameters.url}}" | ||
| - name: ip | ||
| value: "{{workflow.parameters.ip}}" | ||
| script: | ||
| name: main | ||
| image: alpine/curl | ||
| command: | ||
| - sh | ||
| source: | | ||
| curl -s https://{{inputs.parameters.url}} --resolve {{inputs.parameters.url}}:443:{{inputs.parameters.ip}} --connect-timeout 30 | ||
| # exit code 28 - Timeout | ||
| # exit code 7 - Failed to c onnect to host | ||
| code=$? | ||
| test $code -eq 28 || test $code -eq 7 | ||
| ttlStrategy: | ||
| secondsAfterCompletion: 300 | ||
| podGC: | ||
| strategy: OnPodCompletion | ||
| deleteDelayDuration: 300s |
15 changes: 15 additions & 0 deletions
15
example_workflows/input_and_output_artifacts/generate_plots.R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| library(tidyverse) | ||
| library(txtplot) | ||
| setwd("/tmp/test/") | ||
| head(mpg) | ||
| tmp <- | ||
| ggplot(mpg, aes(x = hwy, y = cty)) + | ||
| geom_point() + | ||
| geom_smooth() | ||
| tmp_boxplot <- | ||
| ggplot(mpg, aes(x = class, y = hwy)) + | ||
| geom_boxplot() + | ||
| theme_classic() | ||
| ggsave("/tmp/routput/test.png", plot = tmp, device = "png") | ||
| ggsave("/tmp/routput/test_boxplot.png", plot = tmp_boxplot, device = "png") | ||
| txtdensity(mpg$hwy) |
13 changes: 13 additions & 0 deletions
13
example_workflows/input_and_output_artifacts/generate_plots_no_txt.R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| library(tidyverse) | ||
| setwd("/tmp/test/") | ||
| head(mpg) | ||
| tmp <- | ||
| ggplot(mpg, aes(x = hwy, y = cty)) + | ||
| geom_point() + | ||
| geom_smooth() | ||
| tmp_boxplot <- | ||
| ggplot(mpg, aes(x = class, y = hwy)) + | ||
| geom_boxplot() + | ||
| theme_classic() | ||
| ggsave("/tmp/routput/test.png", plot = tmp, device = "png") | ||
| ggsave("/tmp/routput/test_boxplot.png", plot = tmp_boxplot, device = "png") |
27 changes: 27 additions & 0 deletions
27
example_workflows/input_and_output_artifacts/input_and_output_artifacts.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| metadata: | ||
| name: input-and-output-artifact-s3 | ||
| namespace: argo-workflows | ||
| spec: | ||
| templates: | ||
| - name: s3-input-and-output-example | ||
| inputs: | ||
| artifacts: | ||
| - name: rscript | ||
| path: /tmp/test/generate_plots_no_txt.R | ||
| s3: | ||
| key: generate_plots_no_txt.R | ||
| outputs: | ||
| artifacts: | ||
| - name: routput | ||
| path: /tmp/routput | ||
| s3: | ||
| key: /plot_gen.tgz | ||
| container: | ||
| image: rocker/tidyverse:latest | ||
| command: | ||
| - sh | ||
| - -c | ||
| args: | ||
| - mkdir /tmp/routput; Rscript /tmp/test/generate_plots_no_txt.R | ||
| entrypoint: s3-input-and-output-example | ||
| serviceAccountName: argo-workflow | ||
29 changes: 29 additions & 0 deletions
29
example_workflows/input_and_output_artifacts/input_and_output_custom_image.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| metadata: | ||
| name: input-and-output-artifact-custom-image | ||
| namespace: argo-workflows | ||
| spec: | ||
| templates: | ||
| - name: s3-input-and-output-custom-image-example | ||
| inputs: | ||
| artifacts: | ||
| - name: rscript | ||
| path: /tmp/test/generate_plots.R | ||
| s3: | ||
| key: generate_plots.R | ||
| outputs: | ||
| artifacts: | ||
| - name: routput | ||
| path: /tmp/routput | ||
| s3: | ||
| key: /plot_gen.tgz | ||
| container: | ||
| image: 10.0.50.50/library/rimg:latest | ||
| command: | ||
| - sh | ||
| - -c | ||
| args: | ||
| - mkdir /tmp/routput; Rscript /tmp/test/generate_plots.R | ||
| entrypoint: s3-input-and-output-custom-image-example | ||
| serviceAccountName: argo-workflow | ||
| imagePullSecrets: | ||
| - name: regcred |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| metadata: | ||
| name: create-pod-example | ||
| namespace: argo-workflows | ||
| spec: | ||
| templates: | ||
| - name: create-pod | ||
| resource: | ||
| action: create | ||
| manifest: | | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: create-curl-pod | ||
| namespace: argo-workflows | ||
| spec: | ||
| containers: | ||
| - name: main | ||
| image: alpine/curl | ||
| command: | ||
| - curl | ||
| args: | ||
| - "-s" | ||
| - "https://ipinfo.io" | ||
| entrypoint: create-pod | ||
| serviceAccountName: argo-workflow | ||
| ttlStrategy: | ||
| secondsAfterCompletion: 300 | ||
| podGC: | ||
| strategy: OnPodCompletion | ||
| deleteDelayDuration: 30s |
17 changes: 17 additions & 0 deletions
17
example_workflows/python_population_analysis/generate_csv.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/usr/bin/env python3 | ||
| from csv import DictWriter | ||
|
|
||
| from faker import Faker | ||
JimMadge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Faker.seed(36903) | ||
| fake = Faker(["en_GB", "fr_FR", "de_DE"]) | ||
|
|
||
| population = [fake.profile() for _ in range(5000)] | ||
|
|
||
| field_names = population[0].keys() | ||
| with open("./population.csv", "w", newline="") as csvfile: | ||
| writer = DictWriter(csvfile, field_names) | ||
|
|
||
| writer.writeheader() | ||
| for profile in population: | ||
| writer.writerow(profile) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pandas[performance, plot] |
1 change: 1 addition & 0 deletions
1
example_workflows/python_population_analysis/requirements_generate.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| faker |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/usr/bin/env python3 | ||
| import re | ||
| from decimal import Decimal | ||
| from enum import Enum, unique | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| import pandas as pd | ||
|
|
||
|
|
||
| @unique | ||
| class BloodGroup(Enum): | ||
| a_negative = "A-" | ||
| a_positive = "A+" | ||
| ab_negative = "AB-" | ||
| ab_positive = "AB+" | ||
| b_negative = "B-" | ||
| b_positive = "B+" | ||
| o_negative = "O-" | ||
| o_positive = "O+" | ||
|
|
||
|
|
||
| re_location = re.compile(r"\(Decimal\('(.*)'\), Decimal\('(.*)'\)\)") | ||
|
|
||
|
|
||
| def convert_location(location: str) -> tuple[Decimal, Decimal]: | ||
| match = re_location.match(location) | ||
| return (Decimal(match.group(1)), Decimal(match.group(2))) | ||
|
|
||
|
|
||
| df = pd.read_csv( | ||
| "./population.csv", | ||
| converters={ | ||
| "blood_group": BloodGroup, | ||
| "current_location": convert_location, | ||
| "website": eval, | ||
| }, | ||
| dtype={ | ||
| "job": str, | ||
| "company": str, | ||
| "ssn": str, | ||
| "residence": str, | ||
| "username": str, | ||
| "address": str, | ||
| "mail": str, | ||
| }, | ||
| parse_dates=["birthdate"], | ||
| header=0, | ||
| ) | ||
|
|
||
| ax = df["blood_group"].value_counts().plot.pie() | ||
| ax.get_figure().savefig("./blood_group.png") | ||
|
|
||
| plt.clf() | ||
|
|
||
| now = np.datetime64("now") | ||
| df["age"] = df["birthdate"].apply(lambda x: int((now - x).days / 365.25)) | ||
| ax = df["age"].plot.hist() | ||
| ax.get_figure().savefig("./age.png") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| metadata: | ||
| name: whoami | ||
| namespace: argo-workflows | ||
| spec: | ||
| serviceAccountName: argo-workflow | ||
| entrypoint: steps | ||
| templates: | ||
| - name: steps | ||
| steps: | ||
| - - name: whoami | ||
| template: whoami | ||
| - name: id | ||
| template: id | ||
| - name: whoami | ||
| container: | ||
| name: main | ||
| image: ubuntu:noble | ||
| command: | ||
| - whoami | ||
| - name: id | ||
| container: | ||
| name: main | ||
| image: ubuntu:noble | ||
| command: | ||
| - id | ||
| ttlStrategy: | ||
| secondsAfterCompletion: 300 | ||
| podGC: | ||
| strategy: OnPodCompletion | ||
| deleteDelayDuration: 300s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be a sensible way to generalise this kind of thing?
It would be good to not put the responsibility on the users to makes/find writable directories.
Could we provide templates that ensure the job runs in a tmp dir and has loops like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you wanting these to also be user-facing examples? Is this thinking ahead to what we've discussed about potentially locking down templates? I didn't realise these were really intended to exemplify that.
This was only intended to exemplify getting an artifact in and putting one out, not generalise to many output artifacts. This script just tars an entire directory and puts it in a single file in the default S3 bucket, so there is only one output and it doesn't need a loop.