forked from argoproj/argo-workflows
/
lint.go
65 lines (59 loc) · 1.63 KB
/
lint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cron
import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
cmdutil "github.com/argoproj/argo/util/cmd"
"github.com/argoproj/argo/workflow/validate"
)
func NewLintCommand() *cobra.Command {
var (
strict bool
)
var command = &cobra.Command{
Use: "lint (DIRECTORY | FILE1 FILE2 FILE3...)",
Short: "validate a file or directory of cron workflow manifests",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}
namespace, _, err := clientConfig.Namespace()
if err != nil {
log.Fatal(err)
}
wftmplGetter := &LazyWorkflowTemplateGetter{}
validateDir := cmdutil.MustIsDir(args[0])
if validateDir {
if len(args) > 1 {
fmt.Printf("Validation of a single directory supported")
os.Exit(1)
}
fmt.Printf("Verifying all cron workflow manifests in directory: %s\n", args[0])
err = validate.LintCronWorkflowDir(wftmplGetter, namespace, args[0], strict)
} else {
yamlFiles := make([]string, 0)
for _, filePath := range args {
if cmdutil.MustIsDir(filePath) {
fmt.Printf("Validate against a list of files or a single directory, not both")
os.Exit(1)
}
yamlFiles = append(yamlFiles, filePath)
}
for _, yamlFile := range yamlFiles {
err = validate.LintCronWorkflowFile(wftmplGetter, namespace, yamlFile, strict)
if err != nil {
break
}
}
}
if err != nil {
log.Fatal(err)
}
fmt.Printf("CronWorkflow manifests validated\n")
},
}
command.Flags().BoolVar(&strict, "strict", true, "perform strict workflow validation")
return command
}