123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package client
- import (
- "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflowtemplate"
- "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
- "github.com/pkg/errors"
- )
- type CreateWorkflowTemplateParams struct {
- Namespace string
- TemplateDefinition string
- }
- // CreateWorkflowTemplate 创建工作流模板
- func (c *Client) CreateWorkflowTemplate(params CreateWorkflowTemplateParams) error {
- wft := new(v1alpha1.WorkflowTemplate)
- err := unmarshalYamlToJsonStruct([]byte(params.TemplateDefinition), wft)
- if err != nil {
- return err
- }
- _, err = c.workflowTemplateService.CreateWorkflowTemplate(c.ctx, &workflowtemplate.WorkflowTemplateCreateRequest{
- Namespace: params.Namespace,
- Template: wft,
- })
- if err != nil {
- return errors.New(err.Error())
- }
- return nil
- }
- type DeleteWorkflowTemplateParams struct {
- Namespace string
- Name string
- }
- // DeleteWorkflowTemplate 删除工作流模板
- func (c *Client) DeleteWorkflowTemplate(params DeleteWorkflowTemplateParams) error {
- _, err := c.workflowTemplateService.DeleteWorkflowTemplate(c.ctx, &workflowtemplate.WorkflowTemplateDeleteRequest{
- Namespace: params.Namespace,
- Name: params.Name,
- })
- if err != nil {
- return errors.New(err.Error())
- }
- return nil
- }
- type UpdateWorkflowTemplateParams struct {
- Namespace string
- Name string
- WorkflowTemplate *v1alpha1.WorkflowTemplate
- }
- // UpdateWorkflowTemplate 更新工作流模板
- func (c *Client) UpdateWorkflowTemplate(params UpdateWorkflowTemplateParams) error {
- _, err := c.workflowTemplateService.UpdateWorkflowTemplate(c.ctx, &workflowtemplate.WorkflowTemplateUpdateRequest{
- Namespace: params.Namespace,
- Template: params.WorkflowTemplate,
- })
- if err != nil {
- return errors.New(err.Error())
- }
- return nil
- }
- type GetWorkflowTemplatesInNamespaceParams struct {
- Namespace string
- }
- // GetWorkflowTemplatesInNamespace 获取命名空间下的工作流模板
- func (c *Client) GetWorkflowTemplatesInNamespace(params GetWorkflowTemplatesInNamespaceParams) (v1alpha1.WorkflowTemplates, error) {
- response, err := c.workflowTemplateService.ListWorkflowTemplates(c.ctx, &workflowtemplate.WorkflowTemplateListRequest{
- Namespace: params.Namespace,
- })
- if err != nil {
- return nil, errors.New(err.Error())
- }
- return response.Items, nil
- }
- type GetWorkflowTemplateParams struct {
- Namespace string
- Name string
- }
- // GetWorkflowTemplate 获取指定的工作流模板
- func (c *Client) GetWorkflowTemplate(params GetWorkflowTemplateParams) (*v1alpha1.WorkflowTemplate, error) {
- response, err := c.workflowTemplateService.GetWorkflowTemplate(c.ctx, &workflowtemplate.WorkflowTemplateGetRequest{
- Namespace: params.Namespace,
- Name: params.Name,
- })
- if err != nil {
- return nil, errors.New(err.Error())
- }
- return response, nil
- }
- type LintWorkflowTemplateParams struct {
- Namespace string
- TemplateDefinition string
- }
- // LintWorkflowTemplate 工作流模板定义语法检查
- func (c *Client) LintWorkflowTemplate(params LintWorkflowTemplateParams) error {
- wft := new(v1alpha1.WorkflowTemplate)
- err := unmarshalYamlToJsonStruct([]byte(params.TemplateDefinition), wft)
- if err != nil {
- return err
- }
- _, err = c.workflowTemplateService.LintWorkflowTemplate(c.ctx, &workflowtemplate.WorkflowTemplateLintRequest{
- Namespace: params.Namespace,
- Template: wft,
- })
- if err != nil {
- return errors.New(err.Error())
- }
- return nil
- }
|