@@ -5,10 +5,8 @@ package kubernetes
55
66import (
77 "context"
8+ "errors"
89 "fmt"
9- "io"
10- "log/slog"
11- "strings"
1210
1311 "k8s.io/apimachinery/pkg/runtime"
1412 "k8s.io/client-go/dynamic"
@@ -41,10 +39,7 @@ func WatcherForConfig(cfg *rest.Config) (watcher.StatusWatcher, error) {
4139}
4240
4341// WaitForReadyRuntime waits for all of the runtime objects to reach a ready state.
44- func WaitForReadyRuntime (ctx context.Context , sw watcher.StatusWatcher , robjs []runtime.Object , logger * slog.Logger ) error {
45- if logger == nil {
46- logger = slog .New (slog .NewTextHandler (io .Discard , & slog.HandlerOptions {}))
47- }
42+ func WaitForReadyRuntime (ctx context.Context , sw watcher.StatusWatcher , robjs []runtime.Object ) error {
4843 objs := []object.ObjMetadata {}
4944 for _ , robj := range robjs {
5045 obj , err := object .RuntimeToObjMeta (robj )
@@ -53,14 +48,11 @@ func WaitForReadyRuntime(ctx context.Context, sw watcher.StatusWatcher, robjs []
5348 }
5449 objs = append (objs , obj )
5550 }
56- return WaitForReady (ctx , sw , objs , logger )
51+ return WaitForReady (ctx , sw , objs )
5752}
5853
5954// WaitForReady waits for all of the objects to reach a ready state.
60- func WaitForReady (ctx context.Context , sw watcher.StatusWatcher , objs []object.ObjMetadata , logger * slog.Logger ) error {
61- if logger == nil {
62- logger = slog .New (slog .NewTextHandler (io .Discard , & slog.HandlerOptions {}))
63- }
55+ func WaitForReady (ctx context.Context , sw watcher.StatusWatcher , objs []object.ObjMetadata ) error {
6456 cancelCtx , cancel := context .WithCancel (ctx )
6557 defer cancel ()
6658
@@ -84,26 +76,27 @@ func WaitForReady(ctx context.Context, sw watcher.StatusWatcher, objs []object.O
8476 )
8577 <- done
8678
87- for _ , id := range objs {
88- rs := statusCollector .ResourceStatuses [id ]
89- switch rs .Status {
90- // TODO (@austinabro321) once callers have proper sloggers change logging here to use the slog style
91- case status .CurrentStatus :
92- logger .Debug (fmt .Sprintf ("%s: %s ready" , rs .Identifier .Name , strings .ToLower (rs .Identifier .GroupKind .Kind )))
93- case status .NotFoundStatus :
94- logger .Error (fmt .Sprintf ("%s: %s not found" , rs .Identifier .Name , strings .ToLower (rs .Identifier .GroupKind .Kind )))
95- default :
96- logger .Error (fmt .Sprintf ("%s: %s not ready" , rs .Identifier .Name , strings .ToLower (rs .Identifier .GroupKind .Kind )))
97- }
98- }
99-
10079 if statusCollector .Error != nil {
10180 return statusCollector .Error
10281 }
82+
10383 // Only check parent context error, otherwise we would error when desired status is achieved.
10484 if ctx .Err () != nil {
105- return ctx .Err ()
85+ errs := []error {}
86+ for _ , id := range objs {
87+ rs := statusCollector .ResourceStatuses [id ]
88+ switch rs .Status {
89+ case status .CurrentStatus :
90+ case status .NotFoundStatus :
91+ errs = append (errs , fmt .Errorf ("%s: %s not found" , rs .Identifier .Name , rs .Identifier .GroupKind .Kind ))
92+ default :
93+ errs = append (errs , fmt .Errorf ("%s: %s not ready" , rs .Identifier .Name , rs .Identifier .GroupKind .Kind ))
94+ }
95+ }
96+ errs = append (errs , ctx .Err ())
97+ return errors .Join (errs ... )
10698 }
99+
107100 return nil
108101}
109102
0 commit comments