본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

워크플로우 템플릿 (Workflow Templates)

원문 보기 위키 갱신

WorkflowTemplates는 클러스터 안에 살아 있는 Workflows의 정의예요. 자주 쓰는 템플릿 라이브러리를 만들어 직접 제출(v2.7 이상)하거나 여러분의 Workflows에서 참조해 재사용할 수 있게 해 줘요.

출처: Argo Workflows 문서

본문

v2.4 이상

소개 (Introduction)

WorkflowTemplates는 클러스터 안에 살아 있는 Workflows의 정의예요. 덕분에 자주 쓰는 템플릿 라이브러리를 만들어 두고, 직접 제출하거나(v2.7 이상) 여러분의 Workflows에서 참조하는 방식으로 재사용할 수 있어요.

WorkflowTemplate vs template

WorkflowTemplate과 template이라는 용어는 안타깝게도 이름이 겹쳐서 과거에 혼란을 낳았어요. 하지만 간단한 설명으로 각각의 뜻과 차이가 분명해질 거예요.

  • template(소문자)은 Workflow 안의 태스크이거나, (혼란스럽게도) WorkflowTemplate의 templates 필드 아래에 있는 태스크예요. Workflow를 정의할 때는 반드시 하나 이상(보통 그 이상)의 template을 정의해서 실행해야 해요. 이 template은 container, script, dag, steps, resource, suspend 타입이 될 수 있고, entrypoint나 다른 dag, step 템플릿에서 참조할 수 있어요.

두 개의 templates를 가진 Workflow 예제예요:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: steps-
spec:
  entrypoint: hello           # We reference our first "template" here

  templates:
  - name: hello               # The first "template" in this Workflow, it is referenced by "entrypoint"
    steps:                    # The type of this "template" is "steps"
    - - name: hello
        template: print-message # We reference our second "template" here
        arguments:
          parameters: [{name: message, value: "hello1"}]

  - name: print-message       # The second "template" in this Workflow, it is referenced by "hello"
    inputs:
      parameters:
      - name: message
    container:                # The type of this "template" is "container"
      image: busybox
      command: [echo]
      args: ["{{inputs.parameters.message}}"]
  • WorkflowTemplate은 클러스터 안에 살아 있는 Workflow의 정의예요. Workflow의 정의이므로 templates도 담고 있어요. 이 templates는 WorkflowTemplate 내부에서, 그리고 클러스터의 다른 Workflows와 WorkflowTemplates에서 참조할 수 있어요. 방법은 다른 WorkflowTemplates 참조하기를 보세요.

WorkflowTemplate 스펙 (Spec)

v2.7 이상

v2.7 이상에서는 WorkflowSpec의 모든 필드(priority만 예외로, 이것은 WorkflowSpec 자체에서 구성해야 해요)가 WorkflowTemplates에서 지원돼요. 기존의 어떤 Workflow든 kind: Workflow를 kind: WorkflowTemplate으로 바꾸면 WorkflowTemplate으로 변환할 수 있어요.

v2.4 – 2.6

v2.4 - v2.6의 WorkflowTemplates는 부분적인 Workflow 정의에 불과하고 templates와 arguments 필드만 지원해요.

이것은 v2.4 - v2.6에서 유효한 WorkflowTemplate이 아니에요(entrypoint 필드에 주목):

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: workflow-template-submittable
spec:
  entrypoint: print-message     # Fields other than "arguments" and "templates" not supported in v2.4 - v2.6
  arguments:
    parameters:
      - name: message
        value: hello world
  templates:
    - name: print-message
      inputs:
        parameters:
          - name: message
      container:
        image: busybox
        command: [echo]
        args: ["{{inputs.parameters.message}}"]

하지만 이것은 유효한 WorkflowTemplate이에요:

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: workflow-template-submittable
spec:
  arguments:
    parameters:
      - name: message
        value: hello world
  templates:
    - name: print-message
      inputs:
        parameters:
          - name: message
      container:
        image: busybox
        command: [echo]
        args: ["{{inputs.parameters.message}}"]

workflowMetadata로 워크플로우에 라벨/어노테이션 더하기

v2.10.2 이상

WorkflowTemplates에서 만들어지는 워크플로우에 라벨과/또는 어노테이션을 자동으로 더하려면 workflowMetadata를 쓰세요.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: workflow-template-submittable
spec:
  workflowMetadata:
    labels:
      example-label: example-value

파라미터 다루기 (Working with parameters)

WorkflowTemplate에서 파라미터를 다룰 때는 다음에 유의하세요:

  • 글로벌 파라미터를 다룰 때는 Workflow에서 글로벌 변수를 인스턴스화한 뒤 WorkflowTemplate에서 그 변수를 직접 참조할 수 있어요. 동작하는 예제가 아래에 있어요:
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: hello-world-template-global-arg
spec:
  templates:
    - name: hello-world
      container:
        image: busybox
        command: [echo]
        args: ["{{workflow.parameters.global-parameter}}"]
---
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: hello-world-wf-global-arg-
spec:
  entrypoint: print-message
  arguments:
    parameters:
      - name: global-parameter
        value: hello
  templates:
    - name: print-message
      steps:
        - - name: hello-world
            templateRef:
              name: hello-world-template-global-arg
              template: hello-world
  • 로컬 파라미터를 다룰 때는, 로컬 파라미터의 값이 WorkflowTemplate 안의 템플릿 정의에서 반드시 제공돼야 해요. 동작하는 예제가 아래에 있어요:
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: hello-world-template-local-arg
spec:
  templates:
    - name: hello-world
      inputs:
        parameters:
          - name: msg
            value: "hello world"
      container:
        image: busybox
        command: [echo]
        args: ["{{inputs.parameters.msg}}"]
