@@ -136,24 +136,8 @@ export const validateTemplates = async (): Promise<void> => {
136
136
const argv : HelmArguments = getParsedArgs ( )
137
137
await setup ( argv )
138
138
await processCrdWrapper ( argv )
139
- const constraintKinds = [
140
- 'PspAllowedRepos' ,
141
- 'BannedImageTags' ,
142
- 'ContainerLimits' ,
143
- 'PspAllowedUsers' ,
144
- 'PspHostFilesystem' ,
145
- 'PspHostNetworkingPorts' ,
146
- 'PspPrivileged' ,
147
- 'PspApparmor' ,
148
- 'PspCapabilities' ,
149
- 'PspForbiddenSysctls' ,
150
- 'PspHostSecurity' ,
151
- 'PspSeccomp' ,
152
- 'PspSelinux' ,
153
- ]
154
- // TODO: revisit these excluded resources and see it they exist now (from original sh script)
155
- const skipKinds = [ 'CustomResourceDefinition' , ...constraintKinds ]
156
- const skipFilenames = [ 'crd' , 'constraint' , 'knative-operator' , 'buildpack' , 'docker' , 'git-clone' , 'kaniko' ]
139
+ const skipKinds = [ 'CustomResourceDefinition' ]
140
+ const skipFilenames = [ 'crd' ]
157
141
158
142
d . log ( 'Validating resources' )
159
143
const verbose = argv . verbose ? [ '-verbose' ] : [ ]
@@ -162,47 +146,33 @@ export const validateTemplates = async (): Promise<void> => {
162
146
d . info ( `Skip Filenames: ${ skipFilenames . join ( ', ' ) } ` )
163
147
d . info ( `K8S Resource Path: ${ k8sResourcesPath } ` )
164
148
d . info ( `Schema location: file://${ schemaOutputPath } ` )
165
- const kubevalOutput = await nothrow (
166
- $ `kubeconform -skip ${ skipKinds . join ( ',' ) } -ignore-filename-pattern ${ skipFilenames . join (
167
- '|' ,
168
- ) } -schema-location ${ schemaOutputPath } /${ vk8sVersion } -standalone/{{.ResourceKind}}{{.KindSuffix}}.json ${ k8sResourcesPath } `,
149
+ const skipPatterns = skipFilenames . flatMap ( ( filename ) => [ '-ignore-filename-pattern' , filename ] )
150
+ d . info (
151
+ `Running command: kubeconform -skip ${ skipKinds . join (
152
+ ',' ,
153
+ ) } ${ skipPatterns } -schema-location ${ schemaOutputPath } /${ vk8sVersion } -standalone/{{.ResourceKind}}{{.KindSuffix}}.json -summary -output json ${ verbose } ${ k8sResourcesPath } `,
169
154
)
170
155
171
- let passCount = 0
172
- let warnCount = 0
173
- let errCount = 0
174
- let prev = ''
175
- ; `${ kubevalOutput . stdout } \n${ kubevalOutput . stderr } ` . split ( '\n' ) . forEach ( ( x ) => {
176
- if ( x === '' ) return
177
- const [ left , right ] = x . split ( ' - ' )
178
- const k = left ? left . trim ( ) : ''
179
- const v = right ? right . trim ( ) : ''
180
- switch ( k ) {
181
- case 'PASS' :
182
- passCount += 1
183
- break
184
- case 'WARN' :
185
- warnCount += 1
186
- d . warn ( `${ chalk . yellowBright ( 'WARN' ) } : %s` , v )
187
- break
188
- case 'ERR' :
189
- errCount += 1
190
- d . error ( `${ chalk . redBright ( 'INFO' ) } : %s` , prev )
191
- d . error ( `${ chalk . redBright ( 'ERR' ) } : %s` , v )
192
- break
193
- default :
194
- break
195
- }
196
- prev = x
197
- } )
198
- d . info ( `${ chalk . greenBright ( 'TOTAL PASS' ) } : %s` , `${ passCount } files` )
199
- d . info ( `${ chalk . yellowBright ( 'TOTAL WARN' ) } : %s` , `${ warnCount } files` )
200
- d . info ( `${ chalk . redBright ( 'TOTAL ERR' ) } : %s` , `${ errCount } files` )
201
-
202
- if ( kubevalOutput . exitCode !== 0 ) {
203
- d . info ( 'Kubeval output: %s' , kubevalOutput . stdout )
204
- throw new Error ( `Template validation FAILED: ${ kubevalOutput . exitCode } ` )
205
- } else d . log ( 'Template validation SUCCESS' )
156
+ const kubeconformOutput = await nothrow (
157
+ $ `kubeconform -skip ${ skipKinds . join (
158
+ ',' ,
159
+ ) } ${ skipPatterns } -schema-location ${ schemaOutputPath } /${ vk8sVersion } -standalone/{{.ResourceKind}}{{.KindSuffix}}.json -summary -output json ${ verbose } ${ k8sResourcesPath } `,
160
+ )
161
+
162
+ if ( kubeconformOutput . exitCode !== 0 ) {
163
+ d . info ( 'Kubeconform output: %s' , kubeconformOutput . toString ( ) )
164
+ throw new Error ( `Template validation FAILED: ${ kubeconformOutput . exitCode } ` )
165
+ }
166
+
167
+ const parsedOutput = JSON . parse ( kubeconformOutput . stdout )
168
+ const { valid, invalid, errors, skipped } = parsedOutput . summary
169
+
170
+ d . info ( `${ chalk . greenBright ( 'TOTAL PASS' ) } : %s` , `${ valid } files` )
171
+ d . info ( `${ chalk . magentaBright ( 'TOTAL SKIP' ) } : %s` , `${ skipped } files` )
172
+ d . info ( `${ chalk . yellowBright ( 'TOTAL WARN' ) } : %s` , `${ invalid } files` )
173
+ d . info ( `${ chalk . redBright ( 'TOTAL ERR' ) } : %s` , `${ errors } files` )
174
+
175
+ d . log ( 'Template validation SUCCESS' )
206
176
}
207
177
208
178
export const module = {
0 commit comments