@@ -20,23 +20,22 @@ import { safeLoadAll } from 'js-yaml';
2020import * as path from 'path' ;
2121import {
2222 Configs ,
23- ConfigError ,
24- MultiConfigError ,
2523 isKubernetesObject ,
26- ConfigFileError ,
2724 addAnnotation ,
25+ configFileResult ,
2826 SOURCE_PATH_ANNOTATION ,
2927 SOURCE_INDEX_ANNOTATION ,
28+ Result ,
3029} from 'kpt-functions' ;
3130
3231export const SOURCE_DIR = 'source_dir' ;
33- export const FILTER_IVNALID = 'filter_invalid' ;
32+ export const FILTER_INVALID = 'filter_invalid' ;
3433
3534export async function readYaml ( configs : Configs ) {
3635 // Get the parameters.
3736 const sourceDir = configs . getFunctionConfigValueOrThrow ( SOURCE_DIR ) ;
3837 const ignoreInvalid =
39- configs . getFunctionConfigValue ( FILTER_IVNALID ) === 'true' ;
38+ configs . getFunctionConfigValue ( FILTER_INVALID ) === 'true' ;
4039
4140 // Discard any input objects since this is a source function.
4241 configs . deleteAll ( ) ;
@@ -45,17 +44,10 @@ export async function readYaml(configs: Configs) {
4544 const files = glob . sync ( sourceDir + '/**/*.+(yaml|yml)' ) ;
4645
4746 // Parse each file and convert it to a KubernetesObject.
48- const errors : ConfigError [ ] = files
47+ files
4948 . map ( f => parseFile ( configs , sourceDir , f , ignoreInvalid ) )
50- . filter ( err => err !== undefined )
51- . map ( err => err as ConfigError ) ;
52-
53- if ( errors . length ) {
54- throw new MultiConfigError (
55- `Found files containing invalid objects. To filter invalid objects set ${ FILTER_IVNALID } to 'true'.` ,
56- errors
57- ) ;
58- }
49+ . filter ( result => result !== undefined )
50+ . forEach ( result => configs . addResults ( result as Result ) ) ;
5951}
6052
6153readYaml . usage = `
@@ -64,7 +56,7 @@ Reads a directory of kubernetes YAML configs recursively.
6456Configured using a ConfigMap with the following keys:
6557
6658${ SOURCE_DIR } : Path to the config directory to read.
67- ${ FILTER_IVNALID } : [Optional] If 'true', ignores invalid Kubernetes objects instead of failing.
59+ ${ FILTER_INVALID } : [Optional] If 'true', ignores invalid Kubernetes objects instead of failing.
6860
6961Example:
7062
@@ -81,7 +73,7 @@ function parseFile(
8173 sourceDir : string ,
8274 file : string ,
8375 ignoreInvalid : boolean
84- ) : ConfigError | undefined {
76+ ) : Result | undefined {
8577 const contents = readFileOrThrow ( file ) ;
8678 let objects = safeLoadAll ( contents ) ;
8779
@@ -91,7 +83,7 @@ function parseFile(
9183 if ( ignoreInvalid ) {
9284 objects = objects . filter ( o => isKubernetesObject ( o ) ) ;
9385 } else {
94- return new ConfigFileError (
86+ return configFileResult (
9587 `File contains invalid Kubernetes objects '${ JSON . stringify (
9688 invalidObjects
9789 ) } '`,
0 commit comments