Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions cmd/caib/buildcmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ const (
phaseRunning = "Running"
phaseUploading = "Uploading"

errPrefixBuild = "build"
errPrefixFlash = "flash"
errPrefixPush = "push"
)

// Options wires build handlers to caller-owned state and helper functions.
Expand Down
11 changes: 2 additions & 9 deletions cmd/caib/buildcmd/flash_feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,30 @@ func (h *Handler) displayFlashInstructions(st *buildapitypes.BuildResponse, isFa
}

colorsSupported := h.supportsColorOutput()
var headerColor, commandColor, infoColor func(...any) string
var headerPrefix, commandPrefix string
var commandColor, infoColor func(...any) string
var commandPrefix string

if isFailure {
if colorsSupported {
headerColor = color.New(color.FgHiRed, color.Bold).SprintFunc()
commandColor = color.New(color.FgHiYellow, color.Bold).SprintFunc()
infoColor = color.New(color.FgHiWhite).SprintFunc()
} else {
headerColor = func(a ...any) string { return fmt.Sprint(a...) }
commandColor = func(a ...any) string { return fmt.Sprint(a...) }
infoColor = func(a ...any) string { return fmt.Sprint(a...) }
headerPrefix = "[!] "
commandPrefix = ">> "
}
} else {
if colorsSupported {
headerColor = color.New(color.FgHiWhite, color.Bold).SprintFunc()
commandColor = color.New(color.FgHiGreen, color.Bold).SprintFunc()
infoColor = color.New(color.FgHiYellow).SprintFunc()
} else {
headerColor = func(a ...any) string { return fmt.Sprint(a...) }
commandColor = func(a ...any) string { return fmt.Sprint(a...) }
infoColor = func(a ...any) string { return fmt.Sprint(a...) }
headerPrefix = "[*] "
commandPrefix = ">> "
}
}

if isFailure {
fmt.Printf("\n%s%s\n", headerPrefix, headerColor("Manual Flash Required"))
fmt.Printf("%s\n", infoColor("Flash failed, but you can flash manually using Jumpstarter:"))
} else {
fmt.Printf("%s\n", infoColor("Jumpstarter is available for flashing:"))
Expand Down
25 changes: 5 additions & 20 deletions cmd/caib/buildcmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,12 @@ func (h *Handler) waitForBuildCompletion(ctx context.Context, api *buildapiclien
}
if st.Phase == phaseFailed {
pb.Clear()
errPrefix := errPrefixBuild
isFlashFailure := false

if strings.Contains(strings.ToLower(st.Message), errPrefixFlash) {
errPrefix = errPrefixFlash
isFlashFailure = true
} else if strings.Contains(strings.ToLower(st.Message), errPrefixPush) {
errPrefix = errPrefixPush
} else if lastPhase == phaseFlashing {
errPrefix = errPrefixFlash
isFlashFailure = true
} else if lastPhase == "Pushing" {
errPrefix = errPrefixPush
} else if *h.opts.FlashAfterBuild &&
(lastPhase == phaseFlashing || strings.Contains(strings.ToLower(st.Message), errPrefixFlash)) {
errPrefix = errPrefixFlash
isFlashFailure = true
}
isFlashFailure := strings.Contains(strings.ToLower(st.Message), errPrefixFlash) ||
lastPhase == phaseFlashing

handleErr := fmt.Errorf("%s failed: %s", errPrefix, st.Message)
if isFlashFailure {
handleErr := fmt.Errorf("%s", st.Message)
if isFlashFailure || *h.opts.FlashAfterBuild {
h.displayBuildResults(ctx, api, name)
h.handleFlashError(handleErr, st)
} else {
h.handleError(handleErr)
Expand Down
22 changes: 21 additions & 1 deletion internal/controller/imagebuild/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (r *ImageBuildReconciler) checkBuildProgress(
// Build failed - cleanup transient secrets
r.cleanupTransientSecrets(ctx, imageBuild, r.Log)

if err := r.updateStatus(ctx, imageBuild, phaseFailed, pipelineRunFailureMessage(pipelineRun)); err != nil {
if err := r.updateStatus(ctx, imageBuild, phaseFailed, r.pipelineRunFailureDetail(ctx, pipelineRun)); err != nil {
log.Error(err, "Failed to update status to Failed")
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -1517,6 +1517,26 @@ func pipelineRunFailureMessage(pipelineRun *tektonv1.PipelineRun) string {
return "Build failed"
}

func (r *ImageBuildReconciler) pipelineRunFailureDetail(ctx context.Context, pipelineRun *tektonv1.PipelineRun) string {
for _, child := range pipelineRun.Status.ChildReferences {
if child.PipelineTaskName != "flash-image" {
continue
}
taskRun := &tektonv1.TaskRun{}
if err := r.Get(ctx, types.NamespacedName{
Name: child.Name,
Namespace: pipelineRun.Namespace,
}, taskRun); err != nil {
break
}
Comment thread
bkhizgiy marked this conversation as resolved.
if isTaskRunCompleted(taskRun) && !isTaskRunSuccessful(taskRun) {
return taskRunFailureMessage(taskRun, "Flash failed")
}
break
}
return pipelineRunFailureMessage(pipelineRun)
}

func taskRunFailureMessage(taskRun *tektonv1.TaskRun, fallback string) string {
for _, condition := range taskRun.Status.Conditions {
if condition.Type == conditionSucceeded && condition.Status != corev1.ConditionTrue && condition.Message != "" {
Expand Down
Loading