Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Detect image issues. #678

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading