Skip to content

Commit

Permalink
feat: warning logs when image pulls back off
Browse files Browse the repository at this point in the history
  • Loading branch information
abuchanan-airbyte committed Sep 9, 2024
1 parent d56c385 commit 0b71767
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions internal/cmd/local/local/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,35 +396,42 @@ func (c *Command) handleEvent(ctx context.Context, e *eventsv1.Event) {

switch {
case strings.EqualFold(e.Type, "normal"):
pterm.Debug.Println(e.Note)
if strings.EqualFold(e.Reason, "backoff") {
pterm.Warning.Println(e.Note)
} else {
pterm.Debug.Println(e.Note)
}

case strings.EqualFold(e.Type, "warning"):
var logs = ""
logs := ""
level := pterm.Debug

// only show the warning if the count is higher than 5
// TODO: replace DeprecatedCount
// Similar issue to DeprecatedLastTimestamp, the series attribute is always nil
if e.DeprecatedCount > 5 {
level = pterm.Warning
}

if strings.EqualFold(e.Reason, "backoff") {
var err error
logs, err = c.k8s.LogsGet(ctx, e.Regarding.Namespace, e.Regarding.Name)
if err != nil {
pterm.Debug.Printfln("Unable to retrieve logs for %s:%s\n %s", e.Regarding.Namespace, e.Regarding.Name, err)
logs = fmt.Sprintf("Unable to retrieve logs for %s:%s\n %s", e.Regarding.Namespace, e.Regarding.Name, err)
}
} else if strings.Contains(e.Note, "Failed to pull image") && strings.Contains(e.Note, "429 Too Many Requests") {
// The docker image is failing to pull because the user has hit a rate limit.
// This causes the install to go very slowly and possibly time out.
// Always warn in this case, so the user knows what's going on.
level = pterm.Warning
}

// TODO: replace DeprecatedCount
// Similar issue to DeprecatedLastTimestamp, the series attribute is always nil
if logs != "" {
msg := fmt.Sprintf("Encountered an issue deploying Airbyte:\n Pod: %s\n Reason: %s\n Message: %s\n Count: %d\n Logs: %s",
level.Printfln("Encountered an issue deploying Airbyte:\n Pod: %s\n Reason: %s\n Message: %s\n Count: %d\n Logs: %s",
e.Name, e.Reason, e.Note, e.DeprecatedCount, strings.TrimSpace(logs))
pterm.Debug.Println(msg)
// only show the warning if the count is higher than 5
if e.DeprecatedCount > 5 {
pterm.Warning.Printfln(msg)
}
} else {
msg := fmt.Sprintf("Encountered an issue deploying Airbyte:\n Pod: %s\n Reason: %s\n Message: %s\n Count: %d",
level.Printfln("Encountered an issue deploying Airbyte:\n Pod: %s\n Reason: %s\n Message: %s\n Count: %d",
e.Name, e.Reason, e.Note, e.DeprecatedCount)
pterm.Debug.Printfln(msg)
// only show the warning if the count is higher than 5
if e.DeprecatedCount > 5 {
pterm.Warning.Printfln(msg)
}
}

default:
Expand Down

0 comments on commit 0b71767

Please sign in to comment.