prow/config/config.go
func loadConfig(prowConfig, jobConfig string) (*Config, error) {
	stat, err := os.Stat(prowConfig)
	if err != nil {
		return nil, err
	}

	if stat.IsDir() {
		return nil, fmt.Errorf("prowConfig cannot be a dir - %s", prowConfig)
	}

	var nc Config
	if err := yamlToConfig(prowConfig, &nc); err != nil {
		return nil, err
	}
	if err := parseProwConfig(&nc); err != nil {
		return nil, err
	}

	// TODO(krzyzacy): temporary allow empty jobconfig
	//                 also temporary allow job config in prow config
	if jobConfig == "" {
		return &nc, nil
	}

	stat, err = os.Stat(jobConfig)
	if err != nil {
		return nil, err
	}

	if !stat.IsDir() {
		// still support a single file
		var jc JobConfig
		if err := yamlToConfig(jobConfig, &jc); err != nil {
			return nil, err
		}
		if err := nc.mergeJobConfig(jc); err != nil {
			return nil, err
		}
		return &nc, nil
	}

	// we need to ensure all config files have unique basenames,
	// since updateconfig plugin will use basename as a key in the configmap
	uniqueBasenames := sets.String{}

	err = filepath.Walk(jobConfig, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			logrus.WithError(err).Errorf("walking path %q.", path)
			// bad file should not stop us from parsing the directory
			return nil
		}

		if strings.HasPrefix(info.Name(), "..") {
			// kubernetes volumes also include files we
			// should not look be looking into for keys
			if info.IsDir() {
				return filepath.SkipDir
			}
			return nil
		}

		if filepath.Ext(path) != ".yaml" && filepath.Ext(path) != ".yml" {
			return nil
		}

		if info.IsDir() {
			return nil
		}

		base := filepath.Base(path)
		if uniqueBasenames.Has(base) {
			return fmt.Errorf("duplicated basename is not allowed: %s", base)
		}
		uniqueBasenames.Insert(base)

		var subConfig JobConfig
		if err := yamlToConfig(path, &subConfig); err != nil {
			return err
		}
		return nc.mergeJobConfig(subConfig)
	})

	if err != nil {
		return nil, err
	}

	return &nc, nil
}
func loadConfig(prowConfig, jobConfig string) (*Config, error) {
	stat, err := os.Stat(prowConfig)
	if err != nil {
		return nil, err
	}

	if stat.IsDir() {
		return nil, fmt.Errorf("prowConfig cannot be a dir - %s", prowConfig)
	}

	var nc Config
	if err := yamlToConfig(prowConfig, &nc); err != nil {
		return nil, err
	}
	if err := parseProwConfig(&nc); err != nil {
		return nil, err
	}

	// TODO(krzyzacy): temporary allow empty jobconfig
	//                 also temporary allow job config in prow config
	if jobConfig == "" {
		return &nc, nil
	}

	stat, err = os.Stat(jobConfig)
	if err != nil {
		return nil, err
	}

	if !stat.IsDir() {
		// still support a single file
		var jc JobConfig
		if err := yamlToConfig(jobConfig, &jc); err != nil {
			return nil, err
		}
		if err := nc.mergeJobConfig(jc); err != nil {
			return nil, err
		}
		return &nc, nil
	}

	// we need to ensure all config files have unique basenames,
	// since updateconfig plugin will use basename as a key in the configmap
	uniqueBasenames := sets.String{}

	err = filepath.Walk(jobConfig, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			logrus.WithError(err).Errorf("walking path %q.", path)
			// bad file should not stop us from parsing the directory
			return nil
		}

		if strings.HasPrefix(info.Name(), "..") {
			// kubernetes volumes also include files we
			// should not look be looking into for keys
			if info.IsDir() {
				return filepath.SkipDir
			}
			return nil
		}

		if filepath.Ext(path) != ".yaml" && filepath.Ext(path) != ".yml" {
			return nil
		}

		if info.IsDir() {
			return nil
		}

		base := filepath.Base(path)
		if uniqueBasenames.Has(base) {
			return fmt.Errorf("duplicated basename is not allowed: %s", base)
		}
		uniqueBasenames.Insert(base)

		var subConfig JobConfig
		if err := yamlToConfig(path, &subConfig); err != nil {
			return err
		}
		return nc.mergeJobConfig(subConfig)
	})

	if err != nil {
		return nil, err
	}

	return &nc, nil
}
func loadConfig ( prowConfig , jobConfig string ) ( * Config , error ) { stat , err := os . Stat ( prowConfig ) if err != nil { return nil , err } if stat . IsDir ( ) { return nil , fmt . Errorf ( " " , prowConfig ) } var nc Config if err := yamlToConfig ( prowConfig , & nc ) ; err != nil { return nil , err } if err := parseProwConfig ( & nc ) ; err != nil { return nil , err } // TODO(krzyzacy): temporary allow empty jobconfig //                 also temporary allow job config in prow config if jobConfig == " " { return & nc , nil } stat , err = os . Stat ( jobConfig ) if err != nil { return nil , err } if ! stat . IsDir ( ) { // still support a single file var jc JobConfig if err := yamlToConfig ( jobConfig , & jc ) ; err != nil { return nil , err } if err := nc . mergeJobConfig ( jc ) ; err != nil { return nil , err } return & nc , nil } // we need to ensure all config files have unique basenames, // since updateconfig plugin will use basename as a key in the configmap uniqueBasenames := sets . String { } err = filepath . Walk ( jobConfig , func ( path string , info os . FileInfo , err error ) error { if err != nil { logrus . WithError ( err ) . Errorf ( " " , path ) // bad file should not stop us from parsing the directory return nil } if strings . HasPrefix ( info . Name ( ) , " " ) { // kubernetes volumes also include files we // should not look be looking into for keys if info . IsDir ( ) { return filepath . SkipDir } return nil } if filepath . Ext ( path ) != " " && filepath . Ext ( path ) != " " { return nil } if info . IsDir ( ) { return nil } base := filepath . Base ( path ) if uniqueBasenames . Has ( base ) { return fmt . Errorf ( " " , base ) } uniqueBasenames . Insert ( base ) var subConfig JobConfig if err := yamlToConfig ( path , & subConfig ) ; err != nil { return err } return nc . mergeJobConfig ( subConfig ) } ) if err != nil { return nil , err } return & nc , nil }
// loadConfig loads one or multiple config files and returns a config object.
loadConfig loads one or multiple config files and returns a config object .