1
0
mirror of https://github.com/helm/chart-testing.git synced 2026-02-05 09:45:14 +01:00

Print config to stderr (#277)

Fixes a regression when the config file used is printed
to stdout even when the list-changed command is run. It is
now only printed when --print-config=true. Also, config printing
is now done to stderr so the flag can also be used in combination
with the list-changed command.

Signed-off-by: Reinhard Nägele <unguiculus@gmail.com>
This commit is contained in:
Reinhard Nägele
2020-09-25 22:22:43 +02:00
committed by GitHub
parent 9044b2f1a7
commit 43b9ced061
9 changed files with 36 additions and 17 deletions

View File

@@ -42,7 +42,11 @@ func newLintAndInstallCmd() *cobra.Command {
func lintAndInstall(cmd *cobra.Command, args []string) error {
fmt.Println("Linting and installing charts...")
configuration, err := config.LoadConfiguration(cfgFile, cmd, true)
printConfig, err := cmd.Flags().GetBool("print-config")
if err != nil {
return err
}
configuration, err := config.LoadConfiguration(cfgFile, cmd, printConfig)
if err != nil {
return fmt.Errorf("Error loading configuration: %s", err)
}

View File

@@ -41,7 +41,11 @@ func newListChangedCmd() *cobra.Command {
}
func listChanged(cmd *cobra.Command, args []string) error {
configuration, err := config.LoadConfiguration(cfgFile, cmd, false)
printConfig, err := cmd.Flags().GetBool("print-config")
if err != nil {
return err
}
configuration, err := config.LoadConfiguration(cfgFile, cmd, printConfig)
if err != nil {
return fmt.Errorf("Error loading configuration: %s", err)
}

View File

@@ -71,6 +71,9 @@ func addCommonFlags(flags *pflag.FlagSet) {
flags.StringSlice("excluded-charts", []string{}, heredoc.Doc(`
Charts that should be skipped. May be specified multiple times
or separate values with commas`))
flags.Bool("print-config", false, heredoc.Doc(`
Prints the configuration to stderr (caution: setting this may
expose sensitive data when helm-repo-extra-args contains passwords)`))
}
func addCommonLintAndInstallFlags(flags *pflag.FlagSet) {
@@ -94,7 +97,4 @@ func addCommonLintAndInstallFlags(flags *pflag.FlagSet) {
flags.Bool("debug", false, heredoc.Doc(`
Print CLI calls of external tools to stdout (caution: setting this may
expose sensitive data when helm-repo-extra-args contains passwords)`))
flags.Bool("print-config", false, heredoc.Doc(`
Prints the configuration to stdout (caution: setting this may
expose sensitive data when helm-repo-extra-args contains passwords)`))
}

View File

@@ -56,7 +56,7 @@ ct install [flags]
-h, --help help for install
--namespace string Namespace to install the release(s) into. If not specified, each release will be
installed in its own randomly generated namespace
--print-config Prints the configuration to stdout (caution: setting this may
--print-config Prints the configuration to stderr (caution: setting this may
expose sensitive data when helm-repo-extra-args contains passwords)
--release-label string The label to be used as a selector when inspecting resources created by charts.
This is only used if namespace is specified (default "app.kubernetes.io/instance")

View File

@@ -47,7 +47,7 @@ ct lint-and-install [flags]
that order
--namespace string Namespace to install the release(s) into. If not specified, each release will be
installed in its own randomly generated namespace
--print-config Prints the configuration to stdout (caution: setting this may
--print-config Prints the configuration to stderr (caution: setting this may
expose sensitive data when helm-repo-extra-args contains passwords)
--release-label string The label to be used as a selector when inspecting resources created by charts.
This is only used if namespace is specified (default "app.kubernetes.io/instance")

View File

@@ -53,7 +53,7 @@ ct lint [flags]
--lint-conf string The config file for YAML linting. If not specified, 'lintconf.yaml'
is searched in the current directory, '$HOME/.ct', and '/etc/ct', in
that order
--print-config Prints the configuration to stdout (caution: setting this may
--print-config Prints the configuration to stderr (caution: setting this may
expose sensitive data when helm-repo-extra-args contains passwords)
--remote string The name of the Git remote used to identify changed charts (default "origin")
--since string The Git reference used to identify changed charts (default "HEAD")

View File

@@ -20,6 +20,8 @@ ct list-changed [flags]
--excluded-charts strings Charts that should be skipped. May be specified multiple times
or separate values with commas
-h, --help help for list-changed
--print-config Prints the configuration to stderr (caution: setting this may
expose sensitive data when helm-repo-extra-args contains passwords)
--remote string The name of the Git remote used to identify changed charts (default "origin")
--since string The Git reference used to identify changed charts (default "HEAD")
--target-branch string The name of the target branch used to identify changed charts (default "master")
@@ -29,4 +31,4 @@ ct list-changed [flags]
* [ct](ct.md) - The Helm chart testing tool
###### Auto generated by spf13/cobra on 21-Apr-2020
###### Auto generated by spf13/cobra on 25-Sep-2020

View File

@@ -16,6 +16,7 @@ package config
import (
"fmt"
"os"
"path"
"reflect"
"strings"
@@ -96,7 +97,9 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*C
return nil, errors.Wrap(err, "Error loading config file")
}
} else {
fmt.Println("Using config file:", v.ConfigFileUsed())
if printConfig {
fmt.Fprintln(os.Stderr, "Using config file:", v.ConfigFileUsed())
}
}
isLint := strings.Contains(cmd.Use, "lint")
@@ -143,7 +146,7 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*C
}
if len(cfg.Charts) > 0 || cfg.ProcessAllCharts {
fmt.Println("Version increment checking disabled.")
fmt.Fprintln(os.Stderr, "Version increment checking disabled.")
cfg.CheckVersionIncrement = false
}
@@ -155,9 +158,9 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*C
}
func printCfg(cfg *Configuration) {
util.PrintDelimiterLine("-")
fmt.Println(" Configuration")
util.PrintDelimiterLine("-")
util.PrintDelimiterLineToWriter(os.Stderr, "-")
fmt.Fprintln(os.Stderr, " Configuration")
util.PrintDelimiterLineToWriter(os.Stderr, "-")
e := reflect.ValueOf(cfg).Elem()
typeOfCfg := e.Type()
@@ -170,10 +173,10 @@ func printCfg(cfg *Configuration) {
default:
pattern = "%s: %s\n"
}
fmt.Printf(pattern, typeOfCfg.Field(i).Name, e.Field(i).Interface())
fmt.Fprintf(os.Stderr, pattern, typeOfCfg.Field(i).Name, e.Field(i).Interface())
}
util.PrintDelimiterLine("-")
util.PrintDelimiterLineToWriter(os.Stderr, "-")
}
func findConfigFile(fileName string) (string, error) {

View File

@@ -16,6 +16,7 @@ package util
import (
"fmt"
"io"
"io/ioutil"
"math/rand"
"net"
@@ -210,12 +211,17 @@ func BreakingChangeAllowed(left string, right string) (bool, error) {
return !minor, err
}
// Deprecated: To be removed in v4. Use PrintDelimiterLineToWriter instead.
func PrintDelimiterLine(delimiterChar string) {
PrintDelimiterLineToWriter(os.Stdout, delimiterChar)
}
func PrintDelimiterLineToWriter(w io.Writer, delimiterChar string) {
delim := make([]string, 120)
for i := 0; i < 120; i++ {
delim[i] = delimiterChar
}
fmt.Println(strings.Join(delim, ""))
fmt.Fprintln(w, strings.Join(delim, ""))
}
func SanitizeName(s string, maxLength int) string {