Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dump events in sandbox #802

Merged
merged 1 commit into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ func (f *Framework) RunWithSandbox(name string, t *testing.T, testFunc func(*tes
}

testFunc(t, sandbox)

sandbox.DumpSandboxInfo(t)
})
}

Expand Down
39 changes: 39 additions & 0 deletions pkg/e2e/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/ingress-gce/pkg/fuzz"
"sort"
"testing"
)

// Sandbox represents a sandbox for running tests in a Kubernetes cluster.
Expand Down Expand Up @@ -93,3 +95,40 @@ func (s *Sandbox) MasterUpgraded() bool {
func (s *Sandbox) MasterUpgrading() bool {
return s.f.statusManager.masterUpgrading()
}

// DumpSandboxInfo dumps information about the sandbox into logs
func (s *Sandbox) DumpSandboxInfo(t *testing.T) {
s.dumpSandboxEvents(t)
}

// dumpSandboxEvents dumps the events happened in the sandbox namespace into logs
func (s *Sandbox) dumpSandboxEvents(t *testing.T) {
t.Logf("Collecting events from namespace %q.", s.Namespace)
events, err := s.f.Clientset.CoreV1().Events(s.Namespace).List(metav1.ListOptions{})
if err != nil {
t.Logf("Failed to list events in namespace %q", s.Namespace)
return
}
t.Logf("Found %d events.", len(events.Items))
// Sort events by their first timestamp
sortedEvents := events.Items
if len(sortedEvents) > 1 {
sort.Sort(byFirstTimestamp(sortedEvents))
}
for _, e := range sortedEvents {
t.Logf("At %v - event for %v/%v: %v %v: %v", e.FirstTimestamp, e.Namespace, e.InvolvedObject.Name, e.Source, e.Reason, e.Message)
}
}

// byFirstTimestamp sorts a slice of events by first timestamp, using their involvedObject's name as a tie breaker.
type byFirstTimestamp []v1.Event

func (o byFirstTimestamp) Len() int { return len(o) }
func (o byFirstTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }

func (o byFirstTimestamp) Less(i, j int) bool {
if o[i].FirstTimestamp.Equal(&o[j].FirstTimestamp) {
return o[i].InvolvedObject.Name < o[j].InvolvedObject.Name
}
return o[i].FirstTimestamp.Before(&o[j].FirstTimestamp)
}