✅️2025/5/31 Argo WorkflowsのTemplatesやる
Learn about different types of templates, including key types such as container and DAG.
template tag
code:yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: container-
spec:
entrypoint: main
templates:
- name: main
container:
image: busybox
$ argo submit --serviceaccount argo-workflow --watch container-workflow.yaml
おる
https://gyazo.com/470147359f9a53f5a86b160249178eae
Logsを見ると hello worldと出てる
https://gyazo.com/6ab813ebf9ef1fb247487bc9c2c77464
code:yaml
- name: main
container:
image: busybox
$ 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.
どっちが新しいんだろmrsekut.icon
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
$ argo submit --serviceaccount argo-workflow --watch dag-workflow.yaml
結果
https://gyazo.com/e6c2df5455382558237b6c1d2c459fd4
aが終わってからbが実行されていることがわかる
Loops
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}}"が↑これらに置き換わる
意味はわかるが、なんでyml採用したん?という気持ちになるなmrsekut.icon
code:yml
dag:
tasks:
- name: print-message
template: echo
arguments:
parameters:
- name: message
value: "{{item}}"
withSequence:
count: 5
0〜4 までの値で繰り返され、5個のPodが並列に実行される
onExit
あるタスクが終了した後に処理を実行したい場合に使う
タスクaの後にtidy-up templateを実行する例
code:yml
dag:
tasks:
- name: a
template: echo
onExit: tidy-up