mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-09-26 17:51:13 +08:00
validate workflows
This commit is contained in:
2
go.mod
2
go.mod
@@ -6,7 +6,7 @@ require (
|
||||
github.com/Azure/go-autorest/autorest v0.9.2 // indirect
|
||||
github.com/Azure/go-autorest/autorest/adal v0.8.0 // indirect
|
||||
github.com/Masterminds/squirrel v1.1.0
|
||||
github.com/argoproj/argo v2.4.2+incompatible
|
||||
github.com/argoproj/argo v2.4.3+incompatible
|
||||
github.com/argoproj/pkg v0.0.0-20191031223000-02a6aac40ac4
|
||||
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31 // indirect
|
||||
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
|
||||
|
8
go.sum
8
go.sum
@@ -30,8 +30,10 @@ github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdko
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
|
||||
github.com/argoproj/argo v2.4.2+incompatible h1:FFA8pREl78H0HHucYdFJI0UCgxnO709+OEhM5eRZJB0=
|
||||
github.com/argoproj/argo v2.4.2+incompatible/go.mod h1:KJ0MB+tuhtAklR4jkPM10mIZXfRA0peTYJ1sLUnFLVU=
|
||||
github.com/argoproj/argo v2.4.3+incompatible h1:RA5TX2Bkh5nE+DZFzooEe7Jxy6lkRvAim4fPa+EGA7A=
|
||||
github.com/argoproj/argo v2.4.3+incompatible/go.mod h1:KJ0MB+tuhtAklR4jkPM10mIZXfRA0peTYJ1sLUnFLVU=
|
||||
github.com/argoproj/argo v2.5.0-rc10+incompatible h1:24uVNJw+UmmaH/Y6ViECR1CR8OGJKO5p0YQD0ue1C+Y=
|
||||
github.com/argoproj/argo v2.5.0-rc10+incompatible/go.mod h1:KJ0MB+tuhtAklR4jkPM10mIZXfRA0peTYJ1sLUnFLVU=
|
||||
github.com/argoproj/pkg v0.0.0-20191031223000-02a6aac40ac4 h1:ykGEoo3WuCNoqO+rnaa0j/RdYfXZFp5Aqim+CjzdBaQ=
|
||||
github.com/argoproj/pkg v0.0.0-20191031223000-02a6aac40ac4/go.mod h1:2EZ44RG/CcgtPTwrRR0apOc7oU6UIw8GjCUJWZ8X3bM=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
@@ -206,6 +208,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
||||
github.com/pressly/goose v2.6.0+incompatible h1:3f8zIQ8rfgP9tyI0Hmcs2YNAqUCL1c+diLe3iU8Qd/k=
|
||||
github.com/pressly/goose v2.6.0+incompatible/go.mod h1:m+QHWCqxR3k8D9l7qfzuC/djtlfzxr34mozWDYEu1z8=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
|
||||
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
|
110
kube/workflow.go
110
kube/workflow.go
@@ -7,8 +7,9 @@ import (
|
||||
|
||||
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
|
||||
"github.com/argoproj/argo/workflow/common"
|
||||
"github.com/argoproj/argo/workflow/templateresolution"
|
||||
"github.com/argoproj/argo/workflow/util"
|
||||
argoutil "github.com/argoproj/argo/workflow/util"
|
||||
"github.com/argoproj/argo/workflow/validate"
|
||||
argojson "github.com/argoproj/pkg/json"
|
||||
"github.com/onepanelio/core/model"
|
||||
"github.com/onepanelio/core/util/env"
|
||||
@@ -72,45 +73,7 @@ func unmarshalWorkflows(wfBytes []byte, strict bool) (wfs []Workflow, err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) create(namespace string, wf *Workflow, opts *WorkflowOptions) (createdWorkflow *Workflow, err error) {
|
||||
|
||||
if opts == nil {
|
||||
opts = &WorkflowOptions{}
|
||||
}
|
||||
|
||||
if opts.Name != "" {
|
||||
wf.ObjectMeta.Name = opts.Name
|
||||
}
|
||||
if opts.GenerateName != "" {
|
||||
wf.ObjectMeta.GenerateName = opts.GenerateName
|
||||
}
|
||||
if opts.Entrypoint != "" {
|
||||
wf.Spec.Entrypoint = opts.Entrypoint
|
||||
}
|
||||
if opts.ServiceAccount != "" {
|
||||
wf.Spec.ServiceAccountName = opts.ServiceAccount
|
||||
}
|
||||
if len(opts.Parameters) > 0 {
|
||||
newParams := make([]wfv1.Parameter, 0)
|
||||
passedParams := make(map[string]bool)
|
||||
for _, param := range opts.Parameters {
|
||||
newParams = append(newParams, param)
|
||||
passedParams[param.Name] = true
|
||||
}
|
||||
|
||||
for _, param := range wf.Spec.Arguments.Parameters {
|
||||
if _, ok := passedParams[param.Name]; ok {
|
||||
// this parameter was overridden via command line
|
||||
continue
|
||||
}
|
||||
newParams = append(newParams, param)
|
||||
}
|
||||
wf.Spec.Arguments.Parameters = newParams
|
||||
}
|
||||
if opts.Labels != nil {
|
||||
wf.ObjectMeta.Labels = *opts.Labels
|
||||
}
|
||||
|
||||
func (c *Client) autoInjectFields(namespace string, wf *Workflow, opts *WorkflowOptions) (err error) {
|
||||
if opts.PodGCStrategy == nil {
|
||||
if wf.Spec.PodGC == nil {
|
||||
//TODO - Load this data from onepanel config-map or secret
|
||||
@@ -134,10 +97,10 @@ func (c *Client) create(namespace string, wf *Workflow, opts *WorkflowOptions) (
|
||||
if statusError.ErrStatus.Reason == "NotFound" {
|
||||
addSecretValsToTemplate = false
|
||||
} else {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +142,51 @@ func (c *Client) create(namespace string, wf *Workflow, opts *WorkflowOptions) (
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) create(namespace string, wf *Workflow, opts *WorkflowOptions) (createdWorkflow *Workflow, err error) {
|
||||
if opts == nil {
|
||||
opts = &WorkflowOptions{}
|
||||
}
|
||||
|
||||
if opts.Name != "" {
|
||||
wf.ObjectMeta.Name = opts.Name
|
||||
}
|
||||
if opts.GenerateName != "" {
|
||||
wf.ObjectMeta.GenerateName = opts.GenerateName
|
||||
}
|
||||
if opts.Entrypoint != "" {
|
||||
wf.Spec.Entrypoint = opts.Entrypoint
|
||||
}
|
||||
if opts.ServiceAccount != "" {
|
||||
wf.Spec.ServiceAccountName = opts.ServiceAccount
|
||||
}
|
||||
if len(opts.Parameters) > 0 {
|
||||
newParams := make([]wfv1.Parameter, 0)
|
||||
passedParams := make(map[string]bool)
|
||||
for _, param := range opts.Parameters {
|
||||
newParams = append(newParams, param)
|
||||
passedParams[param.Name] = true
|
||||
}
|
||||
|
||||
for _, param := range wf.Spec.Arguments.Parameters {
|
||||
if _, ok := passedParams[param.Name]; ok {
|
||||
// this parameter was overridden via command line
|
||||
continue
|
||||
}
|
||||
newParams = append(newParams, param)
|
||||
}
|
||||
wf.Spec.Arguments.Parameters = newParams
|
||||
}
|
||||
if opts.Labels != nil {
|
||||
wf.ObjectMeta.Labels = *opts.Labels
|
||||
}
|
||||
|
||||
if err = c.autoInjectFields(namespace, wf, opts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
createdWorkflow, err = c.ArgoprojV1alpha1().Workflows(namespace).Create(wf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -187,8 +195,20 @@ func (c *Client) create(namespace string, wf *Workflow, opts *WorkflowOptions) (
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) ValidateWorkflow(manifest []byte) (err error) {
|
||||
_, err = unmarshalWorkflows(manifest, true)
|
||||
func (c *Client) ValidateWorkflow(namespace string, manifest []byte) (err error) {
|
||||
workflows, err := unmarshalWorkflows(manifest, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
wftmplGetter := templateresolution.WrapWorkflowTemplateInterface(c.ArgoprojV1alpha1().WorkflowTemplates(namespace))
|
||||
for _, wf := range workflows {
|
||||
c.autoInjectFields(namespace, &wf, &WorkflowOptions{})
|
||||
err = validate.ValidateWorkflow(wftmplGetter, &wf, validate.ValidateOpts{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -293,7 +313,7 @@ func (c *Client) SuspendWorkflow(namespace, name string) (err error) {
|
||||
}
|
||||
|
||||
func (c *Client) TerminateWorkflow(namespace, name string) (err error) {
|
||||
err = argoutil.TerminateWorkflow(c.ArgoprojV1alpha1().Workflows(namespace), name)
|
||||
err = util.TerminateWorkflow(c.ArgoprojV1alpha1().Workflows(namespace), name)
|
||||
|
||||
return
|
||||
}
|
||||
|
@@ -424,7 +424,7 @@ func (r *ResourceManager) CreateWorkflowTemplate(namespace string, workflowTempl
|
||||
}
|
||||
|
||||
// validate workflow template
|
||||
if err := r.kubeClient.ValidateWorkflow(workflowTemplate.GetManifestBytes()); err != nil {
|
||||
if err := r.kubeClient.ValidateWorkflow(namespace, workflowTemplate.GetManifestBytes()); err != nil {
|
||||
logging.Logger.Log.WithFields(log.Fields{
|
||||
"Namespace": namespace,
|
||||
"WorkflowTemplate": workflowTemplate,
|
||||
@@ -461,7 +461,7 @@ func (r *ResourceManager) CreateWorkflowTemplateVersion(namespace string, workfl
|
||||
}
|
||||
|
||||
// validate workflow template
|
||||
if err := r.kubeClient.ValidateWorkflow(workflowTemplate.GetManifestBytes()); err != nil {
|
||||
if err := r.kubeClient.ValidateWorkflow(namespace, workflowTemplate.GetManifestBytes()); err != nil {
|
||||
logging.Logger.Log.WithFields(log.Fields{
|
||||
"Namespace": namespace,
|
||||
"WorkflowTemplate": workflowTemplate,
|
||||
@@ -510,7 +510,7 @@ func (r *ResourceManager) UpdateWorkflowTemplateVersion(namespace string, workfl
|
||||
}
|
||||
|
||||
// validate workflow template
|
||||
if err := r.kubeClient.ValidateWorkflow(workflowTemplate.GetManifestBytes()); err != nil {
|
||||
if err := r.kubeClient.ValidateWorkflow(namespace, workflowTemplate.GetManifestBytes()); err != nil {
|
||||
logging.Logger.Log.WithFields(log.Fields{
|
||||
"Namespace": namespace,
|
||||
"WorkflowTemplate": workflowTemplate,
|
||||
|
Reference in New Issue
Block a user