Skip to content

Commit f53c402

Browse files
authored
Print events on cleanup (#155)
Signed-off-by: Reinhard Nägele <[email protected]>
1 parent e3c32f5 commit f53c402

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

pkg/chart/chart.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ type Helm interface {
9999
//
100100
// GetPods gets pods for the given args
101101
//
102+
// GetEvents prints all events for namespace
103+
//
102104
// DescribePod prints the pod's description
103105
//
104106
// Logs prints the logs of container
@@ -111,6 +113,7 @@ type Kubectl interface {
111113
WaitForDeployments(namespace string, selector string) error
112114
GetPodsforDeployment(namespace string, deployment string) ([]string, error)
113115
GetPods(args ...string) ([]string, error)
116+
GetEvents(namespace string) error
114117
DescribePod(namespace string, pod string) error
115118
Logs(namespace string, pod string, container string) error
116119
GetInitContainers(namespace string, pod string) ([]string, error)
@@ -608,13 +611,13 @@ func (t *Testing) generateInstallConfig(chart *Chart) (namespace, release, relea
608611
release, _ = chart.CreateInstallParams(t.config.BuildId)
609612
releaseSelector = fmt.Sprintf("%s=%s", t.config.ReleaseLabel, release)
610613
cleanup = func() {
611-
t.PrintPodDetailsAndLogs(namespace, releaseSelector)
614+
t.PrintEventsPodDetailsAndLogs(namespace, releaseSelector)
612615
t.helm.DeleteRelease(release)
613616
}
614617
} else {
615618
release, namespace = chart.CreateInstallParams(t.config.BuildId)
616619
cleanup = func() {
617-
t.PrintPodDetailsAndLogs(namespace, releaseSelector)
620+
t.PrintEventsPodDetailsAndLogs(namespace, releaseSelector)
618621
t.helm.DeleteRelease(release)
619622
t.kubectl.DeleteNamespace(namespace)
620623
}
@@ -812,7 +815,13 @@ func (t *Testing) ValidateMaintainers(chart *Chart) error {
812815
return nil
813816
}
814817

815-
func (t *Testing) PrintPodDetailsAndLogs(namespace string, selector string) {
818+
func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string) {
819+
util.PrintDelimiterLine("=")
820+
821+
printDetails(namespace, "Events of namespace", ".", func(item string) error {
822+
return t.kubectl.GetEvents(namespace)
823+
}, namespace)
824+
816825
pods, err := t.kubectl.GetPods(
817826
"--no-headers",
818827
"--namespace",
@@ -827,8 +836,6 @@ func (t *Testing) PrintPodDetailsAndLogs(namespace string, selector string) {
827836
return
828837
}
829838

830-
util.PrintDelimiterLine("=")
831-
832839
for _, pod := range pods {
833840
printDetails(pod, "Description of pod", "~", func(item string) error {
834841
return t.kubectl.DescribePod(namespace, pod)
@@ -861,12 +868,12 @@ func (t *Testing) PrintPodDetailsAndLogs(namespace string, selector string) {
861868
util.PrintDelimiterLine("=")
862869
}
863870

864-
func printDetails(pod string, text string, delimiterChar string, printFunc func(item string) error, items ...string) {
871+
func printDetails(resource string, text string, delimiterChar string, printFunc func(item string) error, items ...string) {
865872
for _, item := range items {
866873
item = strings.Trim(item, "'")
867874

868875
util.PrintDelimiterLine(delimiterChar)
869-
fmt.Printf("==> %s %s\n", text, pod)
876+
fmt.Printf("==> %s %s\n", text, resource)
870877
util.PrintDelimiterLine(delimiterChar)
871878

872879
if err := printFunc(item); err != nil {
@@ -875,7 +882,7 @@ func printDetails(pod string, text string, delimiterChar string, printFunc func(
875882
}
876883

877884
util.PrintDelimiterLine(delimiterChar)
878-
fmt.Printf("<== %s %s\n", text, pod)
885+
fmt.Printf("<== %s %s\n", text, resource)
879886
util.PrintDelimiterLine(delimiterChar)
880887
}
881888
}

pkg/tool/kubectl.go

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ func (k Kubectl) GetPods(args ...string) ([]string, error) {
184184
return strings.Fields(pods), nil
185185
}
186186

187+
func (k Kubectl) GetEvents(namespace string) error {
188+
return k.exec.RunProcess("kubectl", "get", "events", "--output", "wide", "--namespace", namespace)
189+
}
190+
187191
func (k Kubectl) DescribePod(namespace string, pod string) error {
188192
return k.exec.RunProcess("kubectl", "describe", "pod", pod, "--namespace", namespace)
189193
}

0 commit comments

Comments
 (0)