Skip to content
Draft
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
56 changes: 56 additions & 0 deletions example_workflows/curl_external/workflow_template.yaml
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 example_workflows/input_and_output_artifacts/generate_plots.R
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)
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")
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
Comment on lines +15 to +18
Copy link
Member Author

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

outputs:
  artifacts:
{{% for output in outputs %}}
    - name: {{ output.name }}
      path: /tmp/{{job_id}}/{{ output.filename }}
      s3:
        key : {{ output.filename }}
{% endfor %}

Copy link
Contributor

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.

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
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
30 changes: 30 additions & 0 deletions example_workflows/k8_resources/workflow_template.yaml
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 example_workflows/python_population_analysis/generate_csv.py
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

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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pandas[performance, plot]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
faker
59 changes: 59 additions & 0 deletions example_workflows/python_population_analysis/script.py
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")
30 changes: 30 additions & 0 deletions example_workflows/whoami/workflow_template.yaml
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
9 changes: 8 additions & 1 deletion infra/fridge/Pulumi.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ config:
- https://graph.microsoft.com/Group.Read.All
- email
fridge:argo_fqdn_prefix: argo
fridge:base_fqdn: fridge.develop.turingsafehaven.ac.uk
fridge:azure_disk_encryption_set: fridge-disk-encryption-set
fridge:azure_subscription_id: "36cfe11d-bfcd-4dce-9b70-c3905a4f3d01"
fridge:azure_resource_group: fridge-one
fridge:base_fqdn: aks.fridge.develop.turingsafehaven.ac.uk
fridge:harbor_admin_password:
secure: v1:3+jAcVhe/3xj57pG:EEgytR6DgCOZqJrJsoHyLNEwWPOLxW5/
fridge:harbor_ip: 10.0.50.50
Expand All @@ -29,4 +32,8 @@ config:
pulumi:autonaming:
mode: verbatim
kubernetes:context: cluster
fridge:fridge_api_admin:
secure: v1:nn2LgdxeGCv5c0Lv:pr4uv23iVaHqcZ9cq0FqZnNtKNaRCciG
fridge:fridge_api_password:
secure: v1:x/BGXr+SaRLFlvZf:KN9s8Tu7wbRc/Pk3yOBv6Jp0VHsjp64UXZw=
encryptionsalt: v1:UMTR46NTSCc=:v1:dRO4tTAutzORsIcQ:BEEfHoJF1QYioY1S3mfhAsEth2I7AA==
2 changes: 1 addition & 1 deletion infra/fridge/Pulumi.local-k3s.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
encryptionsalt: v1:ykjzeFXxJjM=:v1:lelRqe5sSoksTSch:PoR4OU+t4z2i7P1rWQorCrsPlKOT4w==
config:
kubernetes:context: default
fridge:tls_environment: staging
fridge:tls_environment: development
fridge:k8s_env: K3s
fridge:argo_fqdn_prefix: argo
fridge:base_fqdn: fridge.internal
Expand Down
12 changes: 11 additions & 1 deletion infra/fridge/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pulumi_kubernetes.batch.v1 import CronJobPatch, CronJobSpecPatchArgs
from pulumi_kubernetes.core.v1 import NamespacePatch
from pulumi_kubernetes.meta.v1 import ObjectMetaPatchArgs
from pulumi_kubernetes.yaml import ConfigFile
from pulumi_kubernetes.yaml import ConfigFile, ConfigGroup

import components
from enums import K8sEnvironment, PodSecurityStandard, TlsEnvironment
Expand Down Expand Up @@ -148,6 +148,16 @@ def patch_namespace(name: str, pss: PodSecurityStandard) -> NamespacePatch:
),
)

argo_example = ConfigGroup(
"argo-example",
files=["./k8s/argo_workflows/examples/*.yaml"],
opts=ResourceOptions(
depends_on=[
argo_workflows,
]
),
)

# Harbor
harbor = components.ContainerRegistry(
"harbor",
Expand Down
Loading
Loading