Quellcode durchsuchen

增加approve选项

duyong mac vor 3 Monaten
Ursprung
Commit
17aa5d8f88

+ 1 - 0
approve_former/flow.go

@@ -38,6 +38,7 @@ spec:
             enum:
               - '通过'
               - '拒绝'
+              - '忽略'
       outputs:
         parameters:
           - name: approve

+ 19 - 0
example/config/k3s.yaml

@@ -0,0 +1,19 @@
+apiVersion: v1
+clusters:
+  - cluster:
+      certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJkekNDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdGMyVnkKZG1WeUxXTmhRREUzTWpFNE9UZ3pOamd3SGhjTk1qUXdOekkxTURrd05qQTRXaGNOTXpRd056SXpNRGt3TmpBNApXakFqTVNFd0h3WURWUVFEREJock0zTXRjMlZ5ZG1WeUxXTmhRREUzTWpFNE9UZ3pOamd3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFTS0xORWJvZUlJY2NQam91aDEvMU9vVnFwT1A4VVdXck5TOVE1YUp0YWgKSXBucDhySVBkRkR0V09pZzRaZFkvUnArOEV3WlZnc3NyYlZNcWF1UXpBcXJvMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVU44QjB3YzZWdXlnZTdidE82VjdCCnhwa0xoeXd3Q2dZSUtvWkl6ajBFQXdJRFNBQXdSUUlnSVZNK2VUVmtaMUhHQXlIQ21QeVVXUzl0b0pYdEZabHkKY3k5clRwYnVQTk1DSVFDWnl1WCtlNzRXWE01cjR3dTkybTV4WkRrTzdIYWoycURWYXVQY1A5NExIdz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
+      server: https://10.0.0.68:6443
+    name: default
+contexts:
+  - context:
+      cluster: default
+      user: default
+    name: default
+current-context: default
+kind: Config
+preferences: {}
+users:
+  - name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RZMnhwWlc1MExXTmhRREUzTWpFNE9UZ3pOamd3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFTSFBuRFgvVlZWVmUvOVU3OXcvMmkxK0dKUURDVytjRHFtM3h3c1dRTGgKUjdQcVNFNkN2M1hmRkYvS0RaUFpjajlkRjMxektpbHh2RUx6U3pXanJyMUVvMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVWw5WW5uZ0NGMndEUkY0SnMyV0x2Cm9MYzJiWll3Q2dZSUtvWkl6ajBFQXdJRFNBQXdSUUloQUpLSDVJZWZDVFhmUEw4VC9LV2I5UG1GbEYrYXdpSmEKYytsQmxYbXptSElWQWlCUlEwQk1ycFhHMGF3eUJUNnFPOU1tQVljNzltSWt0Rk9yNkord2UrMVZ1dz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
+      client-key-data: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSUxwTGR0bmlPeXBhb2dBNk93NGt4QnlOVkN5S2tGdTdrTkdPd0Nndndsa2xvQW9HQ0NxR1NNNDkKQXdFSG9VUURRZ0FFMHpjQlVEdzFWM3F6UWVvZ1lqeWhKM1RzTi9NMS8wNk9COW45bWhjVTY1RlBFZW5xUEw5Sgo3K3lqRUE0azNDQnNOWHk3OTlUWDJLL1ZBdlZBaFRuOGpnPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo=

+ 56 - 0
example/template-render/andor.yaml

@@ -0,0 +1,56 @@
+apiVersion: argoproj.io/v1alpha1
+kind: WorkflowTemplate
+metadata:
+  name: andor
+spec:
+  entrypoint: approve-flow
+  arguments:
+    parameters:
+      - name: object
+        value: {}
+
+  templates:
+    - name: approve-flow
+      inputs:
+        parameters:
+          - name: object
+      dag:
+        tasks:
+          - name: A
+            template: approval
+          - name: B
+            template: approval
+            depends: "A.Succeeded"
+            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+          - name: C
+            template: approval
+            depends: "A.Succeeded"
+            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+          - name: D
+            template: approval
+            depends: "B.Succeeded && C.Succeeded"
+            when: "({{ tasks.B.outputs.parameters.approve }} == 通过) && ({{ tasks.C.outputs.parameters.approve }} == 通过)"
+          - name: E
+            template: approval
+            depends: "B.Succeeded && C.Succeeded"
+            when: "({{ tasks.B.outputs.parameters.approve }} == 通过) && ({{ tasks.C.outputs.parameters.approve }} == 通过)"
+          - name: F
+            template: approval
+            depends: "D.Succeeded && E.Succeeded"
+            when: "({{ tasks.D.outputs.parameters.approve }} == 通过) || ({{ tasks.E.outputs.parameters.approve }} == 通过)"
+          
+    - name: approval
+      suspend: {}
+      inputs:
+        parameters:
+          - name: approve
+            default: '通过'
+            enum:
+              - '通过'
+              - '拒绝'
+              - '忽略'
+      outputs:
+        parameters:
+          - name: approve
+            valueFrom:
+              supplied: {}

+ 75 - 0
example/template-render/main.go

