123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package approve_former
- import (
- "bytes"
- "github.com/pkg/errors"
- "text/template"
- )
- const workflowTemplateTpl = `
- [[- $workflowTemplateName := .real_workflow_name -]]
- [[- $rootChildren := .children -]]
- apiVersion: argoproj.io/v1alpha1
- kind: WorkflowTemplate
- metadata:
- name: [[ $workflowTemplateName ]]
- spec:
- entrypoint: approve-flow
- arguments:
- parameters:
- - name: object
- value: {}
- templates:
- - name: approve-flow
- inputs:
- parameters:
- - name: object
- dag:
- tasks:
- [[ template "template" $rootChildren ]]
- - name: approval
- suspend: {}
- inputs:
- parameters:
- - name: approve
- default: '通过'
- enum:
- - '通过'
- - '拒绝'
- - '忽略'
- outputs:
- parameters:
- - name: approve
- valueFrom:
- supplied: {}
- [[- define "template" -]]
- - name: node
- template: approval
- [[- end -]]
- `
- func ParseWorkflowTemplate(name string, templateParams map[string]any) (string, error) {
- tpl := template.New(name)
- tpl.Delims("[[", "]]")
- tpl, err := tpl.Parse(workflowTemplateTpl)
- if err != nil {
- return "", errors.New(err.Error())
- }
- templateParams["real_workflow_name"] = name
- buffer := &bytes.Buffer{}
- err = tpl.Execute(buffer, templateParams)
- if err != nil {
- return "", errors.New(err.Error())
- }
- return buffer.String(), nil
- }
|