Skip to content

Commit

Permalink
fix: cover more error reason messages (#759)
Browse files Browse the repository at this point in the history
* fix: cover more error reasons (#758)

Signed-off-by: Jesang Myung <jesang.myung@gmail.com>

* fix: refactoring for simplify conditions

Signed-off-by: Jesang Myung <jesang.myung@gmail.com>

---------

Signed-off-by: Jesang Myung <jesang.myung@gmail.com>
  • Loading branch information
jmyung committed Nov 20, 2023
1 parent 3e3f6a9 commit 5b27c3e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pkg/analyzer/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ func (PodAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) {

// Check through container status to check for crashes or unready
for _, containerStatus := range pod.Status.ContainerStatuses {

if containerStatus.State.Waiting != nil {
if containerStatus.State.Waiting.Reason == "CrashLoopBackOff" || containerStatus.State.Waiting.Reason == "ImagePullBackOff" || containerStatus.State.Waiting.Reason == "CreateContainerConfigError" {
if containerStatus.State.Waiting.Message != "" {
failures = append(failures, common.Failure{
Text: containerStatus.State.Waiting.Message,
Sensitive: []common.Sensitive{},
})
}

if isErrorReason(containerStatus.State.Waiting.Reason) && containerStatus.State.Waiting.Message != "" {
failures = append(failures, common.Failure{
Text: containerStatus.State.Waiting.Message,
Sensitive: []common.Sensitive{},
})
}

// This represents a container that is still being created or blocked due to conditions such as OOMKilled
if containerStatus.State.Waiting.Reason == "ContainerCreating" && pod.Status.Phase == "Pending" {

Expand Down Expand Up @@ -125,3 +126,16 @@ func (PodAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) {

return a.Results, nil
}

func isErrorReason(reason string) bool {
failureReasons := []string{
"CrashLoopBackOff", "ImagePullBackOff", "CreateContainerConfigError", "PreCreateHookError", "CreateContainerError", "PreStartHookError", "RunContainerError", "ImageInspectError", "ErrImagePull", "ErrImageNeverPull", "InvalidImageName",
}

for _, r := range failureReasons {
if r == reason {
return true
}
}
return false
}

0 comments on commit 5b27c3e

Please sign in to comment.