Skip to content

Commit

Permalink
Fix duplicated events on pod detail view (kubernetes#1971)
Browse files Browse the repository at this point in the history
* Fix duplicated events on pod detail view

* Fix test
  • Loading branch information
floreks authored May 19, 2017
1 parent af09719 commit de85041
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/app/backend/resource/event/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func GetPodEvents(client client.Interface, namespace, podName string) ([]api.Eve
return nil, err
}

l := podList.Items[:0]
l := make([]api.Pod, 0)
for _, pi := range podList.Items {
if pi.Name == podName {
l = append(l, pi)
Expand Down
16 changes: 4 additions & 12 deletions src/app/backend/resource/pod/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,17 @@ import (
// GetEventsForPod gets events that are associated with this pod.
func GetEventsForPod(client client.Interface, dsQuery *dataselect.DataSelectQuery, namespace,
podName string) (*common.EventList, error) {

// Get events for pod.
rsEvents, err := event.GetEvents(client, namespace, podName)
if err != nil {
return nil, err
}

// Get events for pods in job.

podEvents, err := event.GetPodEvents(client, namespace, podName)
if err != nil {
return nil, err
}

apiEvents := append(rsEvents, podEvents...)
if !event.IsTypeFilled(apiEvents) {
apiEvents = event.FillEventsType(apiEvents)
if !event.IsTypeFilled(podEvents) {
podEvents = event.FillEventsType(podEvents)
}

events := event.CreateEventList(apiEvents, dsQuery)
events := event.CreateEventList(podEvents, dsQuery)

log.Printf("Found %d events related to %s pod in %s namespace", len(events.Events), podName,
namespace)
Expand Down
30 changes: 21 additions & 9 deletions src/app/backend/resource/pod/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@ import (

func TestGetPodEvents(t *testing.T) {
cases := []struct {
namespace, name string
eventList *api.EventList
expected *common.EventList
namespace, podName string
eventList *api.EventList
podList *api.PodList
expected *common.EventList
}{
{
"ns-1", "dp-1",
"ns-1", "pod-1",
&api.EventList{Items: []api.Event{
{Message: "test-message", ObjectMeta: metaV1.ObjectMeta{
Name: "ev-1", Namespace: "ns-1", Labels: map[string]string{"app": "test"},
{
Message: "test-message",
ObjectMeta: metaV1.ObjectMeta{
Name: "ev-1", Namespace: "ns-1",
Labels: map[string]string{"app": "test"},
},
InvolvedObject: api.ObjectReference{UID: "test-uid"}},
}},
&api.PodList{Items: []api.Pod{
{ObjectMeta: metaV1.ObjectMeta{
Name: "pod-1",
Namespace: "ns-1",
UID: "test-uid",
}},
}},
&common.EventList{
Expand All @@ -37,12 +49,12 @@ func TestGetPodEvents(t *testing.T) {
}

for _, c := range cases {
fakeClient := fake.NewSimpleClientset(c.eventList)
fakeClient := fake.NewSimpleClientset(c.podList, c.eventList)

actual, _ := GetEventsForPod(fakeClient, dataselect.NoDataSelect, c.namespace, c.name)
actual, _ := GetEventsForPod(fakeClient, dataselect.NoDataSelect, c.namespace, c.podName)

if !reflect.DeepEqual(actual, c.expected) {
t.Errorf("GetEventsForPods(%#v) == \ngot %#v, \nexpected %#v", actual,
t.Errorf("GetEventsForPods == \ngot %#v, \nexpected %#v", actual,
c.expected)
}
}
Expand Down

0 comments on commit de85041

Please sign in to comment.