Skip to content

Commit

Permalink
🐛 Detect image issues; reapply pr-678 (#708)
Browse files Browse the repository at this point in the history
Re-apply reverted #678  re-based on current main.

---------

Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel authored Jul 5, 2024
1 parent 220be5d commit b3dd69d
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 @@ -51,6 +51,7 @@ const (
const (
AddonSelected = "AddonSelected"
ExtSelected = "ExtensionSelected"
ImageError = "ImageError"
PodNotFound = "PodNotFound"
PodCreated = "PodCreated"
PodRunning = "PodRunning"
Expand Down Expand Up @@ -946,7 +947,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 @@ -1234,6 +1238,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 @@ -1549,6 +1570,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 b3dd69d

Please sign in to comment.