Skip to content

Commit

Permalink
VPA - protection against malformed pod status in OomObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
schylek committed Jan 16, 2019
1 parent 50e20f0 commit 879b674
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (o *observer) OnUpdate(oldObj, newObj interface{}) {

for _, containerStatus := range newPod.Status.ContainerStatuses {
if containerStatus.RestartCount > 0 &&
containerStatus.LastTerminationState.Terminated != nil &&
containerStatus.LastTerminationState.Terminated.Reason == "OOMKilled" {

oldStatus := findStatus(containerStatus.Name, oldPod.Status.ContainerStatuses)
Expand Down
15 changes: 15 additions & 0 deletions vertical-pod-autoscaler/pkg/recommender/input/oom/observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ func TestOOMReceived(t *testing.T) {
assert.Equal(t, timestamp.Unix(), info.Timestamp.Unix())
}

func TestMalformedPodReceived(t *testing.T) {
p1, err := newPod(pod1Yaml)
assert.NoError(t, err)
p2, err := newPod(pod2Yaml)
assert.NoError(t, err)

// Malformed pod: restart count > 0, but last termination status is nil
p2.Status.ContainerStatuses[0].RestartCount = 1
p2.Status.ContainerStatuses[0].LastTerminationState.Terminated = nil

observer := NewObserver()
observer.OnUpdate(p1, p2)
assert.Empty(t, observer.observedOomsChannel)
}

func TestParseEvictionEvent(t *testing.T) {
parseTimestamp := func(str string) time.Time {
timestamp, err := time.Parse(time.RFC3339, "2018-02-23T13:38:48Z")
Expand Down

0 comments on commit 879b674

Please sign in to comment.