From 5865864cf3fd2f7b1836ea6e8bff07ca1f9b5ab9 Mon Sep 17 00:00:00 2001 From: Nick Hudson Date: Mon, 26 Sep 2022 07:02:51 -0500 Subject: [PATCH] Add configuration option to disable container logging (#472) Signed-off-by: Nick Hudson Signed-off-by: Nick Hudson --- pkg/chart/chart.go | 30 ++++++++++++++++-------------- pkg/config/config.go | 2 ++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 2c63f98f..3167a49c 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -901,22 +901,24 @@ func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string return } - printDetails(pod, "Logs of init container", "-", - func(item string) error { - return t.kubectl.Logs(namespace, pod, item) - }, initContainers...) + if t.config.PrintLogs { + printDetails(pod, "Logs of init container", "-", + func(item string) error { + return t.kubectl.Logs(namespace, pod, item) + }, initContainers...) - containers, err := t.kubectl.GetContainers(namespace, pod) - if err != nil { - fmt.Printf("failed printing logs: %v\n", err.Error()) - return - } + containers, err := t.kubectl.GetContainers(namespace, pod) + if err != nil { + fmt.Printf("failed printing logs: %v\n", err.Error()) + return + } - printDetails(pod, "Logs of container", "-", - func(item string) error { - return t.kubectl.Logs(namespace, pod, item) - }, - containers...) + printDetails(pod, "Logs of container", "-", + func(item string) error { + return t.kubectl.Logs(namespace, pod, item) + }, + containers...) + } } util.PrintDelimiterLineToWriter(os.Stdout, "=") diff --git a/pkg/config/config.go b/pkg/config/config.go index 1c849c8f..56e0f337 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -68,12 +68,14 @@ type Configuration struct { ReleaseLabel string `mapstructure:"release-label"` ExcludeDeprecated bool `mapstructure:"exclude-deprecated"` KubectlTimeout time.Duration `mapstructure:"kubectl-timeout"` + PrintLogs bool `mapstructure:"print-logs"` } func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*Configuration, error) { v := viper.New() v.SetDefault("kubectl-timeout", 30*time.Second) + v.SetDefault("print-logs", bool(true)) cmd.Flags().VisitAll(func(flag *flag.Flag) { flagName := flag.Name