From 8e78199cce64dbed1402f30f44ebf0adc27216cb Mon Sep 17 00:00:00 2001 From: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Date: Wed, 10 Jun 2020 09:39:29 +0200 Subject: [PATCH] chore: emit used project config & defaults to log (#1633) * print used project config * print used project defaults --- cmd/piper.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/cmd/piper.go b/cmd/piper.go index 194920894..caa972a55 100644 --- a/cmd/piper.go +++ b/cmd/piper.go @@ -134,6 +134,8 @@ func PrepareConfig(cmd *cobra.Command, metadata *config.StepData, stepName strin if len(GeneralConfig.StepConfigJSON) != 0 { // ignore config & defaults in favor of passed stepConfigJSON stepConfig = config.GetStepConfigWithJSON(flagValues, GeneralConfig.StepConfigJSON, filters) + log.Entry().Infof("Project config: passed via JSON") + log.Entry().Infof("Project defaults: passed via JSON") } else { // use config & defaults var customConfig io.ReadCloser @@ -141,31 +143,33 @@ func PrepareConfig(cmd *cobra.Command, metadata *config.StepData, stepName strin //accept that config file and defaults cannot be loaded since both are not mandatory here { projectConfigFile := getProjectConfigFile(GeneralConfig.CustomConfig) - - exists, err := piperutils.FileExists(projectConfigFile) - if exists { + if exists, err := piperutils.FileExists(projectConfigFile); exists { + log.Entry().Infof("Project config: '%s'", projectConfigFile) if customConfig, err = openFile(projectConfigFile); err != nil { return errors.Wrapf(err, "Cannot read '%s'", projectConfigFile) } } else { - log.Entry().Infof("Project config file '%s' does not exist. No project configuration available.", projectConfigFile) + log.Entry().Infof("Project config: NONE ('%s' does not exist)", projectConfigFile) customConfig = nil } - } var defaultConfig []io.ReadCloser - for _, f := range GeneralConfig.DefaultConfig { - fc, err := openFile(f) + if len(GeneralConfig.DefaultConfig) == 0 { + log.Entry().Info("Project defaults: NONE") + } + for _, projectDefaultFile := range GeneralConfig.DefaultConfig { + fc, err := openFile(projectDefaultFile) // only create error for non-default values - if err != nil && f != ".pipeline/defaults.yaml" { - return errors.Wrapf(err, "config: getting defaults failed: '%v'", f) - } - if err == nil { + if err != nil { + if projectDefaultFile != ".pipeline/defaults.yaml" { + log.Entry().Infof("Project defaults: '%s'", projectDefaultFile) + return errors.Wrapf(err, "Cannot read '%s'", projectDefaultFile) + } + } else { + log.Entry().Infof("Project defaults: '%s'", projectDefaultFile) defaultConfig = append(defaultConfig, fc) - log.Entry().Infof("Added default config '%s'", f) } } - stepConfig, err = myConfig.GetStepConfig(flagValues, GeneralConfig.ParametersJSON, customConfig, defaultConfig, GeneralConfig.IgnoreCustomDefaults, filters, metadata.Spec.Inputs.Parameters, metadata.Spec.Inputs.Secrets, resourceParams, GeneralConfig.StageName, stepName, metadata.Metadata.Aliases) if err != nil { return errors.Wrap(err, "retrieving step configuration failed")