فهرست منبع

完成workflow的入参定义

yjp 1 سال پیش
والد
کامیت
a05fd151fa
4فایلهای تغییر یافته به همراه171 افزوده شده و 82 حذف شده
  1. 94 15
      client/workflow.go
  2. 52 60
      client/workflow_template.go
  3. 1 1
      test/approve_workflow.yaml
  4. 24 6
      test/workflow_template_test.go

+ 94 - 15
client/workflow.go

@@ -6,6 +6,7 @@ const (
 	getWorkflowsInNamespaceRelativeUrl = "/api/v1/workflows/{namespace}"
 	getWorkflowRelativeUrl             = "/api/v1/workflows/{namespace}/{name}"
 	lintWorkflowRelativeUrl            = "/api/v1/workflows/{namespace}/lint"
+	submitWorkflowRelativeUrl          = "/api/v1/workflows/{namespace}/{name}/submit"
 	resubmitWorkflowRelativeUrl        = "/api/v1/workflows/{namespace}/{name}/resubmit"
 	resumeWorkflowRelativeUrl          = "/api/v1/workflows/{namespace}/{name}/resume"
 	retryWorkflowRelativeUrl           = "/api/v1/workflows/{namespace}/{name}/retry"
@@ -17,62 +18,140 @@ const (
 	getWorkflowEventsStreamRelativeUrl = "/api/v1/workflow-events/{namespace}"
 )
 
-func (c *Client) CreateWorkflow() error {
+type CreateWorkflowParams struct {
+	Namespace          string
+	TemplateDefinition map[string]any
+}
+
+func (c *Client) CreateWorkflow(params CreateWorkflowParams) error {
 	return nil
 }
 
-func (c *Client) DeleteWorkflow() error {
+type DeleteWorkflowParams struct {
+	Namespace string
+	Name      string
+}
+
+func (c *Client) DeleteWorkflow(params DeleteWorkflowParams) error {
 	return nil
 }
 
-func (c *Client) GetWorkflowsInNamespace() ([]map[string]any, error) {
+type GetWorkflowsInNamespaceParams struct {
+	Namespace string
+}
+
+func (c *Client) GetWorkflowsInNamespace(params GetWorkflowsInNamespaceParams) ([]map[string]any, error) {
 	workflowDefinitions := make([]map[string]any, 0)
 	return workflowDefinitions, nil
 }
 
-func (c *Client) GetWorkflow() (map[string]any, error) {
+type GetWorkflowParams struct {
+	Namespace string
+	Name      string
+}
+
+func (c *Client) GetWorkflow(params GetWorkflowParams) (map[string]any, error) {
 	workflowDefinition := make(map[string]any)
 	return workflowDefinition, nil
 }
 
-func (c *Client) LintWorkflow() error {
+type LintWorkflowParams struct {
+	Namespace          string
+	TemplateDefinition map[string]any
+}
+
+func (c *Client) LintWorkflow(params LintWorkflowParams) error {
+	return nil
+}
+
+type SubmitWorkflowParams struct {
+	Namespace string
+	Name      string
+}
+
+func (c *Client) SubmitWorkflow(params SubmitWorkflowParams) error {
 	return nil
 }
 
-func (c *Client) ResubmitWorkflow() error {
+type ResubmitWorkflowParams struct {
+	Namespace              string
+	Name                   string
+	ResubmitParametersJson string
+}
+
+func (c *Client) ResubmitWorkflow(params ResubmitWorkflowParams) error {
 	return nil
 }
 
-func (c *Client) ResumeWorkflow() error {
+type ResumeWorkflowParams struct {
+	Namespace string
+	Name      string
+}
+
+func (c *Client) ResumeWorkflow(params ResumeWorkflowParams) error {
 	return nil
 }
 
-func (c *Client) RetryWorkflow() error {
+type RetryWorkflowParams struct {
+	Namespace                               string
+	Name                                    string
+	RetryParametersJson                     string
+	RetryOnSuccessWorkflowNodeFieldSelector string
+}
+
+func (c *Client) RetryWorkflow(params RetryWorkflowParams) error {
 	return nil
 }
 
-func (c *Client) SetWorkflow() error {
+type SetWorkflowParams struct {
+	Namespace            string
+	Name                 string
+	NodeFieldSelector    string
+	Message              string
+	Phase                string
+	OutputParametersJson string
+}
+
+func (c *Client) SetWorkflow(params SetWorkflowParams) error {
 	return nil
 }
 
-func (c *Client) StopWorkflow() error {
+type StopWorkflowParams struct {
+	Namespace         string
+	Name              string
+	NodeFieldSelector string
+	Message           string
+}
+
+func (c *Client) StopWorkflow(params StopWorkflowParams) error {
 	return nil
 }
 
-func (c *Client) SuspendWorkflow() error {
+type SuspendWorkflowParams struct {
+	Namespace string
+	Name      string
+}
+
+func (c *Client) SuspendWorkflow(params SuspendWorkflowParams) error {
 	return nil
 }
 
-func (c *Client) TerminalWorkflow() error {
+type TerminalWorkflowParams struct {
+	Namespace string
+	Name      string
+}
+
+func (c *Client) TerminalWorkflow(params TerminalWorkflowParams) error {
 	return nil
 }
 
 type EventCallback func(event map[string]any, eventErr error) error
 
-func (c *Client) GetEventsStream(callback EventCallback) error {
-	return nil
+type GetWorkflowEventsStreamParams struct {
+	Namespace string
+	Name      string
 }
 
-func (c *Client) GetWorkflowEventsStream(callback EventCallback) error {
+func (c *Client) GetWorkflowEventsStream(params GetWorkflowEventsStreamParams, callback EventCallback) error {
 	return nil
 }

+ 52 - 60
client/workflow_template.go

@@ -14,24 +14,23 @@ const (
 	lintWorkflowTemplateRelativeUrl            = "/api/v1/workflow-templates/{namespace}/lint"
 )
 
-// CreateWorkflowTemplate 创建工作流模板
-// 参数:
-// namespace: 命名空间
-// templateDefinition: map定义
-// 返回值:
-// 错误
-func (c *Client) CreateWorkflowTemplate(namespace string, templateDefinition map[string]any) error {
+type CreateWorkflowTemplateParams struct {
+	Namespace          string
+	TemplateDefinition map[string]any
+}
+
+func (c *Client) CreateWorkflowTemplate(params CreateWorkflowTemplateParams) error {
 	responseMap := make(map[string]any)
 
 	resp, err := c.restyClient.R().
 		SetHeader("Content-Type", "application/json").
 		SetAuthToken(c.token).
 		SetPathParams(map[string]string{
-			"namespace": namespace,
+			"namespace": params.Namespace,
 		}).
 		SetBody(map[string]any{
-			"namespace": namespace,
-			"template":  templateDefinition,
+			"namespace": params.Namespace,
+			"template":  params.TemplateDefinition,
 		}).
 		SetResult(&responseMap).
 		SetError(&responseMap).
@@ -55,21 +54,20 @@ func (c *Client) CreateWorkflowTemplate(namespace string, templateDefinition map
 	}
 }
 
-// DeleteWorkflowTemplate 删除工作流模板
-// 参数:
-// namespace: 命名空间
-// name: 工作流模板名称
-// 返回值:
-// 错误
-func (c *Client) DeleteWorkflowTemplate(namespace string, name string) error {
+type DeleteWorkflowTemplateParams struct {
+	Namespace string
+	Name      string
+}
+
+func (c *Client) DeleteWorkflowTemplate(params DeleteWorkflowTemplateParams) error {
 	responseMap := make(map[string]any)
 
 	resp, err := c.restyClient.R().
 		SetHeader("Content-Type", "application/json").
 		SetAuthToken(c.token).
 		SetPathParams(map[string]string{
-			"namespace": namespace,
-			"name":      name,
+			"namespace": params.Namespace,
+			"name":      params.Name,
 		}).
 		SetResult(&responseMap).
 		SetError(&responseMap).
@@ -91,27 +89,26 @@ func (c *Client) DeleteWorkflowTemplate(namespace string, name string) error {
 	}
 }
 
-// UpdateWorkflowTemplate 更新工作流模板
-// 参数:
-// namespace: 命名空间
-// name: 工作流模板名称
-// templateDefinition: map定义,注意:需要基于查询回来的map定义进行修改
-// 返回值:
-// 错误
-func (c *Client) UpdateWorkflowTemplate(namespace string, name string, templateDefinition map[string]any) error {
+type UpdateWorkflowTemplateParams struct {
+	Namespace          string
+	Name               string
+	TemplateDefinition map[string]any
+}
+
+func (c *Client) UpdateWorkflowTemplate(params UpdateWorkflowTemplateParams) error {
 	responseMap := make(map[string]any)
 
 	resp, err := c.restyClient.R().
 		SetHeader("Content-Type", "application/json").
 		SetAuthToken(c.token).
 		SetPathParams(map[string]string{
-			"namespace": namespace,
-			"name":      name,
+			"namespace": params.Namespace,
+			"name":      params.Name,
 		}).
 		SetBody(map[string]any{
-			"namespace": namespace,
-			"name":      name,
-			"template":  templateDefinition,
+			"namespace": params.Namespace,
+			"name":      params.Name,
+			"template":  params.TemplateDefinition,
 		}).
 		SetResult(&responseMap).
 		SetError(&responseMap).
@@ -133,20 +130,18 @@ func (c *Client) UpdateWorkflowTemplate(namespace string, name string, templateD
 	}
 }
 
-// GetWorkflowTemplatesInNamespace 查询一个命名空间下的工作流模板
-// 参数:
-// namespace: 命名空间
-// 返回值:
-// 查询到的工作流模板定义
-// 错误
-func (c *Client) GetWorkflowTemplatesInNamespace(namespace string) ([]map[string]any, error) {
+type GetWorkflowTemplatesInNamespaceParams struct {
+	Namespace string
+}
+
+func (c *Client) GetWorkflowTemplatesInNamespace(params GetWorkflowTemplatesInNamespaceParams) ([]map[string]any, error) {
 	responseMap := make(map[string]any)
 
 	resp, err := c.restyClient.R().
 		SetHeader("Content-Type", "application/json").
 		SetAuthToken(c.token).
 		SetPathParams(map[string]string{
-			"namespace": namespace,
+			"namespace": params.Namespace,
 		}).
 		SetResult(&responseMap).
 		SetError(&responseMap).
@@ -188,22 +183,20 @@ func (c *Client) GetWorkflowTemplatesInNamespace(namespace string) ([]map[string
 	}
 }
 
-// GetWorkflowTemplate 查询具体的工作流模板
-// 参数:
-// namespace: 命名空间
-// name: 工作流模板名称
-// 返回值:
-// 查询到的工作流模板定义
-// 错误
-func (c *Client) GetWorkflowTemplate(namespace string, name string) (map[string]any, error) {
+type GetWorkflowTemplateParams struct {
+	Namespace string
+	Name      string
+}
+
+func (c *Client) GetWorkflowTemplate(params GetWorkflowTemplateParams) (map[string]any, error) {
 	responseMap := make(map[string]any)
 
 	resp, err := c.restyClient.R().
 		SetHeader("Content-Type", "application/json").
 		SetAuthToken(c.token).
 		SetPathParams(map[string]string{
-			"namespace": namespace,
-			"name":      name,
+			"namespace": params.Namespace,
+			"name":      params.Name,
 		}).
 		SetResult(&responseMap).
 		SetError(&responseMap).
@@ -225,24 +218,23 @@ func (c *Client) GetWorkflowTemplate(namespace string, name string) (map[string]
 	}
 }
 
-// LintWorkflowTemplate 对工作流模板定义进行语法检查
-// 参数:
-// namespace: 命名空间
-// templateDefinition: map定义
-// 返回值:
-// 错误
-func (c *Client) LintWorkflowTemplate(namespace string, templateDefinition map[string]any) error {
+type LintWorkflowTemplateParams struct {
+	Namespace          string
+	TemplateDefinition map[string]any
+}
+
+func (c *Client) LintWorkflowTemplate(params LintWorkflowTemplateParams) error {
 	responseMap := make(map[string]any)
 
 	resp, err := c.restyClient.R().
 		SetHeader("Content-Type", "application/json").
 		SetAuthToken(c.token).
 		SetPathParams(map[string]string{
-			"namespace": namespace,
+			"namespace": params.Namespace,
 		}).
 		SetBody(map[string]any{
-			"namespace": namespace,
-			"template":  templateDefinition,
+			"namespace": params.Namespace,
+			"template":  params.TemplateDefinition,
 		}).
 		SetResult(&responseMap).
 		SetError(&responseMap).

+ 1 - 1
test/approve_workflow.yaml

@@ -1,7 +1,7 @@
 apiVersion: argoproj.io/v1alpha1
 kind: Workflow
 metadata:
-  generatedName: approve-
+  generateName: approve-
 spec:
   entrypoint: approve-flow
   templates:

+ 24 - 6
test/workflow_template_test.go

@@ -18,24 +18,35 @@ func TestWorkflowTemplate(t *testing.T) {
 		panic(err)
 	}
 
-	err = argo.GetInstance().LintWorkflowTemplate(namespace, templateDefinition)
+	err = argo.GetInstance().LintWorkflowTemplate(client.LintWorkflowTemplateParams{
+		Namespace:          namespace,
+		TemplateDefinition: templateDefinition,
+	})
 	if err != nil {
 		t.Fatalf("%+v\n", err)
 	}
 
-	err = argo.GetInstance().CreateWorkflowTemplate(namespace, templateDefinition)
+	err = argo.GetInstance().CreateWorkflowTemplate(client.CreateWorkflowTemplateParams{
+		Namespace:          namespace,
+		TemplateDefinition: templateDefinition,
+	})
 	if err != nil {
 		t.Fatalf("%+v\n", err)
 	}
 
 	defer func() {
-		err := argo.GetInstance().DeleteWorkflowTemplate(namespace, workflowTemplateName)
+		err := argo.GetInstance().DeleteWorkflowTemplate(client.DeleteWorkflowTemplateParams{
+			Namespace: namespace,
+			Name:      workflowTemplateName,
+		})
 		if err != nil {
 			t.Fatalf("%+v\n", err)
 		}
 	}()
 
-	createdTemplateDefinitions, err := argo.GetInstance().GetWorkflowTemplatesInNamespace(namespace)
+	createdTemplateDefinitions, err := argo.GetInstance().GetWorkflowTemplatesInNamespace(client.GetWorkflowTemplatesInNamespaceParams{
+		Namespace: namespace,
+	})
 	if err != nil {
 		t.Fatalf("%+v\n", err)
 	}
@@ -44,12 +55,19 @@ func TestWorkflowTemplate(t *testing.T) {
 		t.Fatalf("%+v\n", errors.Errorf("数量不一致: %v", len(createdTemplateDefinitions)))
 	}
 
-	createdTemplateDefinition, err := argo.GetInstance().GetWorkflowTemplate(namespace, workflowTemplateName)
+	createdTemplateDefinition, err := argo.GetInstance().GetWorkflowTemplate(client.GetWorkflowTemplateParams{
+		Namespace: namespace,
+		Name:      workflowTemplateName,
+	})
 	if err != nil {
 		t.Fatalf("%+v\n", err)
 	}
 
-	err = argo.GetInstance().UpdateWorkflowTemplate(namespace, workflowTemplateName, createdTemplateDefinition)
+	err = argo.GetInstance().UpdateWorkflowTemplate(client.UpdateWorkflowTemplateParams{
+		Namespace:          namespace,
+		Name:               workflowTemplateName,
+		TemplateDefinition: createdTemplateDefinition,
+	})
 	if err != nil {
 		t.Fatalf("%+v\n", err)
 	}