@@ -18,6 +18,7 @@ import (
18
18
"helm.sh/helm/v3/pkg/cli/values"
19
19
"helm.sh/helm/v3/pkg/engine"
20
20
v1 "k8s.io/api/core/v1"
21
+ "k8s.io/apimachinery/pkg/runtime"
21
22
"k8s.io/apimachinery/pkg/runtime/serializer"
22
23
"k8s.io/apimachinery/pkg/util/yaml"
23
24
"k8s.io/client-go/kubernetes/scheme"
@@ -34,15 +35,18 @@ var (
34
35
decoder = serializer .NewCodecFactory (clientSchema ).UniversalDeserializer ()
35
36
)
36
37
37
- func parseObjects (data []byte ) ([]k8sutil.Object , error ) {
38
- obj , _ , err := decoder .Decode (data , nil , nil )
38
+ func parseObjects (data []byte , d runtime.Decoder ) ([]k8sutil.Object , error ) {
39
+ if d == nil {
40
+ d = decoder
41
+ }
42
+ obj , _ , err := d .Decode (data , nil , nil )
39
43
if err != nil {
40
44
return nil , errors .Wrap (err , "failed to decode" )
41
45
}
42
46
if list , ok := obj .(* v1.List ); ok {
43
47
objs := make ([]k8sutil.Object , 0 , len (list .Items ))
44
48
for i , item := range list .Items {
45
- obj , _ , err := decoder .Decode (item .Raw , nil , nil )
49
+ obj , _ , err := d .Decode (item .Raw , nil , nil )
46
50
if err != nil {
47
51
return nil , errors .Wrapf (err , "decoding item %d in the list" , i )
48
52
}
@@ -103,7 +107,7 @@ func (l *lintContextImpl) renderValues(chrt *chart.Chart, values map[string]inte
103
107
return rendered , nil
104
108
}
105
109
106
- func (l * lintContextImpl ) loadObjectsFromHelmChart (dir string ) error {
110
+ func (l * lintContextImpl ) loadObjectsFromHelmChart (dir string , d runtime. Decoder ) error {
107
111
metadata := ObjectMetadata {FilePath : dir }
108
112
renderedFiles , err := l .renderHelmChart (dir )
109
113
if err != nil {
@@ -114,14 +118,14 @@ func (l *lintContextImpl) loadObjectsFromHelmChart(dir string) error {
114
118
// The first element of path will be the same as the last element of dir, because
115
119
// Helm duplicates it.
116
120
pathToTemplate := filepath .Join (filepath .Dir (dir ), path )
117
- if err := l .loadObjectsFromReader (pathToTemplate , strings .NewReader (contents )); err != nil {
121
+ if err := l .loadObjectsFromReader (pathToTemplate , strings .NewReader (contents ), d ); err != nil {
118
122
return errors .Wrapf (err , "loading objects from rendered helm chart %s/%s" , dir , pathToTemplate )
119
123
}
120
124
}
121
125
return nil
122
126
}
123
127
124
- func (l * lintContextImpl ) loadObjectsFromTgzHelmChart (tgzFile string ) error {
128
+ func (l * lintContextImpl ) loadObjectsFromTgzHelmChart (tgzFile string , d runtime. Decoder ) error {
125
129
metadata := ObjectMetadata {FilePath : tgzFile }
126
130
renderedFiles , err := l .renderTgzHelmChart (tgzFile )
127
131
if err != nil {
@@ -132,7 +136,7 @@ func (l *lintContextImpl) loadObjectsFromTgzHelmChart(tgzFile string) error {
132
136
// The first element of path will be the same as the last element of tgzFile, because
133
137
// Helm duplicates it.
134
138
pathToTemplate := filepath .Join (filepath .Dir (tgzFile ), path )
135
- if err := l .loadObjectsFromReader (pathToTemplate , strings .NewReader (contents )); err != nil {
139
+ if err := l .loadObjectsFromReader (pathToTemplate , strings .NewReader (contents ), d ); err != nil {
136
140
return errors .Wrapf (err , "loading objects from rendered helm chart %s/%s" , tgzFile , pathToTemplate )
137
141
}
138
142
}
@@ -182,7 +186,7 @@ func (l *lintContextImpl) parseValues(filePath string, bytes []byte) (map[string
182
186
return currentMap , nil
183
187
}
184
188
185
- func (l * lintContextImpl ) loadObjectFromYAMLReader (filePath string , r * yaml.YAMLReader ) error {
189
+ func (l * lintContextImpl ) loadObjectFromYAMLReader (filePath string , r * yaml.YAMLReader , d runtime. Decoder ) error {
186
190
doc , err := r .Read ()
187
191
if err != nil {
188
192
return err
@@ -197,7 +201,7 @@ func (l *lintContextImpl) loadObjectFromYAMLReader(filePath string, r *yaml.YAML
197
201
Raw : doc ,
198
202
}
199
203
200
- objs , err := parseObjects (doc )
204
+ objs , err := parseObjects (doc , d )
201
205
if err != nil {
202
206
l .addInvalidObjects (InvalidObject {
203
207
Metadata : metadata ,
@@ -214,7 +218,7 @@ func (l *lintContextImpl) loadObjectFromYAMLReader(filePath string, r *yaml.YAML
214
218
return nil
215
219
}
216
220
217
- func (l * lintContextImpl ) loadObjectsFromYAMLFile (filePath string , info os.FileInfo ) error {
221
+ func (l * lintContextImpl ) loadObjectsFromYAMLFile (filePath string , info os.FileInfo , d runtime. Decoder ) error {
218
222
if info .Size () > maxFileSizeBytes {
219
223
return nil
220
224
}
@@ -226,13 +230,13 @@ func (l *lintContextImpl) loadObjectsFromYAMLFile(filePath string, info os.FileI
226
230
_ = file .Close ()
227
231
}()
228
232
229
- return l .loadObjectsFromReader (filePath , file )
233
+ return l .loadObjectsFromReader (filePath , file , d )
230
234
}
231
235
232
- func (l * lintContextImpl ) loadObjectsFromReader (filePath string , reader io.Reader ) error {
236
+ func (l * lintContextImpl ) loadObjectsFromReader (filePath string , reader io.Reader , d runtime. Decoder ) error {
233
237
yamlReader := yaml .NewYAMLReader (bufio .NewReader (reader ))
234
238
for {
235
- if err := l .loadObjectFromYAMLReader (filePath , yamlReader ); err != nil {
239
+ if err := l .loadObjectFromYAMLReader (filePath , yamlReader , d ); err != nil {
236
240
if err == io .EOF {
237
241
return nil
238
242
}
0 commit comments