From 0872f19c2e9cf5a31717a02bc3370bd1c22bd377 Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Thu, 20 Jun 2024 18:06:59 +0200 Subject: [PATCH] feat: add wait for ready runtime (#105) ## Description Adds an alternative wait function to remove the need to create object meta slices and instead pass runtime objects. ## Related Issue N/A --- kubernetes/wait.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kubernetes/wait.go b/kubernetes/wait.go index 04d1477..c824870 100644 --- a/kubernetes/wait.go +++ b/kubernetes/wait.go @@ -6,6 +6,7 @@ package kubernetes import ( "context" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/discovery" "k8s.io/client-go/dynamic" "k8s.io/client-go/rest" @@ -37,7 +38,20 @@ func WatcherForConfig(cfg *rest.Config) (watcher.StatusWatcher, error) { return sw, nil } -// WaitForReady waits for all of the resources to reach a ready state. +// WaitForReadyRuntime waits for all of the runtime objects to reach a ready state. +func WaitForReadyRuntime(ctx context.Context, sw watcher.StatusWatcher, robjs []runtime.Object) error { + objs := []object.ObjMetadata{} + for _, robj := range robjs { + obj, err := object.RuntimeToObjMeta(robj) + if err != nil { + return err + } + objs = append(objs, obj) + } + return WaitForReady(ctx, sw, objs) +} + +// WaitForReady waits for all of the objects to reach a ready state. func WaitForReady(ctx context.Context, sw watcher.StatusWatcher, objs []object.ObjMetadata) error { cancelCtx, cancel := context.WithCancel(ctx) defer cancel()