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
21 changes: 21 additions & 0 deletions pkg/descheduler/kubeclientsandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

v1 "k8s.io/api/core/v1"
policy "k8s.io/api/policy/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -63,6 +64,26 @@ func setupTestSandbox(ctx context.Context, t *testing.T, initialObjects ...runti
realFactory.Start(ctx.Done())
realFactory.WaitForCacheSync(ctx.Done())

// Wait for initial objects to propagate from real client to fake client via event handlers.
for _, obj := range initialObjects {
Comment on lines +67 to +68
if err := wait.PollUntilContextTimeout(ctx, time.Second, 5*time.Second, true, func(ctx context.Context) (bool, error) {
exists, err := sandbox.hasRuntimeObjectInIndexer(obj)
if err != nil {
t.Logf("Error checking if object propagated to fake indexer: %v", err)
return false, nil
}
if !exists {
metaObj, _ := meta.Accessor(obj)
t.Logf("Initial object %s/%s has not propagated to fake indexer yet, waiting...", metaObj.GetNamespace(), metaObj.GetName())
}
return exists, nil
}); err != nil {
metaObj, _ := meta.Accessor(obj)
t.Fatalf("Initial object %s/%s did not propagate to fake indexer within timeout: %v",
metaObj.GetNamespace(), metaObj.GetName(), err)
}
}

return sandbox, realFactory, realClient
}

Expand Down