---
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: hello-world-local-arg-
spec:
  entrypoint: print-message
  templates:
    - name: print-message
      steps:
        - - name: hello-world
            templateRef:
              name: hello-world-template-local-arg
              template: hello-world

다른 WorkflowTemplates 참조하기 (Referencing other WorkflowTemplates)

templateRef 필드를 써서 다른 WorkflowTemplates의 templates를 참조할 수 있어요(둘의 차이를 보세요). 같은 Workflow 안에서 다른 templates를 참조하듯이, steps나 dag 템플릿에서 하면 돼요.

steps 템플릿에서 참조하는 예제예요:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: workflow-template-hello-world-
spec:
  entrypoint: hello-world
  templates:
  - name: hello-world
    steps:                              # You should only reference external "templates" in a "steps" or "dag" "template".
      - - name: call-print-message
          templateRef:                  # You can reference a "template" from another "WorkflowTemplate" using this field
            name: workflow-template-1   # This is the name of the "WorkflowTemplate" CRD that contains the "template" you want
            template: print-message     # This is the name of the "template" you want to reference
          arguments:                    # You can pass in arguments as normal
            parameters:
            - name: message
              value: "hello world"

dag 템플릿으로도 똑같이 할 수 있어요:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: workflow-template-hello-world-
spec:
  entrypoint: hello-world
  templates:
  - name: hello-world
    dag:
      tasks:
        - name: call-print-message
          templateRef:
            name: workflow-template-1
            template: print-message
          arguments:
            parameters:
            - name: message
              value: "hello world"

WorkflowTemplate 스펙에서 Workflow 만들기 (Create Workflow from WorkflowTemplate Spec)

v2.9 이상

workflowTemplateRef를 써서 WorkflowTemplate 스펙으로 Workflow를 만들 수 있어요. 만들어진 Workflow에 인자를 전달하면, 그 인자는 워크플로우 템플릿의 인자와 병합(merge)돼요. entrypoint와 Workflow Arguments를 WorkflowTemplate에 전달하면서 WorkflowTemplate을 Workflow로 참조하는 예제예요:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: workflow-template-hello-world-
spec:
  entrypoint: print-message
  arguments:
    parameters:
      - name: message
        value: "from workflow"
  workflowTemplateRef:
    name: workflow-template-submittable

WorkflowTemplates의 entrypoint와 Workflow Arguments를 그대로 쓰면서 WorkflowTemplate을 Workflow로 참조하는 예제예요:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: workflow-template-hello-world-
spec:
  workflowTemplateRef:
    name: workflow-template-submittable

WorkflowTemplates 관리하기 (Managing WorkflowTemplates)

CLI

다음과 같이 예제 템플릿을 만들 수 있어요:

argo template create https://raw.githubusercontent.com/argoproj/argo-workflows/main/examples/workflow-template/templates.yaml

그다음 그 템플릿 중 하나로 워크플로우를 제출해요:

argo submit https://raw.githubusercontent.com/argoproj/argo-workflows/main/examples/workflow-template/hello-world.yaml

v2.7 이상

WorkflowTemplate을 Workflow로 제출해요:

argo submit --from workflowtemplate/workflow-template-submittable

파라미터를 넣어서 WorkflowTemplate을 Workflow로 제출해야 한다면:

argo submit --from workflowtemplate/workflow-template-submittable -p message=value1

이 방식으로 전달하는 파라미터는 WorkflowTemplate이 선언하지 않아도 돼요. 템플릿은 선언하지 않은 파라미터에 대해 {{workflow.parameters.<name>}}을 참조할 수 있어요. 파라미터에 합리적인 기본값이 없고 항상 제출 시점에 값을 넣고 싶을 때 유용해요.

kubectl

kubectl apply -f와 kubectl get wftmpl을 쓰세요.

Argo CD를 통한 GitOps

WorkflowTemplate 리소스는 Argo CD로 GitOps 방식으로 관리할 수 있어요.

UI

WorkflowTemplate 리소스는 UI로도 관리할 수 있어요.

UI에서 WorkflowTemplate을 제출할 때 드롭다운 목록 선택을 켜려면, enum 아래에 옵션을 지정하면 돼요.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: workflow-template-with-enum-values
spec:
  entrypoint: argosay
  arguments:
    parameters:
      - name: message
        value: one
        enum:
          -   one
          -   two
          -   three
  templates:
    - name: argosay
      inputs:
        parameters:
          - name: message
            value: '{{workflow.parameters.message}}'
      container:
        name: main
        image: 'argoproj/argosay:v2'
        command:
          - /argosay
        args:
          - echo
          - '{{inputs.parameters.message}}'

더 알아보기 (Learn more)

  • template은 Workflow/WorkflowTemplate 안의 개별 태스크이고, WorkflowTemplate은 클러스터에 저장되는 Workflow 정의예요.
  • workflowTemplateRef로 제출하면 전달한 인자가 템플릿 인자와 병합돼요.
  • UI 제출 화면에 드롭다운을 쓰고 싶다면 파라미터에 enum 옵션을 지정하세요.