Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions test/utils/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,31 @@ func BindToAPIExport(t *testing.T, ctx context.Context, client ctrlruntimeclient
}

t.Logf("Creating APIBinding %q…", apiBinding.Name)
if err := client.Create(ctx, apiBinding); err != nil {

// Creating an APIBinding requires the "bind" permission on the APIExport. kcp checks this
// using its informer-based RBAC authorizer, which can lag behind freshly created workspaces
// (especially right after kcp has started), so retry on Forbidden errors for a while.
var lastErr error
err := wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 30*time.Second, true, func(ctx context.Context) (done bool, err error) {
lastErr = client.Create(ctx, apiBinding)
if lastErr == nil {
return true, nil
}

if apierrors.IsForbidden(lastErr) {
return false, nil
}

return false, lastErr
})
if err != nil {
if lastErr != nil {
err = lastErr
}
t.Fatalf("Failed to create APIBinding: %v", err)
}

err := wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 30*time.Second, false, func(ctx context.Context) (done bool, err error) {
err = wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 30*time.Second, false, func(ctx context.Context) (done bool, err error) {
err = client.Get(ctx, ctrlruntimeclient.ObjectKeyFromObject(apiBinding), apiBinding)
if err != nil {
return false, err
Expand Down
Loading