1
0
mirror of synced 2026-04-09 00:36:56 +00:00

refactor: flux check to return non-zero exit code on failure

Signed-off-by: h3nryc0ding <hr.richterhenry@gmail.com>
This commit is contained in:
h3nryc0ding
2025-04-12 18:20:01 +02:00
parent c436708a13
commit cfcd1cd439
3 changed files with 252 additions and 120 deletions

View File

@@ -18,6 +18,7 @@ package status
import (
"context"
"errors"
"fmt"
"sort"
"strings"
@@ -85,22 +86,20 @@ func (sc *StatusChecker) Assess(identifiers ...object.ObjMetadata) error {
sort.SliceStable(identifiers, func(i, j int) bool {
return strings.Compare(identifiers[i].Name, identifiers[j].Name) < 0
})
var errs []error
for _, id := range identifiers {
rs := coll.ResourceStatuses[id]
switch rs.Status {
case status.CurrentStatus:
sc.logger.Successf("%s: %s ready", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
case status.NotFoundStatus:
sc.logger.Failuref("%s: %s not found", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
default:
sc.logger.Failuref("%s: %s not ready", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind))
if rs.Status == status.NotFoundStatus {
errs = append(errs, fmt.Errorf("%s: %s not found", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind)))
} else if rs.Status != status.CurrentStatus {
errs = append(errs, fmt.Errorf("%s: %s not ready", rs.Identifier.Name, strings.ToLower(rs.Identifier.GroupKind.Kind)))
}
}
if coll.Error != nil || ctx.Err() == context.DeadlineExceeded {
return fmt.Errorf("timed out waiting for all resources to be ready")
if coll.Error != nil || errors.Is(ctx.Err(), context.DeadlineExceeded) {
errs = append(errs, fmt.Errorf("timeout waiting for resources to be ready"))
}
return nil
return errors.Join(errs...)
}
// desiredStatusNotifierFunc returns an Observer function for the