Skip to content

Commit

Permalink
🐛 Detect image issues. (#678)
Browse files Browse the repository at this point in the history
Detect malformed _fqin_ and image pull backoff. When detected, the task
is failed and reported with error and event.

Reported as:
```
events:
    - kind: ImageError
      reason: ImagePullBackOff
      last: 2024-06-27T11:04:14.088026727-07:00
    - kind: PodDeleted
      count: 1
      last: 2024-06-27T11:04:14.126638809-07:00
errors:
    - severity: Error
      description: 'Container (addon) failed: ImagePullBackOff'
```

Detects:
- CrashLoopBackOff,
- ImagePullBackOff
- CreateContainerConfigError
- InvalidImageName
- CreateContainerError

closes: #677

---------

Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel authored Jun 27, 2024
1 parent 9b4cc38 commit 83b8519
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
const (
AddonSelected = "AddonSelected"
ExtSelected = "ExtensionSelected"
ImageError = "ImageError"
PodNotFound = "PodNotFound"
PodCreated = "PodCreated"
PodRunning = "PodRunning"
Expand Down Expand Up @@ -945,7 +946,10 @@ func (m *Manager) podEvent(pod *core.Pod) (events []Event, err error) {

// podLogs - get and store pod logs as a Files.
func (m *Manager) podLogs(pod *core.Pod) (files []*model.File, err error) {
for _, container := range pod.Spec.Containers {
for _, container := range pod.Status.ContainerStatuses {
if container.State.Waiting != nil {
continue
}
f, nErr := m.containerLog(pod, container.Name)
if nErr == nil {
files = append(files, f)
Expand Down Expand Up @@ -1233,6 +1237,23 @@ func (r *Task) podPending(pod *core.Pod) {
status,
pod.Status.ContainerStatuses...)
for _, status := range status {
state := status.State
if state.Waiting != nil {
waiting := state.Waiting
reason := strings.ToLower(waiting.Reason)
if r.containsAny(reason, "invalid", "error", "backoff") {
r.Error(
"Error",
"Container (%s) failed: %s",
status.Name,
waiting.Reason)
mark := time.Now()
r.Terminated = &mark
r.Event(ImageError, waiting.Reason)
r.State = Failed
return
}
}
if status.Started == nil {
continue
}
Expand Down Expand Up @@ -1548,6 +1569,17 @@ func (r *Task) attach(file *model.File) {
})
}

// containsAny returns true when the str contains any of substr.
func (r *Task) containsAny(str string, substr ...string) (matched bool) {
for i := range substr {
if strings.Contains(str, substr[i]) {
matched = true
break
}
}
return
}

// Event represents a pod event.
type Event struct {
Type string
Expand Down

0 comments on commit 83b8519

Please sign in to comment.