Skip to content

Commit

Permalink
Print events on cleanup (#155)
Browse files Browse the repository at this point in the history
Signed-off-by: Reinhard Nägele <[email protected]>
  • Loading branch information
unguiculus authored May 3, 2019
1 parent e3c32f5 commit f53c402
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ type Helm interface {
//
// GetPods gets pods for the given args
//
// GetEvents prints all events for namespace
//
// DescribePod prints the pod's description
//
// Logs prints the logs of container
Expand All @@ -111,6 +113,7 @@ type Kubectl interface {
WaitForDeployments(namespace string, selector string) error
GetPodsforDeployment(namespace string, deployment string) ([]string, error)
GetPods(args ...string) ([]string, error)
GetEvents(namespace string) error
DescribePod(namespace string, pod string) error
Logs(namespace string, pod string, container string) error
GetInitContainers(namespace string, pod string) ([]string, error)
Expand Down Expand Up @@ -608,13 +611,13 @@ func (t *Testing) generateInstallConfig(chart *Chart) (namespace, release, relea
release, _ = chart.CreateInstallParams(t.config.BuildId)
releaseSelector = fmt.Sprintf("%s=%s", t.config.ReleaseLabel, release)
cleanup = func() {
t.PrintPodDetailsAndLogs(namespace, releaseSelector)
t.PrintEventsPodDetailsAndLogs(namespace, releaseSelector)
t.helm.DeleteRelease(release)
}
} else {
release, namespace = chart.CreateInstallParams(t.config.BuildId)
cleanup = func() {
t.PrintPodDetailsAndLogs(namespace, releaseSelector)
t.PrintEventsPodDetailsAndLogs(namespace, releaseSelector)
t.helm.DeleteRelease(release)
t.kubectl.DeleteNamespace(namespace)
}
Expand Down Expand Up @@ -812,7 +815,13 @@ func (t *Testing) ValidateMaintainers(chart *Chart) error {
return nil
}

func (t *Testing) PrintPodDetailsAndLogs(namespace string, selector string) {
func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string) {
util.PrintDelimiterLine("=")

printDetails(namespace, "Events of namespace", ".", func(item string) error {
return t.kubectl.GetEvents(namespace)
}, namespace)

pods, err := t.kubectl.GetPods(
"--no-headers",
"--namespace",
Expand All @@ -827,8 +836,6 @@ func (t *Testing) PrintPodDetailsAndLogs(namespace string, selector string) {
return
}

util.PrintDelimiterLine("=")

for _, pod := range pods {
printDetails(pod, "Description of pod", "~", func(item string) error {
return t.kubectl.DescribePod(namespace, pod)
Expand Down Expand Up @@ -861,12 +868,12 @@ func (t *Testing) PrintPodDetailsAndLogs(namespace string, selector string) {
util.PrintDelimiterLine("=")
}

func printDetails(pod string, text string, delimiterChar string, printFunc func(item string) error, items ...string) {
func printDetails(resource string, text string, delimiterChar string, printFunc func(item string) error, items ...string) {
for _, item := range items {
item = strings.Trim(item, "'")

util.PrintDelimiterLine(delimiterChar)
fmt.Printf("==> %s %s\n", text, pod)
fmt.Printf("==> %s %s\n", text, resource)
util.PrintDelimiterLine(delimiterChar)

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

util.PrintDelimiterLine(delimiterChar)
fmt.Printf("<== %s %s\n", text, pod)
fmt.Printf("<== %s %s\n", text, resource)
util.PrintDelimiterLine(delimiterChar)
}
}
4 changes: 4 additions & 0 deletions pkg/tool/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ func (k Kubectl) GetPods(args ...string) ([]string, error) {
return strings.Fields(pods), nil
}

func (k Kubectl) GetEvents(namespace string) error {
return k.exec.RunProcess("kubectl", "get", "events", "--output", "wide", "--namespace", namespace)
}

func (k Kubectl) DescribePod(namespace string, pod string) error {
return k.exec.RunProcess("kubectl", "describe", "pod", pod, "--namespace", namespace)
}
Expand Down

0 comments on commit f53c402

Please sign in to comment.