@@ -18,12 +18,10 @@ package utils
1818
1919import (
2020 "context"
21- "slices"
2221 "testing"
2322 "time"
2423
25- kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
26-
24+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2725 "k8s.io/apimachinery/pkg/runtime/schema"
2826 "k8s.io/apimachinery/pkg/types"
2927 "k8s.io/apimachinery/pkg/util/wait"
@@ -49,32 +47,21 @@ func WaitForBoundAPI(t *testing.T, ctx context.Context, client ctrlruntimeclient
4947 t .Helper ()
5048
5149 t .Logf ("Waiting for API %s/%s to be bound in kcp…" , gvr .Group , gvr .Resource )
52- err := wait .PollUntilContextTimeout (ctx , 500 * time .Millisecond , 1 * time .Minute , false , func (ctx context.Context ) (bool , error ) {
53- apiBindings := & kcpapisv1alpha1.APIBindingList {}
54- err := client .List (ctx , apiBindings )
55- if err != nil {
56- return false , err
57- }
5850
59- for _ , binding := range apiBindings .Items {
60- if bindingHasGVR (binding , gvr ) {
61- return true , nil
62- }
63- }
64-
65- return false , nil
51+ // Wait for actual resource availability instead of checking the APIBinding, because this is more
52+ // reliable, especially on slower CI environments.
53+ err := wait .PollUntilContextTimeout (ctx , 500 * time .Millisecond , 1 * time .Minute , false , func (ctx context.Context ) (bool , error ) {
54+ // Try to list resources of this type - if the resource isn't ready, this will fail
55+ list := & unstructured.UnstructuredList {}
56+ list .SetGroupVersionKind (schema.GroupVersionKind {
57+ Group : gvr .Group ,
58+ Version : gvr .Version ,
59+ Kind : gvr .Resource , // This will be corrected by the client
60+ })
61+
62+ return client .List (ctx , list ) == nil , nil
6663 })
6764 if err != nil {
6865 t .Fatalf ("Failed to wait for API %v to become available: %v" , gvr , err )
6966 }
7067}
71-
72- func bindingHasGVR (binding kcpapisv1alpha1.APIBinding , gvr schema.GroupVersionResource ) bool {
73- for _ , bound := range binding .Status .BoundResources {
74- if bound .Group == gvr .Group && bound .Resource == gvr .Resource && slices .Contains (bound .StorageVersions , gvr .Version ) {
75- return true
76- }
77- }
78-
79- return false
80- }
0 commit comments