✅️2025/5/31 Argo WorkflowsのTemplatesやる
Learn about different types of templates, including key types such as container and DAG.
https://killercoda.com/argoproj/course/argo-workflows/templates
template tag
Container Templateを実行
code:yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: container-
spec:
entrypoint: main
templates:
- name: main
container:
image: busybox
command: echo
args: "hello world"
$ argo submit --serviceaccount argo-workflow --watch container-workflow.yaml
λ argo submit
おる
https://gyazo.com/470147359f9a53f5a86b160249178eae
Logsを見ると hello worldと出てる
https://gyazo.com/6ab813ebf9ef1fb247487bc9c2c77464
Template tags (argo)を使う
code:yaml
- name: main
container:
image: busybox
command: echo
args: "hello {{workflow.name}}"
$ argo submit --serviceaccount argo-workflow --watch template-tag-workflow.yaml
$ argo logs @latest
出力
code:出力
template-tag-z6dcn: hello template-tag-z6dcn
うーん、まあわかるが、workflow.nameがグローバル変数であるのムズいなあmrsekut.icon
A data template allows you get data from storage (e.g. S3). This is useful when each item of data represents an item of work that needs doing.
と、あるが Core ConceptsにDataなんてないな
どっちが新しいんだろmrsekut.icon
DAG Templateを使う
code:yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-
spec:
entrypoint: main
templates:
- name: main
dag:
tasks:
- name: a
template: echo
- name: b
template: echo
dependencies:
- a
- name: echo
container:
image: busybox
command: echo
args: "hello world"
$ argo submit --serviceaccount argo-workflow --watch dag-workflow.yaml
結果
https://gyazo.com/e6c2df5455382558237b6c1d2c459fd4
aが終わってからbが実行されていることがわかる
Loops
withItems (argo)
code:yaml
dag:
tasks:
- name: print-message
template: echo
arguments:
parameters:
- name: message
value: "{{item}}"
withItems:
- "hello world"
- "goodbye world"
print-message タスクが
"hello world" と "goodbye world" の 2回実行される
"{{item}}"が↑これらに置き換わる
DAG Templateなので、これらは並行に実行される
意味はわかるが、なんでyml採用したん?という気持ちになるなmrsekut.icon
withSequence (argo)
code:yml
dag:
tasks:
- name: print-message
template: echo
arguments:
parameters:
- name: message
value: "{{item}}"
withSequence:
count: 5
0〜4 までの値で繰り返され、5個のPodが並列に実行される
Exit handler (argo)
onExit
あるタスクが終了した後に処理を実行したい場合に使う
タスクaの後にtidy-up templateを実行する例
code:yml
dag:
tasks:
- name: a
template: echo
onExit: tidy-up