Skip to content

Commit 314c0ba

Browse files
committed
fix: ensure flux check returns non-zero exit code on failure
Signed-off-by: h3nryc0ding <[email protected]>
1 parent f0fecf7 commit 314c0ba

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

cmd/flux/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
277277
}
278278
logger.Waitingf("verifying installation")
279279
if err := statusChecker.Assess(componentRefs...); err != nil {
280-
return fmt.Errorf("install failed")
280+
return fmt.Errorf("install failed: %w", err)
281281
}
282282

283283
logger.Successf("install finished")

pkg/status/status.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package status
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"sort"
2324
"strings"
@@ -85,19 +86,28 @@ func (sc *StatusChecker) Assess(identifiers ...object.ObjMetadata) error {
8586
sort.SliceStable(identifiers, func(i, j int) bool {
8687
return strings.Compare(identifiers[i].Name, identifiers[j].Name) < 0
8788
})
89+
var errs []error
8890
for _, id := range identifiers {
8991
rs := coll.ResourceStatuses[id]
9092
switch rs.Status {
9193
case status.CurrentStatus:
9294
sc.logger.Successf("%s: %s ready", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
9395
case status.NotFoundStatus:
94-
sc.logger.Failuref("%s: %s not found", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
96+
errMsg := fmt.Sprintf("%s: %s not found", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
97+
sc.logger.Failuref(errMsg)
98+
errs = append(errs, errors.New(errMsg))
9599
default:
96-
sc.logger.Failuref("%s: %s not ready", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
100+
errMsg := fmt.Sprintf("%s: %s not ready", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
101+
sc.logger.Failuref(errMsg)
102+
errs = append(errs, errors.New(errMsg))
97103
}
98104
}
99105

100-
if coll.Error != nil || ctx.Err() == context.DeadlineExceeded {
106+
if len(errs) > 0 {
107+
return errors.Join(errs...)
108+
}
109+
110+
if coll.Error != nil || errors.Is(ctx.Err(), context.DeadlineExceeded) {
101111
return fmt.Errorf("timed out waiting for all resources to be ready")
102112
}
103113
return nil

0 commit comments

Comments
 (0)