Skip to content

Commit

Permalink
Print k8s pods if a poller times out
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Mar 14, 2019
1 parent d259c9b commit 735ccd2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions integration/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package integration

import (
"context"
"fmt"
"os/exec"
"testing"
"time"
Expand Down Expand Up @@ -95,6 +96,7 @@ func (k *NSKubernetesClient) WaitForPodsReady(podNames ...string) {
waitLoop:
select {
case <-ctx.Done():
k.debug("pods")
k.t.Fatalf("Timed out waiting for pods %v ready in namespace %s", podNames, k.ns)

case event := <-w.ResultChan():
Expand Down Expand Up @@ -147,6 +149,8 @@ func (k *NSKubernetesClient) WaitForDeploymentsToStabilize(depNames ...string) {
waitLoop:
select {
case <-ctx.Done():
k.debug("deployments.apps")
k.debug("pods")
k.t.Fatalf("Timed out waiting for deployments %v to stabilize in namespace %s", depNames, k.ns)

case event := <-w.ResultChan():
Expand All @@ -167,6 +171,16 @@ func (k *NSKubernetesClient) WaitForDeploymentsToStabilize(depNames ...string) {
}
}

// debug is used to print all the details about pods or deployments
func (k *NSKubernetesClient) debug(entities string) {
cmd := exec.Command("kubectl", "-n", k.ns, "get", entities, "-oyaml")
out, _ := cmd.CombinedOutput()

logrus.Warnln(cmd.Args)
// Use fmt.Println, not logrus, for prettier output
fmt.Println(string(out))
}

func isStable(dp *appsv1.Deployment) bool {
return dp.Generation <= dp.Status.ObservedGeneration && *(dp.Spec.Replicas) == dp.Status.Replicas
}

0 comments on commit 735ccd2

Please sign in to comment.