{"id":2531,"date":"2023-11-11T17:25:37","date_gmt":"2023-11-11T09:25:37","guid":{"rendered":"http:\/\/yaochenkun.site\/?p=2531"},"modified":"2024-11-23T15:52:40","modified_gmt":"2024-11-23T07:52:40","slug":"argo-workflows","status":"publish","type":"post","link":"http:\/\/yaochenkun.site\/index.php\/2023\/11\/11\/argo-workflows\/","title":{"rendered":"Argo Workflows \u5de5\u4f5c\u6d41\u5f15\u64ce"},"content":{"rendered":"<h3>\u5f15\u8a00<\/h3>\n<p>\u201c\u5de5\u4f5c\u6d41\u201d\u662f\u5728\u7cfb\u7edf\u5f00\u53d1\u4e2d\u7ecf\u5e38\u88ab\u63d0\u53ca\u7684\u4e00\u4e2a\u6982\u5ff5\uff0c\u6bd4\u5982\u673a\u5668\u5b66\u4e60\u5e73\u53f0\u91cc\u9700\u8981\u7528\u5de5\u4f5c\u6d41\u4e32\u8054\u4ece\u5efa\u6a21\u3001\u8bad\u7ec3\u5230\u9884\u6d4b\u7684\u5168\u6d41\u7a0b\uff0cCICD\u7cfb\u7edf\u9700\u8981\u7528\u5de5\u4f5c\u6d41\u6253\u901a\u4ece\u5f00\u53d1\u3001\u6784\u5efa\u518d\u5230\u90e8\u7f72\u7684\u94fe\u8def\uff0c\u529e\u516c\u81ea\u52a8\u5316\u4e2d\u4e5f\u7ecf\u5e38\u8981\u7528\u5230\u5de5\u4f5c\u6d41\u5b9e\u73b0\u9010\u7ea7\u5ba1\u6279\u7b49\uff0c\u56e0\u6b64\u5f88\u6709\u5fc5\u8981\u4e3a\u9879\u76ee\u5f15\u5165\u4e00\u4e2a\u7b80\u5355\u6613\u7528\uff0c\u53c8\u5177\u6709\u4e00\u5b9a\u62bd\u8c61\u5ea6\u548c\u6269\u5c55\u6027\u7684\u5de5\u4f5c\u6d41\u6846\u67b6\u2014\u2014Argo Workflows\uff0c\u5b83\u662f\u4e00\u4e2a\u57fa\u4e8e Kubernetes \u7684\u5de5\u4f5c\u6d41\u7ec4\u4ef6\uff0c\u901a\u5e38\u7528\u6765\u7f16\u6392\u8282\u70b9\uff08\u4efb\u52a1\uff09\u4f9d\u8d56\u5173\u7cfb\uff0c\u7136\u540e\u8c03\u5ea6\u8fd9\u4e9b\u8282\u70b9\uff0c\u8ba9\u4ed6\u4eec\u4ee5\u4e32\u884c\u6216\u5e76\u884c\u65b9\u5f0f\u8fd0\u884c\u3002\u672c\u6587\u60f3\u4ece\u5f00\u53d1\u8005\u89d2\u5ea6\u4ecb\u7ecd\u4e00\u4e0b Argo Workflows \u7684\u603b\u4f53\u6846\u67b6\u4e0e\u6838\u5fc3\u80fd\u529b\uff0c\u8fd8\u6709\u4e00\u4e9b\u5b9e\u9645\u5de5\u4f5c\u4e2d\u5f88\u5bb9\u6613\u7528\u5230\u7684\u7279\u6027\u3002<\/p>\n<h3>\u603b\u4f53\u67b6\u6784<\/h3>\n<p>Argo Workflows \u9075\u5faa Kubernetes \u7684\u5f00\u53d1\u8303\u5f0f\uff0c\u603b\u4f53\u67b6\u6784\u8fd8\u662f\u6bd4\u8f83\u6e05\u6670\u7684\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2539\" src=\"http:\/\/yaochenkun.site\/wp-content\/uploads\/2023\/11\/argo-wf-overview.jpeg\" alt=\"\" width=\"661\" height=\"416\" \/><\/p>\n<p>\u4ece\u56fe\u4e2d\u53ef\u4ee5\u770b\u5230\u4e0b\u9762\u51e0\u4e2a\u6838\u5fc3\u7ec4\u4ef6\uff1a<\/p>\n<ul>\n<li>Workflow CRD\uff1aWorkflow \u8d44\u6e90\u63cf\u8ff0\u6587\u4ef6\uff0c\u6587\u4ef6\u5b9a\u4e49\u4e86 Workflow \u5185\u5404\u6267\u884c\u8282\u70b9\u7684\u4f9d\u8d56\u5173\u7cfb\u3001\u4e32\/\u5e76\u884c\u884c\u4e3a\u3001\u5165\u53c2\u51fa\u53c2\u3001\u9000\u51fa\u56de\u8c03\u7b49\u3002<\/li>\n<li>Workflow Controller\uff1aWorkflow \u8c03\u5ea6\u4e0e\u751f\u547d\u5468\u671f\u7ba1\u7406\u63a7\u5236\u5668\uff0c\u8d1f\u8d23\u76d1\u89c6 Workflow CR \u7684\u521b\u5efa\u3001\u66f4\u65b0\u4e0e\u5220\u9664\uff0c\u5e76\u63a7\u5236 Workflow \u5b9e\u4f8b\u53ca\u6bcf\u4e2a\u5b9e\u4f8b\u4e0b\u8282\u70b9\u7684\u8fd0\u884c\u3002<\/li>\n<li>Argo UI\uff1a\u63d0\u4f9b Web GUI \u9875\u9762\u5de5\u5177\uff0c\u53ef\u89c6\u5316\u89c2\u6d4b Workflow \u5b9e\u4f8b\u7684\u8fd0\u884c\u52a8\u6001\uff0c\u4ee5\u53ca\u4e00\u4e9b\u8fd0\u7ef4\u5de5\u5177\u3002<\/li>\n<li>Argo Cli\uff1a\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u66f4\u52a0\u65b9\u4fbf\u7b80\u6d01\u5730\u5bf9 Workflow \u5b9e\u4f8b\u8fdb\u884c\u521b\u5efa\u3001\u67e5\u770b\u3001\u5220\u9664\u7b49\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p>Argo UI \u548c Arg Cli \u4f5c\u4e3a\u5ba2\u6237\u7aef\u4e3a\u7528\u6237\u63d0\u4f9b\u4e86\u66f4\u4fbf\u6377\u7684\u8bbf\u95ee\u5165\u53e3\uff0c\u800c Workflow CRD \u548c Workflow Controller \u4f5c\u4e3a\u670d\u52a1\u7aef\u63d0\u4f9b\u4e86\u63a7\u5236 Workflow \u5b9e\u4f8b\u8c03\u5ea6\u3001\u8fd0\u8f6c\u4e0e\u7ba1\u7406\u7684\u80fd\u529b\uff0c\u6700\u7ec8 Workflow \u5185\u6bcf\u4e2a\u8282\u70b9\u5c06\u4f5c\u4e3a\u6838\u5fc3\u7684\u4e1a\u52a1\u6267\u884c\u5355\u5143\uff0c\u4ee5 Kubernetes \u539f\u751f Pod \u5f62\u5f0f\u8fd0\u884c\u3002<\/p>\n<h3>Workflow CRD<\/h3>\n<p>Workflow CRD \u9075\u5faa Kubernetes CRD \u6807\u51c6\u89c4\u8303\u5b9a\u4e49\uff0c\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a\u662f\u63cf\u8ff0 Workflow \u914d\u7f6e\u7684\u4e00\u4efd\u6587\u4ef6\uff0c\u91cc\u9762\u5305\u542b\u4e86\u5bf9 Workflow \u672c\u8eab\u7684\u914d\u7f6e\u5b9a\u4e49\uff0c\u53c8\u5305\u542b\u4e86\u5bf9\u6bcf\u4e2a\u8fd0\u884c\u8282\u70b9\u53ca\u5b83\u4eec\u4e4b\u95f4\u4f9d\u8d56\u5173\u7cfb\u7684\u914d\u7f6e\u5b9a\u4e49\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u6700\u7b80\u5355\u7684 Workflow CR\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">apiVersion: argoproj.io\/v1alpha1\r\nkind: Workflow                  # new type of k8s spec\r\nmetadata:\r\n  generateName: hello-world-    # name of the workflow spec\r\nspec:\r\n  entrypoint: whalesay          # invoke the whalesay template\r\n  templates:\r\n    - name: whalesay              # name of the template\r\n      container:\r\n        image: docker\/whalesay\r\n        command: [ cowsay ]\r\n        args: [ \"hello world\" ]\r\n        resources: # limit the resources\r\n          limits:\r\n            memory: 32Mi\r\n            cpu: 100m<\/pre>\n<p>Workflow CRD \u91cc\u5f88\u91cd\u8981\u7684\u4e00\u4e2a\u6982\u5ff5\u662f templates\uff0c\u5b83\u7528\u6765\u63cf\u8ff0\u8fd9\u4e2a\u5de5\u4f5c\u6d41\u4e0b\u8282\u70b9\u7684\u6267\u884c\u5185\u5bb9\u4e0e\u53c2\u6570\uff0c\u4ee5\u53ca\u8282\u70b9\u4e0e\u8282\u70b9\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u4e32\u884c\u8fd8\u662f\u5e76\u884c\u6267\u884c\u3002templates \u6709\u4e09\u79cd\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>Container\uff1a\u4e0d\u53ef\u518d\u7ec6\u5206\u7684\u539f\u5b50\u7c7b\u578b template\uff0c\u4e5f\u53ef\u4ee5\u7406\u89e3\u4e3a\u5fc5\u987b\u8981\u5b9a\u4e49\u67d0\u4e2a\u8282\u70b9\u5bf9\u5e94\u7684 container \u6267\u884c\u884c\u4e3a\u7684 template\uff08\u6bd4\u5982\u4e0a\u9762\u7684 whalesay \u5c31\u662f\uff09\uff0c\u5305\u62ec\u5bb9\u5668\u540d\u79f0\u3001\u8d44\u6e90\u5b9a\u4e49\u3001\u955c\u50cf\u3001\u542f\u52a8\u547d\u4ee4\u3001\u6267\u884c\u53c2\u6570\u7b49\uff0c\u4e0e\u6211\u4eec\u5b9a\u4e49 pod \u91cc\u7684 container \u65e0\u5f02\u3002<\/li>\n<li>Steps\uff1a\u5206\u6b65\u6267\u884c\u7c7b\u578b\u7684 template\u3002\u8fd9\u79cd template \u5c06\u4e00\u7cfb\u5217\u8282\u70b9\u4ee5\u4e32\u884c\u6216\u5e76\u884c\u65b9\u5f0f\u7f16\u6392\uff0c\u5e76\u6307\u5b9a\u6bcf\u4e2a\u8282\u70b9\u7528\u5230\u7684 template\uff0c\u8fd9\u4e2a template \u901a\u5e38\u5c31\u5f15\u7528 container \u7c7b\u578b\u7684 template\uff0c\u4f46\u5982\u679c\u6709\u590d\u6742\u573a\u666f\uff0c\u4e5f\u652f\u6301\u5d4c\u5957\u5f15\u7528 steps \u6216 dag \u7c7b\u578b\u7684 template\u3002\u5173\u4e8e steps \u540e\u9762\u4f1a\u7ed9\u51fa\u4e00\u4e2a\u793a\u4f8b\u8bb2\u89e3\u3002<\/li>\n<li>DAG\uff1a\u4f9d\u8d56\u5173\u7cfb\u7c7b\u578b\u7684 template\u3002\u8fd9\u79cd template \u66f4\u52a0\u7075\u6d3b\uff0c\u662f\u4e0a\u9762 steps \u7684\u53e6\u5916\u4e00\u79cd\u8868\u793a\u65b9\u5f0f\uff0c\u5b83\u9488\u5bf9\u6bcf\u4e2a\u8282\u70b9\u5b9a\u4e49\u4e86\u4ed6\u4eec\u6240\u4f9d\u8d56\u7684\u4e0a\u6e38\u8282\u70b9\u540d\u79f0\uff0c\u6216\u4e32\u884c\u6216\u5e76\u884c\u6267\u884c\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684 template \u540c\u4e0a\u53ef\u4ee5\u4efb\u610f\u5f15\u7528\u3002\u5173\u4e8e dag \u540e\u9762\u4e5f\u4f1a\u7ed9\u51fa\u4e00\u4e2a\u793a\u4f8b\u8bb2\u89e3\u3002<\/li>\n<\/ul>\n<h3>Arguments<\/h3>\n<p>\u4e0a\u9762\u5c55\u793a\u4e86\u4e00\u4e2a\u6700\u7b80\u5355\u7684 container template \u7528\u6cd5\uff0c\u4f46\u65e2\u7136\u88ab\u53eb\u505a\u6a21\u7248\uff0c\u90a3\u6bcf\u4e2a\u8282\u70b9\u603b\u4e0d\u80fd\u90fd\u6267\u884c\u4e00\u6837\u7684\u5185\u5bb9\u5427\uff0c\u56e0\u6b64 Argo Workflows \u8fd8\u63d0\u4f9b\u4e86\u5728 template.inputs \u5b9a\u4e49\u53c2\u6570\u7684\u529f\u80fd\uff0c\u7136\u540e\u7528 {{ inputs.parameters.xxx }} \u6765\u5f15\u7528\u53c2\u6570\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">apiVersion: argoproj.io\/v1alpha1\r\nkind: Workflow\r\nmetadata:\r\n  generateName: hello-world-parameters-\r\nspec:\r\n  # invoke the whalesay template with\r\n  # \"hello world\" as the argument\r\n  # to the message parameter\r\n  entrypoint: whalesay\r\n  templates:\r\n  - name: whalesay\r\n    inputs:\r\n      parameters:\r\n      - name: message       # parameter declaration\r\n        value: hello world\r\n    container:\r\n      # run cowsay with that message input parameter as args\r\n      image: docker\/whalesay\r\n      command: [cowsay]\r\n      args: [\"{{inputs.parameters.message}}\"]<\/pre>\n<p>\u4f46\u5982\u679c\u591a\u4e2a template \u90fd\u60f3\u5f15\u7528\u540c\u4e00\u4e2a\u53c2\u6570\uff0c\u90a3\u4e48\u53ef\u4ee5\u7701\u7565 inputs \u8fd9\u5757\uff0c\u76f4\u63a5\u5728 spec.arguments \u5b9a\u4e49\u53c2\u6570\uff0c\u7136\u540e\u5728 template \u4e2d\u7528 {{ workflow.parameters.xxx }} \u6765\u5f15\u7528\u53c2\u6570\uff0c\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">apiVersion: argoproj.io\/v1alpha1\r\nkind: Workflow\r\nmetadata:\r\n  generateName: global-parameters-\r\nspec:\r\n  entrypoint: A\r\n  arguments:\r\n    parameters:\r\n    - name: log-level\r\n      value: INFO\r\n\r\n  templates:\r\n  - name: A\r\n    container:\r\n      image: containerA\r\n      env:\r\n      - name: LOG_LEVEL\r\n        value: \"{{workflow.parameters.log-level}}\"\r\n      command: [runA]\r\n  - name: B\r\n    container:\r\n      image: containerB\r\n      env:\r\n      - name: LOG_LEVEL\r\n        value: \"{{workflow.parameters.log-level}}\"\r\n      command: [runB]<\/pre>\n<h3>Steps Template<\/h3>\n<p>Steps Template \u5176\u5b9e\u5f88\u597d\u7406\u89e3\uff0c\u5c31\u662f\u5f53\u4f60\u8981\u7f16\u6392\u4e00\u4e2a Workflow \u4e0b\u5404\u8282\u70b9\u7684\u6267\u884c\u987a\u5e8f\u548c\u4f9d\u8d56\u5173\u7cfb\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u7528\u5b83\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">apiVersion: argoproj.io\/v1alpha1\r\nkind: Workflow\r\nmetadata:\r\n  generateName: steps-\r\nspec:\r\n  entrypoint: hello-hello-hello\r\n\r\n  # This spec contains two templates: hello-hello-hello and whalesay\r\n  templates:\r\n  - name: hello-hello-hello\r\n    # Instead of just running a container\r\n    # This template has a sequence of steps\r\n    steps:\r\n    - - name: hello1            # hello1 is run before the following steps\r\n        template: whalesay\r\n        arguments:\r\n          parameters:\r\n          - name: message\r\n            value: \"hello1\"\r\n    - - name: hello2a           # double dash =&gt; run after previous step\r\n        template: whalesay\r\n        arguments:\r\n          parameters:\r\n          - name: message\r\n            value: \"hello2a\"\r\n      - name: hello2b           # single dash =&gt; run in parallel with previous step\r\n        template: whalesay\r\n        arguments:\r\n          parameters:\r\n          - name: message\r\n            value: \"hello2b\"\r\n\r\n  # This is the same template as from the previous example\r\n  - name: whalesay\r\n    inputs:\r\n      parameters:\r\n      - name: message\r\n    container:\r\n      image: docker\/whalesay\r\n      command: [cowsay]\r\n      args: [\"{{inputs.parameters.message}}\"]<\/pre>\n<p>\u4ece\u4e0a\u9762\u53ef\u4ee5\u770b\u51fa\u5b9a\u4e49\u4e86\u4e00\u4e2a\u65b0\u7684\u53eb\u505a hello-hello-hello \u7684 Steps Template\uff0c\u5176\u4e2d\u53cc\u6a2a\u7ebf \u201c- -\u201d \u8868\u793a\u6b65\u9aa4\u81ea\u4e0a\u800c\u4e0b\u3001\u4e32\u884c\u6267\u884c\uff0c\u800c\u5355\u6a2a\u7ebf \u201c-\u201d \u8868\u793a\u540c\u7ea7\u6b65\u9aa4\u5e76\u884c\u6267\u884c\u3002\u4e0b\u9762\u662f\u7528 Argo Cli \u67e5\u770b\u5f97\u5230\u7684\u8fd9\u4e2a Workflow \u5b9e\u4f8b\u7684\u5de5\u4f5c\u72b6\u6001\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">STEP            TEMPLATE           PODNAME                 DURATION  MESSAGE\r\n \u2714 steps-z2zdn  hello-hello-hello\r\n \u251c\u2500\u2500\u2500\u2714 hello1   whalesay           steps-z2zdn-27420706    2s\r\n \u2514\u2500\u252c\u2500\u2714 hello2a  whalesay           steps-z2zdn-2006760091  3s\r\n   \u2514\u2500\u2714 hello2b  whalesay           steps-z2zdn-2023537710  3s<\/pre>\n<h3>DAG Template<\/h3>\n<p>DAG Template \u5176\u5b9e\u662f\u4e0e Steps Template \u7b49\u4ef7\u7684\u53e6\u5916\u4e00\u79cd\u4e66\u5199\u65b9\u5f0f\uff0c\u53ea\u662f\u5b83\u5728\u63cf\u8ff0\u4f9d\u8d56\u5173\u7cfb\u7684\u65f6\u5019\u66f4\u52a0\u7cbe\u786e\uff0c\u6bcf\u4e2a\u8282\u70b9\u76f4\u63a5\u6307\u5b9a\u5b83\u6240\u4f9d\u8d56\u7684\u4e0a\u6e38\u8282\u70b9\u540d\u5b57\uff0c\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">apiVersion: argoproj.io\/v1alpha1\r\nkind: Workflow\r\nmetadata:\r\n  generateName: dag-diamond-\r\nspec:\r\n  entrypoint: diamond\r\n  templates:\r\n  - name: echo\r\n    inputs:\r\n      parameters:\r\n      - name: message\r\n    container:\r\n      image: alpine:3.7\r\n      command: [echo, \"{{inputs.parameters.message}}\"]\r\n  - name: diamond\r\n    dag:\r\n      tasks:\r\n      - name: A\r\n        template: echo\r\n        continueOn:\r\n          error: true\r\n          failed: true\r\n        arguments:\r\n          parameters: [{name: message, value: A}]\r\n      - name: B\r\n        dependencies: [A]\r\n        template: echo\r\n        arguments:\r\n          parameters: [{name: message, value: B}]\r\n      - name: C\r\n        dependencies: [A]\r\n        template: echo\r\n        arguments:\r\n          parameters: [{name: message, value: C}]\r\n      - name: D\r\n        dependencies: [B, C]\r\n        template: echo\r\n        arguments:\r\n          parameters: [{name: message, value: D}]<\/pre>\n<p>\u4ece\u4e0a\u9762\u53ef\u4ee5\u770b\u5230\uff0cDAG Template \u5927\u591a\u914d\u7f6e\u4e0e\u4e4b\u524d\u7684\u90fd\u4e00\u6837\uff0c\u6bd4\u8f83\u5173\u952e\u7684\u4e00\u9879\u914d\u7f6e\u662f\u8282\u70b9\u7684 dependencies\uff0c\u91cc\u9762\u6307\u5b9a\u4e86\u8282\u70b9\u6240\u4f9d\u8d56\u7684\u5176\u4ed6\u8282\u70b9\u7684\u540d\u79f0\u3002\u5176\u4e2d task A \u8bbe\u7f6e\u4e86\u53c2\u6570 continueOn\uff0c\u8fd9\u8868\u660e\u5f53\u8fd9\u4e2a\u8282\u70b9\u8fd0\u884c\u4ea7\u751f Failed \u6216 Error \u7684\u65f6\u5019\uff0c\u90fd\u4e0d\u4f1a\u5bfc\u81f4\u6574\u4e2a Workflow \u5b9e\u4f8b\u76f4\u63a5\u5931\u8d25\uff0c\u800c\u4f1a\u7ee7\u7eed\u8fd0\u884c\u4e0b\u9762\u7684\u8282\u70b9\uff0c\u4f46\u4e0b\u9762\u7684\u8282\u70b9\u5176\u5b9e\u53c8\u4f9d\u8d56\u8282\u70b9 A\uff0c\u56e0\u6b64\u8fd9\u79cd\u8bbe\u7f6e\u65b9\u6cd5\u662f\u81ea\u76f8\u77db\u76fe\u7684\uff0c\u4ec5\u9002\u5408\u4e00\u4e9b\u7279\u6b8a\u7684\u4e1a\u52a1\u573a\u666f\u4f7f\u7528\u3002<\/p>\n<h3>RetryStrategy<\/h3>\n<p>\u8282\u70b9\u6267\u884c\u7684\u65f6\u5019\u96be\u514d\u4f1a\u56e0\u4e3a\u7279\u6b8a\u539f\u56e0\u5931\u8d25\uff0cWorkflow \u4e3a\u6b64\u652f\u6301\u4e86\u91cd\u8bd5\u7b56\u7565 retryStrategy\uff0c\u53ef\u4ee5\u5b9a\u4e49\u5728\u5931\u8d25\u7684\u65f6\u5019\u662f\u5426\u91cd\u8bd5\u3001\u91cd\u8bd5\u51e0\u6b21\u7b49\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\"># This example demonstrates the use of retry back offs\r\napiVersion: argoproj.io\/v1alpha1\r\nkind: Workflow\r\nmetadata:\r\n  generateName: retry-backoff-\r\nspec:\r\n  entrypoint: retry-backoff\r\n  templates:\r\n  - name: retry-backoff\r\n    retryStrategy:\r\n      limit: 10\r\n      retryPolicy: \"Always\"\r\n      backoff:\r\n        duration: \"1\"      # Must be a string. Default unit is seconds. Could also be a Duration, e.g.: \"2m\", \"6h\", \"1d\"\r\n        factor: 2\r\n        maxDuration: \"1m\"  # Must be a string. Default unit is seconds. Could also be a Duration, e.g.: \"2m\", \"6h\", \"1d\"\r\n      affinity:\r\n        nodeAntiAffinity: {}\r\n    container:\r\n      image: python:alpine3.6\r\n      command: [\"python\", -c]\r\n      # fail with a 66% probability\r\n      args: [\"import random; import sys; exit_code = random.choice([0, 1, 1]); sys.exit(exit_code)\"]\r\n<\/pre>\n<ul>\n<li>limit\uff1a\u5bb9\u5668\u5931\u8d25\u65f6\u6700\u5927\u91cd\u8bd5\u6b21\u6570<\/li>\n<li>retryPolicy\uff1a\u5bb9\u5668\u5728\u4f55\u79cd\u5931\u8d25\u573a\u666f\u4e0b\u8fdb\u884c\u91cd\u8bd5\uff0c\u5982OnFailure(default), OnError, Always, OnTransientError<\/li>\n<li>backoff\uff1a\u6bcf\u6b21\u91cd\u8bd5\u4e4b\u95f4\u65f6\u95f4\u95f4\u9694\u7684\u8870\u51cf\u914d\u7f6e\n<ul>\n<li>duration\uff1a\u8d77\u59cb\u65f6\u95f4\u95f4\u9694<\/li>\n<li>factor\uff1a\u6bcf\u6b21\u91cd\u8bd5\u7684\u65f6\u95f4\u95f4\u9694\u4e3a\u524d\u4e00\u6b21\u7684\u51e0\u500d<\/li>\n<li>maxDuration\uff1a\u6700\u5927\u65f6\u95f4\u95f4\u9694<\/li>\n<\/ul>\n<\/li>\n<li>affinity\n<ul>\n<li>nodeAntiAffinity\uff1a\u8282\u70b9\u53cd\u4eb2\u548c\u8bbe\u7f6e\uff0c\u907f\u514d\u6bcf\u6b21\u91cd\u8bd5\u8c03\u5ea6\u5230\u540c\u4e00\u8282\u70b9<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>Exit Handler<\/h3>\n<p>\u5f53\u4e00\u4e2a Workflow \u8fd0\u884c\u7ed3\u675f\u540e\u5982\u679c\u5e0c\u671b\u505a\u4e00\u4e9b\u4e8b\u60c5\uff0c\u90a3\u4e48 Exit Handler \u5c31\u53ef\u4ee5\u6d3e\u4e0a\u7528\u573a\u3002\u4e00\u4e9b\u5e38\u89c1\u573a\u666f\u6709\uff1a<\/p>\n<ul>\n<li>\u53d1\u9001\u6d88\u606f\u901a\u77e5<\/li>\n<li>\u91cd\u65b0\u63d0\u4ea4 Workflow \u6216 \u63d0\u4ea4\u4e00\u4e2a\u65b0\u7684 Workflow<\/li>\n<li>\u6e05\u7406\u8be5 Workflow \u4ea7\u751f\u7684\u4e34\u65f6\u6570\u636e<\/li>\n<li>\u4e0a\u62a5\u8be5 Workflow \u7684\u5b8c\u6210\u72b6\u6001\u7ed9\u6570\u636e\u5e93<\/li>\n<\/ul>\n<p>Exit Handler \u7684\u5b9a\u4e49\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">apiVersion: argoproj.io\/v1alpha1\r\nkind: Workflow\r\nmetadata:\r\n  generateName: exit-handlers-\r\nspec:\r\n  entrypoint: intentional-fail\r\n  onExit: exit-handler                  # invoke exit-handler template at end of the workflow\r\n  templates:\r\n  # primary workflow template\r\n  - name: intentional-fail\r\n    container:\r\n      image: alpine:latest\r\n      command: [sh, -c]\r\n      args: [\"echo intentional failure; exit 1\"]\r\n\r\n  # Exit handler templates\r\n  # After the completion of the entrypoint template, the status of the\r\n  # workflow is made available in the global variable {{workflow.status}}.\r\n  # {{workflow.status}} will be one of: Succeeded, Failed, Error\r\n  - name: exit-handler\r\n    steps:\r\n    - - name: notify\r\n        template: send-email\r\n      - name: celebrate\r\n        template: celebrate\r\n        when: \"{{workflow.status}} == Succeeded\"\r\n      - name: cry\r\n        template: cry\r\n        when: \"{{workflow.status}} != Succeeded\"\r\n  - name: send-email\r\n    container:\r\n      image: alpine:latest\r\n      command: [sh, -c]\r\n      args: [\"echo send e-mail: {{workflow.name}} {{workflow.status}} {{workflow.duration}}\"]\r\n  - name: celebrate\r\n    container:\r\n      image: alpine:latest\r\n      command: [sh, -c]\r\n      args: [\"echo hooray!\"]\r\n  - name: cry\r\n    container:\r\n      image: alpine:latest\r\n      command: [sh, -c]\r\n      args: [\"echo boohoo!\"]<\/pre>\n<h3>Timeouts<\/h3>\n<p>\u53ef\u4ee5\u5728 Workflow \u6216 template \u4e0a\u8bbe\u7f6e\u6267\u884c\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u4ee5\u514d\u56e0\u4e3a\u4e2a\u522b\u8282\u70b9\u963b\u585e\u6574\u4e2a Workflow \u7684\u8fd0\u884c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">apiVersion: argoproj.io\/v1alpha1\r\nkind: Workflow\r\nmetadata:\r\n  generateName: timeouts-\r\nspec:\r\n  activeDeadlineSeconds: 10 # terminate workflow after 10 seconds\r\n  entrypoint: sleep\r\n  templates:\r\n  - name: sleep\r\n    activeDeadlineSeconds: 5 # terminate container after 5 seconds\r\n    container:\r\n      image: alpine:latest\r\n      command: [sh, -c]\r\n      args: [\"echo sleeping for 1m; sleep 60; echo done\"]<\/pre>\n<h3>Suspending<\/h3>\n<p>\u5982\u679c\u5e0c\u671b\u6682\u505c Workflow \u7684\u6267\u884c\uff0c\u53ef\u4ee5\u52a0\u5165\u4e00\u4e2a\u5305\u542b suspend \u914d\u7f6e\u7684 template\uff0c\u7136\u540e\u5728\u9700\u8981\u6682\u505c\u7684\u5730\u65b9\u5f15\u7528\u5b83\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">apiVersion: argoproj.io\/v1alpha1\r\nkind: Workflow\r\nmetadata:\r\n  generateName: suspend-template-\r\nspec:\r\n  entrypoint: suspend\r\n  templates:\r\n  - name: suspend\r\n    steps:\r\n    - - name: build\r\n        template: whalesay\r\n    - - name: approve\r\n        template: approve\r\n    - - name: delay\r\n        template: delay\r\n    - - name: release\r\n        template: whalesay\r\n\r\n  - name: approve\r\n    suspend: {}\r\n\r\n  - name: delay\r\n    suspend:\r\n      duration: \"20\"    # Must be a string. Default unit is seconds. Could also be a Duration, e.g.: \"2m\", \"6h\"\r\n\r\n  - name: whalesay\r\n    container:\r\n      image: docker\/whalesay\r\n      command: [cowsay]\r\n      args: [\"hello world\"]<\/pre>\n<p>\u4e00\u65e6\u6682\u505c\uff0cWorkflow \u5c06\u4e0d\u4f1a\u518d\u8c03\u5ea6\u540e\u9762\u7684\u8282\u70b9\uff0c\u800c\u662f\u4e00\u76f4\u7b49\u5230\u6682\u505c\u7684\u65f6\u95f4\u7ed3\u675f\u3002<\/p>\n<h3>\u7ed3\u8bed<\/h3>\n<p>Argo Workflows \u5176\u5b9e\u8fd8\u6709\u5f88\u591a\u7279\u6027\u672c\u6587\u6ca1\u6709\u4ecb\u7ecd\uff0c\u6bd4\u5982\u751f\u6210\/\u6d88\u8d39artifacts\u3001\u6267\u884cscripts\u3001\u6302\u8f7dsecrets\/volumes\u7b49\uff0c\u66f4\u591a\u8be6\u7ec6\u7684\u7528\u6cd5\u53ef\u4ee5\u53c2\u8003<span style=\"color: #7cc576;\"><a style=\"color: #7cc576;\" href=\"https:\/\/argoproj.github.io\/argo-workflows\/walk-through\/hello-world\/\">\u5b98\u65b9\u6587\u6863<\/a><\/span>\u3002\u53e6\u5916\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cArgo Workflows \u56e0\u4e3a\u672c\u8d28\u662f\u57fa\u4e8e Kubernetes \u7684 etcd \u6570\u636e\u5e93\u4fdd\u5b58\u5de5\u4f5c\u6d41\u914d\u7f6e\u548c\u8fd0\u884c\u6570\u636e\uff0c\u6570\u636e\u4f1a\u6709\u65f6\u6548\u6027\uff0c\u56e0\u6b64\u5982\u679c\u5e0c\u671b\u6301\u4e45\u4fdd\u5b58\uff0c\u5efa\u8bae\u8fd8\u662f\u81ea\u5df1\u5b9e\u73b0\u4e00\u4e2a Persist Controller \u6765\u76d1\u542c Workflow CR \u7684\u751f\u547d\u5468\u671f\u5e76\u6301\u4e45\u5316\u5230\u5173\u7cfb\u578b\u6570\u636e\u5e93\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u8a00 \u201c\u5de5\u4f5c\u6d41\u201d\u662f\u5728\u7cfb\u7edf\u5f00\u53d1\u4e2d\u7ecf\u5e38\u88ab\u63d0\u53ca\u7684\u4e00\u4e2a\u6982\u5ff5\uff0c\u6bd4\u5982\u673a\u5668\u5b66\u4e60\u5e73\u53f0\u91cc\u9700\u8981\u7528\u5de5\u4f5c\u6d41\u4e32\u8054\u4ece\u5efa\u6a21\u3001\u8bad\u7ec3\u5230\u9884\u6d4b\u7684\u5168\u6d41 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[65,64],"tags":[],"_links":{"self":[{"href":"http:\/\/yaochenkun.site\/index.php\/wp-json\/wp\/v2\/posts\/2531"}],"collection":[{"href":"http:\/\/yaochenkun.site\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yaochenkun.site\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yaochenkun.site\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yaochenkun.site\/index.php\/wp-json\/wp\/v2\/comments?post=2531"}],"version-history":[{"count":53,"href":"http:\/\/yaochenkun.site\/index.php\/wp-json\/wp\/v2\/posts\/2531\/revisions"}],"predecessor-version":[{"id":3159,"href":"http:\/\/yaochenkun.site\/index.php\/wp-json\/wp\/v2\/posts\/2531\/revisions\/3159"}],"wp:attachment":[{"href":"http:\/\/yaochenkun.site\/index.php\/wp-json\/wp\/v2\/media?parent=2531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yaochenkun.site\/index.php\/wp-json\/wp\/v2\/categories?post=2531"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yaochenkun.site\/index.php\/wp-json\/wp\/v2\/tags?post=2531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}