@@ -0,0 +1,75 @@
+package main
+
+import (
+	"git.sxidc.com/go-tools/argo-api/approve_former"
+	"os"
+)
+
+const dir = "/Users/duyong/workspace/fangshi/meta-business/argo/example/template-render/"
+
+func main() {
+	//simpleTemp()
+	//buildSignsTemp()
+	buildAndORTemp()
+}
+
+// simpleTemp 什么也没有的流程
+func simpleTemp() {
+	flow := approve_former.NewFlow("simple")
+	templateString, err := flow.Render(nil)
+	if err != nil {
+		panic(err)
+	}
+	_ = writeFile(dir+"simple.yaml", templateString)
+}
+
+func writeFile(fileName string, data string) error {
+	// 将字符串写入文件
+	err := os.WriteFile(fileName, []byte(data), 0644)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// 只有单签的流程模板
+func buildSignsTemp() {
+	flow := approve_former.NewFlow("signs",
+		approve_former.NewSign("技术总监"),
+		approve_former.NewSign("研发总监"),
+		approve_former.NewSign("人事总监"))
+	templateString, err := flow.Render(nil)
+	if err != nil {
+		panic(err)
+	}
+	_ = writeFile(dir+"signs.yaml", templateString)
+
+	flow1 := approve_former.NewFlow("signs",
+		approve_former.NewSign("A"),
+		approve_former.NewSign("B"),
+		approve_former.NewSign("C"))
+	templateString1, err := flow1.Render(nil)
+	if err != nil {
+		panic(err)
+	}
+	_ = writeFile(dir+"signs1.yaml", templateString1)
+}
+
+// 会签和或签
+func buildAndORTemp() {
+	flow := approve_former.NewFlow("andor",
+		approve_former.NewSign("A"),
+		approve_former.NewAnd(
+			approve_former.NewSign("B"), approve_former.NewSign("C"),
+		),
+		approve_former.NewOr(
+			approve_former.NewSign("D"), approve_former.NewSign("E"),
+		),
+		approve_former.NewSign("F"),
+	)
+	templateString, err := flow.Render(nil)
+	if err != nil {
+		panic(err)
+	}
+	_ = writeFile(dir+"andor.yaml", templateString)
+}

+ 55 - 0
example/template-render/signs.yaml

@@ -0,0 +1,55 @@
+apiVersion: argoproj.io/v1alpha1
+kind: WorkflowTemplate
+metadata:
+  name: buildAndOR
+spec:
+  entrypoint: approve-flow
+  arguments:
+    parameters:
+      - name: object
+        value: {}
+
+  templates:
+    - name: approve-flow
+      inputs:
+        parameters:
+          - name: object
+      dag:
+        tasks:
+          - name: A
+            template: approval
+          - name: B
+            template: approval
+            depends: "A.Succeeded"
+            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+          - name: C
+            template: approval
+            depends: "A.Succeeded"
+            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+          - name: D
+            template: approval
+            depends: "B.Succeeded && C.Succeeded"
+            when: "({{ tasks.B.outputs.parameters.approve }} == 通过) && ({{ tasks.C.outputs.parameters.approve }} == 通过)"
+          - name: E
+            template: approval
+            depends: "B.Succeeded && C.Succeeded"
+            when: "({{ tasks.B.outputs.parameters.approve }} == 通过) && ({{ tasks.C.outputs.parameters.approve }} == 通过)"
+          - name: F
+            template: approval
+            depends: "D.Succeeded && E.Succeeded"
+            when: "({{ tasks.D.outputs.parameters.approve }} == 通过) || ({{ tasks.E.outputs.parameters.approve }} == 通过)"
+          
+    - name: approval
+      suspend: {}
+      inputs:
+        parameters:
+          - name: approve
+            default: '通过'
+            enum:
+              - '通过'
+              - '拒绝'
+      outputs:
+        parameters:
+          - name: approve
+            valueFrom:
+              supplied: {}

+ 43 - 0
example/template-render/signs1.yaml

@@ -0,0 +1,43 @@
+apiVersion: argoproj.io/v1alpha1
+kind: WorkflowTemplate
+metadata:
+  name: signs
+spec:
+  entrypoint: approve-flow
+  arguments:
+    parameters:
+      - name: object
+        value: {}
+
+  templates:
+    - name: approve-flow
+      inputs:
+        parameters:
+          - name: object
+      dag:
+        tasks:
+          - name: A
+            template: approval
+          - name: B
+            template: approval
+            depends: "A.Succeeded"
+            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+          - name: C
+            template: approval
+            depends: "B.Succeeded"
+            when: "{{ tasks.B.outputs.parameters.approve }} == 通过"
+          
+    - name: approval
+      suspend: {}
+      inputs:
+        parameters:
+          - name: approve
+            default: '通过'
+            enum:
+              - '通过'
+              - '拒绝'
+      outputs:
+        parameters:
+          - name: approve
+            valueFrom:
+              supplied: {}

+ 35 - 0
example/template-render/simple.yaml

@@ -0,0 +1,35 @@
+apiVersion: argoproj.io/v1alpha1
+kind: WorkflowTemplate
+metadata:
+  name: simple
+spec:
+  entrypoint: approve-flow
+  arguments:
+    parameters:
+      - name: object
+        value: {}
+
+  templates:
+    - name: approve-flow
+      inputs:
+        parameters:
+          - name: object
+      dag:
+        tasks:
+          - name: node
+            template: approval
+          
+    - name: approval
+      suspend: {}
+      inputs:
+        parameters:
+          - name: approve
+            default: '通过'
+            enum:
+              - '通过'
+              - '拒绝'
+      outputs:
+        parameters:
+          - name: approve
+            valueFrom:
+              supplied: {}

+ 1 - 1
test/common.go

@@ -5,7 +5,7 @@ import (
 )
 
 const (
-	kubeConfig                     = "/etc/rancher/k3s/k3s.yaml"
+	kubeConfig                     = "/etc/rancher/k3s.yaml/k3s.yaml.yaml"
 	namespace                      = "argo-api"
 	workflowTemplateName           = "approve"
 	workflowTemplateWithParamsName = "hello"