Skip to content

Commit

Permalink
Return OOMKilled error if pod goes out of memory
Browse files Browse the repository at this point in the history
If scan job pod fails due to OOMKilled reason then
the error of specific type is returned to the caller

(cherry picked from commit 1775cc44bc125390d1340016b8df8683b849222c)
  • Loading branch information
nilesh-akhade committed Aug 22, 2022
1 parent 24bdc75 commit f50dc61
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/kube/runnable_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,13 @@ func (r *runnableJob) getTerminatedContainersErrors(ctx context.Context) error {
continue
}
klog.Errorf("Container %s terminated with %s: %s", container, status.Reason, status.Message)
return fmt.Errorf("container %s terminated with %s: %s", container, status.Reason, status.Message)
var containerErr error
if status.Reason == "OOMKilled" {
containerErr = &errOOMKilled{container: container}
} else {
containerErr = fmt.Errorf("container %s terminated with %s: %s", container, status.Reason, status.Message)
}
return containerErr
}
return nil
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/kube/starboard.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
package kube

import (
"fmt"
"time"
)

var ErrOOMKilled *errOOMKilled

type errOOMKilled struct {
container string
}

func (e *errOOMKilled) Error() string {
return fmt.Sprintf("container %s terminated with OOMKilled", e.container)
}

func (e *errOOMKilled) Is(target error) bool {
if _, ok := target.(*errOOMKilled); ok {
return true
}
return false
}

// ScannerOpts holds configuration of the vulnerability Scanner.
// TODO Rename to CLIConfig and move it to the cmd package
type ScannerOpts struct {
Expand Down

0 comments on commit f50dc61

Please sign in to comment.