@@ -9,19 +9,27 @@ import (
9
9
"github.com/pkg/errors"
10
10
"golang.stackrox.io/kube-linter/internal/set"
11
11
"helm.sh/helm/v3/pkg/chartutil"
12
+ "k8s.io/apimachinery/pkg/runtime"
12
13
)
13
14
14
15
var (
15
16
knownYAMLExtensions = set .NewFrozenStringSet (".yaml" , ".yml" )
16
17
)
17
18
19
+ type Options struct {
20
+ customDecoder runtime.Decoder
21
+ }
22
+
18
23
// CreateContexts creates a context. Each context contains a set of files that should be linted
19
24
// as a group.
20
25
// Currently, each directory of Kube YAML files (or Helm charts) are treated as a separate context.
21
26
// TODO: Figure out if it's useful to allow people to specify that files spanning different directories
22
27
// should be treated as being in the same context.
23
28
func CreateContexts (filesOrDirs ... string ) ([]LintContext , error ) {
29
+ return CreateContextsWithOptions (Options {}, filesOrDirs ... )
30
+ }
24
31
32
+ func CreateContextsWithOptions (options Options , filesOrDirs ... string ) ([]LintContext , error ) {
25
33
contextsByDir := make (map [string ]* lintContextImpl )
26
34
for _ , fileOrDir := range filesOrDirs {
27
35
// Stdin
@@ -30,6 +38,7 @@ func CreateContexts(filesOrDirs ...string) ([]LintContext, error) {
30
38
continue
31
39
}
32
40
ctx := new ()
41
+ ctx .customDecoder = options .customDecoder
33
42
if err := ctx .loadObjectsFromReader ("<standard input>" , os .Stdin ); err != nil {
34
43
return nil , err
35
44
}
@@ -49,6 +58,7 @@ func CreateContexts(filesOrDirs ...string) ([]LintContext, error) {
49
58
if ! info .IsDir () {
50
59
if strings .HasSuffix (strings .ToLower (currentPath ), ".tgz" ) {
51
60
ctx := new ()
61
+ ctx .customDecoder = options .customDecoder
52
62
if err := ctx .loadObjectsFromTgzHelmChart (currentPath ); err != nil {
53
63
return err
54
64
}
@@ -63,6 +73,7 @@ func CreateContexts(filesOrDirs ...string) ([]LintContext, error) {
63
73
ctx := contextsByDir [dirName ]
64
74
if ctx == nil {
65
75
ctx = new ()
76
+ ctx .customDecoder = options .customDecoder
66
77
contextsByDir [dirName ] = ctx
67
78
}
68
79
if err := ctx .loadObjectsFromYAMLFile (currentPath , info ); err != nil {
@@ -77,6 +88,7 @@ func CreateContexts(filesOrDirs ...string) ([]LintContext, error) {
77
88
return nil
78
89
}
79
90
ctx := new ()
91
+ ctx .customDecoder = options .customDecoder
80
92
contextsByDir [currentPath ] = ctx
81
93
if err := ctx .loadObjectsFromHelmChart (currentPath ); err != nil {
82
94
return err
0 commit comments