Skip to content

Commit c37f2d9

Browse files
committed
refactor: only show init container logs if --debug is specified
1 parent bdeaa4c commit c37f2d9

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

cmd/purge.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ devspace purge -d my-deployment
7070

7171
purgeCmd.Flags().StringSliceVar(&cmd.SkipDependency, "skip-dependency", []string{}, "Skips the following dependencies from purging")
7272
purgeCmd.Flags().StringSliceVar(&cmd.Dependency, "dependency", []string{}, "Purges only the specific named dependencies")
73-
7473
return purgeCmd
7574
}
7675

pkg/devspace/services/targetselector/until_newest_running.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"github.com/loft-sh/devspace/pkg/util/scanner"
66
"github.com/loft-sh/devspace/pkg/util/stringutil"
7+
"github.com/sirupsen/logrus"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89
"sort"
910
"strings"
@@ -94,22 +95,24 @@ func (u *PodInfoPrinter) PrintPodInfo(client kubectl.Client, pod *v1.Pod, log lo
9495

9596
if time.Since(u.lastWarning) > time.Second*10 {
9697
// show init container logs if init container is running
97-
for _, initContainer := range pod.Status.InitContainerStatuses {
98-
if !stringutil.Contains(u.printedInitContainers, initContainer.Name) && initContainer.State.Running != nil {
99-
// show logs of this currently running init container
100-
log.Infof("Printing init container logs of pod %s", pod.Name)
101-
reader, err := client.Logs(context.TODO(), pod.Namespace, pod.Name, initContainer.Name, false, nil, true)
102-
if err != nil {
103-
log.Warnf("Error reading init container logs: %v", err)
104-
} else {
105-
scanner := scanner.NewScanner(reader)
106-
for scanner.Scan() {
107-
log.Info(scanner.Text())
98+
if log.GetLevel() == logrus.DebugLevel {
99+
for _, initContainer := range pod.Status.InitContainerStatuses {
100+
if !stringutil.Contains(u.printedInitContainers, initContainer.Name) && initContainer.State.Running != nil {
101+
// show logs of this currently running init container
102+
log.Infof("Printing init container logs of pod %s", pod.Name)
103+
reader, err := client.Logs(context.TODO(), pod.Namespace, pod.Name, initContainer.Name, false, nil, true)
104+
if err != nil {
105+
log.Warnf("Error reading init container logs: %v", err)
106+
} else {
107+
scanner := scanner.NewScanner(reader)
108+
for scanner.Scan() {
109+
log.Info(scanner.Text())
110+
}
108111
}
109-
}
110112

111-
u.printedInitContainers = append(u.printedInitContainers, initContainer.Name)
112-
return
113+
u.printedInitContainers = append(u.printedInitContainers, initContainer.Name)
114+
return
115+
}
113116
}
114117
}
115118

0 commit comments

Comments
 (0)