mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-08 02:44:20 +00:00
check that the recorded event is not nil on refreshExistingEventSeries
Signed-off-by: Yassine TIJANI <ytijani@vmware.com> Kubernetes-commit: 000c2c557f862270ec83341c1af3fcd7c6f7d4a2
This commit is contained in:
parent
9fc8bb16d6
commit
72094bc6d5
@ -111,11 +111,13 @@ func (e *eventBroadcasterImpl) refreshExistingEventSeries() {
|
||||
for isomorphicKey, event := range e.eventCache {
|
||||
if event.Series != nil {
|
||||
if recordedEvent, retry := recordEvent(e.sink, event); !retry {
|
||||
if recordedEvent != nil {
|
||||
e.eventCache[isomorphicKey] = recordedEvent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// finishSeries checks if a series has ended and either:
|
||||
// - write final count to the apiserver
|
||||
|
@ -30,6 +30,7 @@ import (
|
||||
k8sruntime "k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
ref "k8s.io/client-go/tools/reference"
|
||||
)
|
||||
|
||||
@ -299,10 +300,30 @@ func TestRefreshExistingEventSeries(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
LastObservedTime := metav1.MicroTime{Time: time.Now().Add(-9 * time.Minute)}
|
||||
|
||||
createEvent := make(chan *v1beta1.Event, 10)
|
||||
updateEvent := make(chan *v1beta1.Event, 10)
|
||||
patchEvent := make(chan *v1beta1.Event, 10)
|
||||
|
||||
table := []struct {
|
||||
patchFunc func(event *v1beta1.Event, patch []byte) (*v1beta1.Event, error)
|
||||
}{
|
||||
{
|
||||
patchFunc: func(event *v1beta1.Event, patch []byte) (*v1beta1.Event, error) {
|
||||
// event we receive is already patched, usually the sink uses it
|
||||
//only to retrieve the name and namespace, here we'll use it directly.
|
||||
patchEvent <- event
|
||||
return event, nil
|
||||
},
|
||||
},
|
||||
{
|
||||
patchFunc: func(event *v1beta1.Event, patch []byte) (*v1beta1.Event, error) {
|
||||
// we simulate an apiserver error here
|
||||
patchEvent <- nil
|
||||
return nil, &restclient.RequestConstructionError{}
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, item := range table {
|
||||
testEvents := testEventSeriesSink{
|
||||
OnCreate: func(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
createEvent <- event
|
||||
@ -312,12 +333,7 @@ func TestRefreshExistingEventSeries(t *testing.T) {
|
||||
updateEvent <- event
|
||||
return event, nil
|
||||
},
|
||||
OnPatch: func(event *v1beta1.Event, patch []byte) (*v1beta1.Event, error) {
|
||||
// event we receive is already patched, usually the sink uses it
|
||||
//only to retrieve the name and namespace, here we'll use it directly.
|
||||
patchEvent <- event
|
||||
return event, nil
|
||||
},
|
||||
OnPatch: item.patchFunc,
|
||||
}
|
||||
cache := map[eventKey]*v1beta1.Event{}
|
||||
eventBroadcaster := newBroadcaster(&testEvents, 0, cache).(*eventBroadcasterImpl)
|
||||
@ -343,7 +359,13 @@ func TestRefreshExistingEventSeries(t *testing.T) {
|
||||
if len(patchEvent) != 0 || len(createEvent) != 0 || len(updateEvent) != 0 {
|
||||
t.Errorf("exactly one event should be emitted, but got %v", len(patchEvent))
|
||||
}
|
||||
cacheEvent, exists := cache[cacheKey]
|
||||
|
||||
if cacheEvent == nil || !exists {
|
||||
t.Errorf("expected event to exist and not being nil, but instead event: %v and exists: %v", cacheEvent, exists)
|
||||
}
|
||||
case <-time.After(wait.ForeverTestTimeout):
|
||||
t.Fatalf("timeout after %v", wait.ForeverTestTimeout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user