@@ -9,19 +9,28 @@ 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
+ // Options represent values that can be provided to modify how objects are parsed to create lint contexts
20
+ type Options struct {
21
+ customDecoder runtime.Decoder
22
+ }
23
+
18
24
// CreateContexts creates a context. Each context contains a set of files that should be linted
19
25
// as a group.
20
26
// Currently, each directory of Kube YAML files (or Helm charts) are treated as a separate context.
21
27
// TODO: Figure out if it's useful to allow people to specify that files spanning different directories
22
28
// should be treated as being in the same context.
23
29
func CreateContexts (filesOrDirs ... string ) ([]LintContext , error ) {
30
+ return CreateContextsWithOptions (Options {}, filesOrDirs ... )
31
+ }
24
32
33
+ func CreateContextsWithOptions (options Options , filesOrDirs ... string ) ([]LintContext , error ) {
25
34
contextsByDir := make (map [string ]* lintContextImpl )
26
35
for _ , fileOrDir := range filesOrDirs {
27
36
// Stdin
@@ -30,6 +39,7 @@ func CreateContexts(filesOrDirs ...string) ([]LintContext, error) {
30
39
continue
31
40
}
32
41
ctx := new ()
42
+ ctx .customDecoder = options .customDecoder
33
43
if err := ctx .loadObjectsFromReader ("<standard input>" , os .Stdin ); err != nil {
34
44
return nil , err
35
45
}
@@ -49,6 +59,7 @@ func CreateContexts(filesOrDirs ...string) ([]LintContext, error) {
49
59
if ! info .IsDir () {
50
60
if strings .HasSuffix (strings .ToLower (currentPath ), ".tgz" ) {
51
61
ctx := new ()
62
+ ctx .customDecoder = options .customDecoder
52
63
if err := ctx .loadObjectsFromTgzHelmChart (currentPath ); err != nil {
53
64
return err
54
65
}
@@ -63,6 +74,7 @@ func CreateContexts(filesOrDirs ...string) ([]LintContext, error) {
63
74
ctx := contextsByDir [dirName ]
64
75
if ctx == nil {
65
76
ctx = new ()
77
+ ctx .customDecoder = options .customDecoder
66
78
contextsByDir [dirName ] = ctx
67
79
}
68
80
if err := ctx .loadObjectsFromYAMLFile (currentPath , info ); err != nil {
@@ -77,6 +89,7 @@ func CreateContexts(filesOrDirs ...string) ([]LintContext, error) {
77
89
return nil
78
90
}
79
91
ctx := new ()
92
+ ctx .customDecoder = options .customDecoder
80
93
contextsByDir [currentPath ] = ctx
81
94
if err := ctx .loadObjectsFromHelmChart (currentPath ); err != nil {
82
95
return err
0 commit comments