Skip to content

Commit 9617f8a

Browse files
committed
wait for Kube resource instead of APIBinding to make e2e tests more reliable
On-behalf-of: @SAP christoph.mewes@sap.com
1 parent 6d8fd96 commit 9617f8a

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

test/utils/wait.go

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ package utils
1818

1919
import (
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

Comments
 (0)