Các bài trước chúng ta chỉ run 1 template 1 workflow … Nếu bạn muốn run nhiều template thì sao.
Chúng ta tiếp tục đẻ ra 1 khái niệm là Master Workflow.
Đầu tiên chúng ta cần 2 template:
apiVersion: argoproj.io/v1alpha1 kind: WorkflowTemplate metadata: name: wftmpl-dag spec: entrypoint: dag-templates templates: - name: dag-templates dag: tasks: - name: Task1 template: task-template - name: Task2 template: task-template dependencies: [Task1] - name: Task3 template: task-template dependencies: [Task1] - name: Task4 template: task-template dependencies: [Task2, Task3] - name: task-template script: image: python:3.8-slim command: - python source: | print("Nimtechnology - Task executed.")
và Template thứ 2:
apiVersion: argoproj.io/v1alpha1 kind: WorkflowTemplate metadata: name: wftmpl-loop spec: entrypoint: dag-template arguments: parameters: - name: message1 value: Task 1 is executed - name: message2 value: Task 2 is executed templates: - name: dag-template inputs: parameters: - name: message1 - name: message2 dag: tasks: - name: Task1 arguments: parameters: [{name: text, value: "{{inputs.parameters.message1}}"}] template: task-template - name: Task2 arguments: parameters: [{name: text, value: "{{inputs.parameters.message2}}"}] template: task-template - name: Task3 template: task-template dependencies: [Task1] arguments: parameters: - name: text value: "{{item}}" withItems: - Element1 - Element2 - Element3 - name: task-template inputs: parameters: - name: text script: image: python:3.8-slim command: - python source: | p = "{{inputs.parameters.text}}" print(p)
Tiếp đến là tạo 1 master:
apiVersion: argoproj.io/v1alpha1 kind: CronWorkflow metadata: name: cronwf-master spec: schedule: "0 * * * *" concurrentcyPolicy: "Replace" startingDeadLineSeconds: 0 workflowSpec: entrypoint: dag-master templates: - name: dag-master dag: tasks: - name: task-dag template: trigger-workflow arguments: parameters: - name: workflowtemplate value: wftmpl-dag - name: task-loop depends: task-dag.Succeeded template: trigger-workflow arguments: parameters: - name: workflowtemplate value: wftmpl-loop - name: trigger-workflow inputs: parameters: - name: workflowtemplate resource: action: create manifest: | apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: {{inputs.parameters.workflowtemplate}}- spec: workflowTemplateRef: name: {{inputs.parameters.workflowtemplate}} successCondition: status.phase == Succeeded failureCondition: status.phase in (Failed, Error)
Bạn thấy nó gọi 2 template và chạy 2 workflow.