@@ -38,17 +38,16 @@ export async function kubeval(configs: Configs): Promise<void> {
3838 const strict = JSON . parse ( configs . getFunctionConfigValue ( STRICT ) || 'false' ) ;
3939
4040 const results : Result [ ] = [ ] ;
41+ const args = buildKubevalArgs (
42+ schemaLocation ,
43+ additionalSchemaLocations ,
44+ ignoreMissingSchemas ,
45+ skipKinds ,
46+ strict
47+ ) ;
4148
4249 for ( const object of configs . getAll ( ) ) {
43- await runKubeval (
44- object ,
45- results ,
46- schemaLocation ,
47- additionalSchemaLocations ,
48- ignoreMissingSchemas ,
49- skipKinds ,
50- strict
51- ) ;
50+ await runKubeval ( object , results , args ) ;
5251 }
5352
5453 configs . addResults ( ...results ) ;
@@ -57,37 +56,8 @@ export async function kubeval(configs: Configs): Promise<void> {
5756async function runKubeval (
5857 object : KubernetesObject ,
5958 results : Result [ ] ,
60- schemaLocation ?: string ,
61- additionalSchemaLocations ?: string [ ] ,
62- ignoreMissingSchemas ?: boolean ,
63- skipKinds ?: string [ ] ,
64- strict ?: boolean
59+ args : string [ ]
6560) : Promise < void > {
66- const args = [ '--output' , 'json' ] ;
67-
68- if ( schemaLocation ) {
69- args . push ( '--schema-location' ) ;
70- args . push ( schemaLocation ) ;
71- }
72-
73- if ( additionalSchemaLocations ) {
74- args . push ( '--additional-schema-locations' ) ;
75- args . push ( additionalSchemaLocations . join ( ',' ) ) ;
76- }
77-
78- if ( ignoreMissingSchemas ) {
79- args . push ( '--ignore-missing-schemas' ) ;
80- }
81-
82- if ( skipKinds ) {
83- args . push ( '--skip-kinds' ) ;
84- args . push ( skipKinds . join ( ',' ) ) ;
85- }
86-
87- if ( strict ) {
88- args . push ( '--strict' ) ;
89- }
90-
9161 const kubevalProcess = spawn ( 'kubeval' , args , {
9262 stdio : [ 'pipe' , 'pipe' , process . stderr ] ,
9363 } ) ;
@@ -132,6 +102,40 @@ async function runKubeval(
132102 }
133103}
134104
105+ function buildKubevalArgs (
106+ schemaLocation : string | undefined ,
107+ additionalSchemaLocations : string [ ] ,
108+ ignoreMissingSchemas : boolean ,
109+ skipKinds : string [ ] ,
110+ strict : boolean
111+ ) {
112+ const args = [ '--output' , 'json' ] ;
113+
114+ if ( schemaLocation ) {
115+ args . push ( '--schema-location' ) ;
116+ args . push ( schemaLocation ) ;
117+ }
118+
119+ if ( additionalSchemaLocations ) {
120+ args . push ( '--additional-schema-locations' ) ;
121+ args . push ( additionalSchemaLocations . join ( ',' ) ) ;
122+ }
123+
124+ if ( ignoreMissingSchemas ) {
125+ args . push ( '--ignore-missing-schemas' ) ;
126+ }
127+
128+ if ( skipKinds ) {
129+ args . push ( '--skip-kinds' ) ;
130+ args . push ( skipKinds . join ( ',' ) ) ;
131+ }
132+
133+ if ( strict ) {
134+ args . push ( '--strict' ) ;
135+ }
136+ return args ;
137+ }
138+
135139function writeToStream ( stream : Writable , data : string ) : Promise < void > {
136140 return new Promise ( ( resolve , reject ) =>
137141 stream . write ( data , 'utf-8' , err => ( err ? reject ( err ) : resolve ( ) ) )
0 commit comments