Fix tests to to only accesses keys from under resourcePrefix

Kubernetes-commit: 1ac067ae0e68b14a7a6eff464aacdaf7d70e838d
This commit is contained in:
Marek Siarkowicz 2025-09-03 12:23:07 +02:00 committed by Kubernetes Publisher
parent 6d430c71ae
commit 677aaf0c38
8 changed files with 79 additions and 79 deletions

View File

@ -65,12 +65,12 @@ func TestDryRunCreateDoesntCreate(t *testing.T) {
obj := UnstructuredOrDie(`{"kind": "Pod"}`) obj := UnstructuredOrDie(`{"kind": "Pod"}`)
out := UnstructuredOrDie(`{}`) out := UnstructuredOrDie(`{}`)
err := s.Create(context.Background(), "key", obj, out, 0, true) err := s.Create(context.Background(), "/pods/key", obj, out, 0, true)
if err != nil { if err != nil {
t.Fatalf("Failed to create new dry-run object: %v", err) t.Fatalf("Failed to create new dry-run object: %v", err)
} }
err = s.Get(context.Background(), "key", storage.GetOptions{}, out) err = s.Get(context.Background(), "/pods/key", storage.GetOptions{}, out)
if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeKeyNotFound { if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeKeyNotFound {
t.Errorf("Expected key to be not found, error: %v", err) t.Errorf("Expected key to be not found, error: %v", err)
} }
@ -83,7 +83,7 @@ func TestDryRunCreateReturnsObject(t *testing.T) {
obj := UnstructuredOrDie(`{"kind": "Pod"}`) obj := UnstructuredOrDie(`{"kind": "Pod"}`)
out := UnstructuredOrDie(`{}`) out := UnstructuredOrDie(`{}`)
err := s.Create(context.Background(), "key", obj, out, 0, true) err := s.Create(context.Background(), "/pods/key", obj, out, 0, true)
if err != nil { if err != nil {
t.Fatalf("Failed to create new dry-run object: %v", err) t.Fatalf("Failed to create new dry-run object: %v", err)
} }
@ -100,12 +100,12 @@ func TestDryRunCreateExistingObjectFails(t *testing.T) {
obj := UnstructuredOrDie(`{"kind": "Pod"}`) obj := UnstructuredOrDie(`{"kind": "Pod"}`)
out := UnstructuredOrDie(`{}`) out := UnstructuredOrDie(`{}`)
err := s.Create(context.Background(), "key", obj, out, 0, false) err := s.Create(context.Background(), "/pods/key", obj, out, 0, false)
if err != nil { if err != nil {
t.Fatalf("Failed to create new object: %v", err) t.Fatalf("Failed to create new object: %v", err)
} }
err = s.Create(context.Background(), "key", obj, out, 0, true) err = s.Create(context.Background(), "/pods/key", obj, out, 0, true)
if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeKeyExists { if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeKeyExists {
t.Errorf("Expected KeyExists error: %v", err) t.Errorf("Expected KeyExists error: %v", err)
} }
@ -122,7 +122,7 @@ func TestDryRunUpdateMissingObjectFails(t *testing.T) {
return input, nil, errors.New("UpdateFunction shouldn't be called") return input, nil, errors.New("UpdateFunction shouldn't be called")
} }
err := s.GuaranteedUpdate(context.Background(), "key", obj, false, nil, updateFunc, true, nil) err := s.GuaranteedUpdate(context.Background(), "/pods/key", obj, false, nil, updateFunc, true, nil)
if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeKeyNotFound { if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeKeyNotFound {
t.Errorf("Expected key to be not found, error: %v", err) t.Errorf("Expected key to be not found, error: %v", err)
} }
@ -134,7 +134,7 @@ func TestDryRunUpdatePreconditions(t *testing.T) {
obj := UnstructuredOrDie(`{"kind": "Pod", "metadata": {"uid": "my-uid"}}`) obj := UnstructuredOrDie(`{"kind": "Pod", "metadata": {"uid": "my-uid"}}`)
out := UnstructuredOrDie(`{}`) out := UnstructuredOrDie(`{}`)
err := s.Create(context.Background(), "key", obj, out, 0, false) err := s.Create(context.Background(), "/pods/key", obj, out, 0, false)
if err != nil { if err != nil {
t.Fatalf("Failed to create new object: %v", err) t.Fatalf("Failed to create new object: %v", err)
} }
@ -149,12 +149,12 @@ func TestDryRunUpdatePreconditions(t *testing.T) {
} }
wrongID := types.UID("wrong-uid") wrongID := types.UID("wrong-uid")
myID := types.UID("my-uid") myID := types.UID("my-uid")
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, &storage.Preconditions{UID: &wrongID}, updateFunc, true, nil) err = s.GuaranteedUpdate(context.Background(), "/pods/key", obj, false, &storage.Preconditions{UID: &wrongID}, updateFunc, true, nil)
if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeInvalidObj { if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeInvalidObj {
t.Errorf("Expected invalid object, error: %v", err) t.Errorf("Expected invalid object, error: %v", err)
} }
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, &storage.Preconditions{UID: &myID}, updateFunc, true, nil) err = s.GuaranteedUpdate(context.Background(), "/pods/key", obj, false, &storage.Preconditions{UID: &myID}, updateFunc, true, nil)
if err != nil { if err != nil {
t.Fatalf("Failed to update with valid precondition: %v", err) t.Fatalf("Failed to update with valid precondition: %v", err)
} }
@ -167,7 +167,7 @@ func TestDryRunUpdateDoesntUpdate(t *testing.T) {
obj := UnstructuredOrDie(`{"kind": "Pod"}`) obj := UnstructuredOrDie(`{"kind": "Pod"}`)
created := UnstructuredOrDie(`{}`) created := UnstructuredOrDie(`{}`)
err := s.Create(context.Background(), "key", obj, created, 0, false) err := s.Create(context.Background(), "/pods/key", obj, created, 0, false)
if err != nil { if err != nil {
t.Fatalf("Failed to create new object: %v", err) t.Fatalf("Failed to create new object: %v", err)
} }
@ -181,12 +181,12 @@ func TestDryRunUpdateDoesntUpdate(t *testing.T) {
return u, nil, nil return u, nil, nil
} }
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, nil, updateFunc, true, nil) err = s.GuaranteedUpdate(context.Background(), "/pods/key", obj, false, nil, updateFunc, true, nil)
if err != nil { if err != nil {
t.Fatalf("Failed to dry-run update: %v", err) t.Fatalf("Failed to dry-run update: %v", err)
} }
out := UnstructuredOrDie(`{}`) out := UnstructuredOrDie(`{}`)
err = s.Get(context.Background(), "key", storage.GetOptions{}, out) err = s.Get(context.Background(), "/pods/key", storage.GetOptions{}, out)
if err != nil { if err != nil {
t.Fatalf("Failed to get storage: %v", err) t.Fatalf("Failed to get storage: %v", err)
} }
@ -202,7 +202,7 @@ func TestDryRunUpdateReturnsObject(t *testing.T) {
obj := UnstructuredOrDie(`{"kind": "Pod"}`) obj := UnstructuredOrDie(`{"kind": "Pod"}`)
out := UnstructuredOrDie(`{}`) out := UnstructuredOrDie(`{}`)
err := s.Create(context.Background(), "key", obj, out, 0, false) err := s.Create(context.Background(), "/pods/key", obj, out, 0, false)
if err != nil { if err != nil {
t.Fatalf("Failed to create new object: %v", err) t.Fatalf("Failed to create new object: %v", err)
} }
@ -216,7 +216,7 @@ func TestDryRunUpdateReturnsObject(t *testing.T) {
return u, nil, nil return u, nil, nil
} }
err = s.GuaranteedUpdate(context.Background(), "key", obj, false, nil, updateFunc, true, nil) err = s.GuaranteedUpdate(context.Background(), "/pods/key", obj, false, nil, updateFunc, true, nil)
if err != nil { if err != nil {
t.Fatalf("Failed to dry-run update: %v", err) t.Fatalf("Failed to dry-run update: %v", err)
} }
@ -233,17 +233,17 @@ func TestDryRunDeleteDoesntDelete(t *testing.T) {
obj := UnstructuredOrDie(`{"kind": "Pod"}`) obj := UnstructuredOrDie(`{"kind": "Pod"}`)
out := UnstructuredOrDie(`{}`) out := UnstructuredOrDie(`{}`)
err := s.Create(context.Background(), "key", obj, out, 0, false) err := s.Create(context.Background(), "/pods/key", obj, out, 0, false)
if err != nil { if err != nil {
t.Fatalf("Failed to create new object: %v", err) t.Fatalf("Failed to create new object: %v", err)
} }
err = s.Delete(context.Background(), "key", out, nil, rest.ValidateAllObjectFunc, true, nil, storage.DeleteOptions{}) err = s.Delete(context.Background(), "/pods/key", out, nil, rest.ValidateAllObjectFunc, true, nil, storage.DeleteOptions{})
if err != nil { if err != nil {
t.Fatalf("Failed to dry-run delete the object: %v", err) t.Fatalf("Failed to dry-run delete the object: %v", err)
} }
err = s.Get(context.Background(), "key", storage.GetOptions{}, out) err = s.Get(context.Background(), "/pods/key", storage.GetOptions{}, out)
if err != nil { if err != nil {
t.Fatalf("Failed to retrieve dry-run deleted object: %v", err) t.Fatalf("Failed to retrieve dry-run deleted object: %v", err)
} }
@ -254,7 +254,7 @@ func TestDryRunDeleteMissingObjectFails(t *testing.T) {
defer destroy() defer destroy()
out := UnstructuredOrDie(`{}`) out := UnstructuredOrDie(`{}`)
err := s.Delete(context.Background(), "key", out, nil, rest.ValidateAllObjectFunc, true, nil, storage.DeleteOptions{}) err := s.Delete(context.Background(), "/pods/key", out, nil, rest.ValidateAllObjectFunc, true, nil, storage.DeleteOptions{})
if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeKeyNotFound { if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeKeyNotFound {
t.Errorf("Expected key to be not found, error: %v", err) t.Errorf("Expected key to be not found, error: %v", err)
} }
@ -267,14 +267,14 @@ func TestDryRunDeleteReturnsObject(t *testing.T) {
obj := UnstructuredOrDie(`{"kind": "Pod"}`) obj := UnstructuredOrDie(`{"kind": "Pod"}`)
out := UnstructuredOrDie(`{}`) out := UnstructuredOrDie(`{}`)
err := s.Create(context.Background(), "key", obj, out, 0, false) err := s.Create(context.Background(), "/pods/key", obj, out, 0, false)
if err != nil { if err != nil {
t.Fatalf("Failed to create new object: %v", err) t.Fatalf("Failed to create new object: %v", err)
} }
out = UnstructuredOrDie(`{}`) out = UnstructuredOrDie(`{}`)
expected := UnstructuredOrDie(`{"kind": "Pod", "metadata": {"resourceVersion": "2"}}`) expected := UnstructuredOrDie(`{"kind": "Pod", "metadata": {"resourceVersion": "2"}}`)
err = s.Delete(context.Background(), "key", out, nil, rest.ValidateAllObjectFunc, true, nil, storage.DeleteOptions{}) err = s.Delete(context.Background(), "/pods/key", out, nil, rest.ValidateAllObjectFunc, true, nil, storage.DeleteOptions{})
if err != nil { if err != nil {
t.Fatalf("Failed to delete with valid precondition: %v", err) t.Fatalf("Failed to delete with valid precondition: %v", err)
} }
@ -290,19 +290,19 @@ func TestDryRunDeletePreconditions(t *testing.T) {
obj := UnstructuredOrDie(`{"kind": "Pod", "metadata": {"uid": "my-uid"}}`) obj := UnstructuredOrDie(`{"kind": "Pod", "metadata": {"uid": "my-uid"}}`)
out := UnstructuredOrDie(`{}`) out := UnstructuredOrDie(`{}`)
err := s.Create(context.Background(), "key", obj, out, 0, false) err := s.Create(context.Background(), "/pods/key", obj, out, 0, false)
if err != nil { if err != nil {
t.Fatalf("Failed to create new object: %v", err) t.Fatalf("Failed to create new object: %v", err)
} }
wrongID := types.UID("wrong-uid") wrongID := types.UID("wrong-uid")
myID := types.UID("my-uid") myID := types.UID("my-uid")
err = s.Delete(context.Background(), "key", out, &storage.Preconditions{UID: &wrongID}, rest.ValidateAllObjectFunc, true, nil, storage.DeleteOptions{}) err = s.Delete(context.Background(), "/pods/key", out, &storage.Preconditions{UID: &wrongID}, rest.ValidateAllObjectFunc, true, nil, storage.DeleteOptions{})
if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeInvalidObj { if e, ok := err.(*storage.StorageError); !ok || e.Code != storage.ErrCodeInvalidObj {
t.Errorf("Expected invalid object, error: %v", err) t.Errorf("Expected invalid object, error: %v", err)
} }
err = s.Delete(context.Background(), "key", out, &storage.Preconditions{UID: &myID}, rest.ValidateAllObjectFunc, true, nil, storage.DeleteOptions{}) err = s.Delete(context.Background(), "/pods/key", out, &storage.Preconditions{UID: &myID}, rest.ValidateAllObjectFunc, true, nil, storage.DeleteOptions{})
if err != nil { if err != nil {
t.Fatalf("Failed to delete with valid precondition: %v", err) t.Fatalf("Failed to delete with valid precondition: %v", err)
} }

View File

@ -64,7 +64,7 @@ import (
) )
func newTestCacherWithoutSyncing(s storage.Interface, c clock.WithTicker) (*Cacher, storage.Versioner, error) { func newTestCacherWithoutSyncing(s storage.Interface, c clock.WithTicker) (*Cacher, storage.Versioner, error) {
prefix := "pods" prefix := "/pods"
config := Config{ config := Config{
Storage: s, Storage: s,
Versioner: storage.APIObjectVersioner{}, Versioner: storage.APIObjectVersioner{},
@ -626,7 +626,7 @@ apiserver_watch_cache_consistent_read_total{fallback="true", group="", resource=
} }
start := cacher.clock.Now() start := cacher.clock.Now()
err = delegator.GetList(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: "", Recursive: true}, result) err = delegator.GetList(context.TODO(), "/pods/ns", storage.ListOptions{ResourceVersion: "", Recursive: true}, result)
clockStepCancelFn() clockStepCancelFn()
duration := cacher.clock.Since(start) duration := cacher.clock.Since(start)
if (err != nil) != tc.expectError { if (err != nil) != tc.expectError {
@ -718,7 +718,7 @@ func TestMatchExactResourceVersionFallback(t *testing.T) {
delegator := NewCacheDelegator(cacher, backingStorage) delegator := NewCacheDelegator(cacher, backingStorage)
result := &example.PodList{} result := &example.PodList{}
err = delegator.GetList(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: "20", ResourceVersionMatch: metav1.ResourceVersionMatchExact, Recursive: true}, result) err = delegator.GetList(context.TODO(), "/pods/ns", storage.ListOptions{ResourceVersion: "20", ResourceVersionMatch: metav1.ResourceVersionMatchExact, Recursive: true}, result)
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
@ -761,7 +761,7 @@ func TestGetListNonRecursiveCacheBypass(t *testing.T) {
// Inject error to underlying layer and check if cacher is not bypassed. // Inject error to underlying layer and check if cacher is not bypassed.
backingStorage.injectGetListError(errDummy) backingStorage.injectGetListError(errDummy)
err = delegator.GetList(context.TODO(), "pods/ns", storage.ListOptions{ err = delegator.GetList(context.TODO(), "/pods/ns", storage.ListOptions{
ResourceVersion: "0", ResourceVersion: "0",
Predicate: pred, Predicate: pred,
}, result) }, result)
@ -769,7 +769,7 @@ func TestGetListNonRecursiveCacheBypass(t *testing.T) {
t.Errorf("GetList with Limit and RV=0 should be served from cache: %v", err) t.Errorf("GetList with Limit and RV=0 should be served from cache: %v", err)
} }
err = delegator.GetList(context.TODO(), "pods/ns", storage.ListOptions{ err = delegator.GetList(context.TODO(), "/pods/ns", storage.ListOptions{
ResourceVersion: "", ResourceVersion: "",
Predicate: pred, Predicate: pred,
}, result) }, result)
@ -842,7 +842,7 @@ func TestGetListNonRecursiveCacheWithConsistentListFromCache(t *testing.T) {
defer delegator.Stop() defer delegator.Stop()
// Setup test object // Setup test object
key := "pods/ns" key := "/pods/ns"
input := &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "ns"}} input := &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "ns"}}
if err := v.UpdateObject(input, 100); err != nil { if err := v.UpdateObject(input, 100); err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
@ -917,7 +917,7 @@ func TestGetCacheBypass(t *testing.T) {
// Inject error to underlying layer and check if cacher is not bypassed. // Inject error to underlying layer and check if cacher is not bypassed.
backingStorage.injectGetListError(errDummy) backingStorage.injectGetListError(errDummy)
err = delegator.Get(context.TODO(), "pods/ns/pod-0", storage.GetOptions{ err = delegator.Get(context.TODO(), "/pods/ns/pod-0", storage.GetOptions{
IgnoreNotFound: true, IgnoreNotFound: true,
ResourceVersion: "0", ResourceVersion: "0",
}, result) }, result)
@ -925,7 +925,7 @@ func TestGetCacheBypass(t *testing.T) {
t.Errorf("Get with RV=0 should be served from cache: %v", err) t.Errorf("Get with RV=0 should be served from cache: %v", err)
} }
err = delegator.Get(context.TODO(), "pods/ns/pod-0", storage.GetOptions{ err = delegator.Get(context.TODO(), "/pods/ns/pod-0", storage.GetOptions{
IgnoreNotFound: true, IgnoreNotFound: true,
ResourceVersion: "", ResourceVersion: "",
}, result) }, result)
@ -1120,7 +1120,7 @@ func TestWatchNotHangingOnStartupFailure(t *testing.T) {
// Watch hangs waiting on watchcache being initialized. // Watch hangs waiting on watchcache being initialized.
// Ensure that it terminates when its context is cancelled // Ensure that it terminates when its context is cancelled
// (e.g. the request is terminated for whatever reason). // (e.g. the request is terminated for whatever reason).
_, err = cacher.Watch(ctx, "pods/ns", storage.ListOptions{ResourceVersion: "0"}) _, err = cacher.Watch(ctx, "/pods/ns", storage.ListOptions{ResourceVersion: "0"})
if !utilfeature.DefaultFeatureGate.Enabled(features.ResilientWatchCacheInitialization) { if !utilfeature.DefaultFeatureGate.Enabled(features.ResilientWatchCacheInitialization) {
if err == nil || err.Error() != apierrors.NewServiceUnavailable(context.Canceled.Error()).Error() { if err == nil || err.Error() != apierrors.NewServiceUnavailable(context.Canceled.Error()).Error() {
t.Errorf("Unexpected error: %#v", err) t.Errorf("Unexpected error: %#v", err)
@ -1165,7 +1165,7 @@ func TestWatcherNotGoingBackInTime(t *testing.T) {
totalPods := 100 totalPods := 100
// Create watcher that will be slowing down reading. // Create watcher that will be slowing down reading.
w1, err := cacher.Watch(context.TODO(), "pods/ns", storage.ListOptions{ w1, err := cacher.Watch(context.TODO(), "/pods/ns", storage.ListOptions{
ResourceVersion: "999", ResourceVersion: "999",
Predicate: storage.Everything, Predicate: storage.Everything,
}) })
@ -1190,7 +1190,7 @@ func TestWatcherNotGoingBackInTime(t *testing.T) {
} }
// Create fast watcher and ensure it will get each object exactly once. // Create fast watcher and ensure it will get each object exactly once.
w2, err := cacher.Watch(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: "999", Predicate: storage.Everything}) w2, err := cacher.Watch(context.TODO(), "/pods/ns", storage.ListOptions{ResourceVersion: "999", Predicate: storage.Everything})
if err != nil { if err != nil {
t.Fatalf("Failed to create watch: %v", err) t.Fatalf("Failed to create watch: %v", err)
} }
@ -1235,7 +1235,7 @@ func TestCacherDontAcceptRequestsStopped(t *testing.T) {
} }
} }
w, err := delegator.Watch(context.Background(), "pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: storage.Everything}) w, err := delegator.Watch(context.Background(), "/pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: storage.Everything})
if err != nil { if err != nil {
t.Fatalf("Failed to create watch: %v", err) t.Fatalf("Failed to create watch: %v", err)
} }
@ -1255,13 +1255,13 @@ func TestCacherDontAcceptRequestsStopped(t *testing.T) {
cacher.Stop() cacher.Stop()
_, err = delegator.Watch(context.Background(), "pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: storage.Everything}) _, err = delegator.Watch(context.Background(), "/pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: storage.Everything})
if err == nil { if err == nil {
t.Fatalf("Success to create Watch: %v", err) t.Fatalf("Success to create Watch: %v", err)
} }
result := &example.Pod{} result := &example.Pod{}
err = delegator.Get(context.TODO(), "pods/ns/pod-0", storage.GetOptions{ err = delegator.Get(context.TODO(), "/pods/ns/pod-0", storage.GetOptions{
IgnoreNotFound: true, IgnoreNotFound: true,
ResourceVersion: "1", ResourceVersion: "1",
}, result) }, result)
@ -1276,7 +1276,7 @@ func TestCacherDontAcceptRequestsStopped(t *testing.T) {
} }
listResult := &example.PodList{} listResult := &example.PodList{}
err = delegator.GetList(context.TODO(), "pods/ns", storage.ListOptions{ err = delegator.GetList(context.TODO(), "/pods/ns", storage.ListOptions{
ResourceVersion: "1", ResourceVersion: "1",
Recursive: true, Recursive: true,
Predicate: storage.SelectionPredicate{ Predicate: storage.SelectionPredicate{
@ -1374,7 +1374,7 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
for i := 0; i < concurrency; i++ { for i := 0; i < concurrency; i++ {
go func() { go func() {
defer wg.Done() defer wg.Done()
w, err := cacher.Watch(ctx, "pods", storage.ListOptions{ResourceVersion: "1", Predicate: storage.Everything}) w, err := cacher.Watch(ctx, "/pods", storage.ListOptions{ResourceVersion: "1", Predicate: storage.Everything})
if err != nil { if err != nil {
// Watch failed to initialize (this most probably means that cacher // Watch failed to initialize (this most probably means that cacher
// already moved back to Pending state before watch initialized. // already moved back to Pending state before watch initialized.
@ -1443,7 +1443,7 @@ func TestCacherNoLeakWithMultipleWatchers(t *testing.T) {
default: default:
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel() defer cancel()
w, err := cacher.Watch(ctx, "pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: pred}) w, err := cacher.Watch(ctx, "/pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: pred})
if err != nil { if err != nil {
watchErr = fmt.Errorf("Failed to create watch: %v", err) watchErr = fmt.Errorf("Failed to create watch: %v", err)
return return
@ -1508,7 +1508,7 @@ func testCacherSendBookmarkEvents(t *testing.T, allowWatchBookmarks, expectedBoo
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel() defer cancel()
w, err := cacher.Watch(ctx, "pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: pred}) w, err := cacher.Watch(ctx, "/pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: pred})
if err != nil { if err != nil {
t.Fatalf("Failed to create watch: %v", err) t.Fatalf("Failed to create watch: %v", err)
} }
@ -1677,7 +1677,7 @@ func TestInitialEventsEndBookmark(t *testing.T) {
pred.AllowWatchBookmarks = scenario.allowWatchBookmarks pred.AllowWatchBookmarks = scenario.allowWatchBookmarks
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel() defer cancel()
w, err := cacher.Watch(ctx, "pods/ns", storage.ListOptions{ResourceVersion: "100", SendInitialEvents: scenario.sendInitialEvents, Predicate: pred}) w, err := cacher.Watch(ctx, "/pods/ns", storage.ListOptions{ResourceVersion: "100", SendInitialEvents: scenario.sendInitialEvents, Predicate: pred})
if err != nil { if err != nil {
t.Fatalf("Failed to create watch: %v", err) t.Fatalf("Failed to create watch: %v", err)
} }
@ -1724,7 +1724,7 @@ func TestCacherSendsMultipleWatchBookmarks(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
w, err := cacher.Watch(ctx, "pods/ns", storage.ListOptions{ResourceVersion: "100", Predicate: pred}) w, err := cacher.Watch(ctx, "/pods/ns", storage.ListOptions{ResourceVersion: "100", Predicate: pred})
if err != nil { if err != nil {
t.Fatalf("Failed to create watch: %v", err) t.Fatalf("Failed to create watch: %v", err)
} }
@ -1795,7 +1795,7 @@ func TestDispatchingBookmarkEventsWithConcurrentStop(t *testing.T) {
pred.AllowWatchBookmarks = true pred.AllowWatchBookmarks = true
ctx, cancel := context.WithTimeout(context.Background(), time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel() defer cancel()
w, err := cacher.Watch(ctx, "pods/ns", storage.ListOptions{ResourceVersion: "999", Predicate: pred}) w, err := cacher.Watch(ctx, "/pods/ns", storage.ListOptions{ResourceVersion: "999", Predicate: pred})
if err != nil { if err != nil {
t.Fatalf("Failed to create watch: %v", err) t.Fatalf("Failed to create watch: %v", err)
} }
@ -1969,7 +1969,7 @@ func TestStartingResourceVersion(t *testing.T) {
// Advance RV by 10. // Advance RV by 10.
startVersion := uint64(1010) startVersion := uint64(1010)
watcher, err := cacher.Watch(context.TODO(), "pods/ns/foo", storage.ListOptions{ResourceVersion: strconv.FormatUint(startVersion, 10), Predicate: storage.Everything}) watcher, err := cacher.Watch(context.TODO(), "/pods/ns/foo", storage.ListOptions{ResourceVersion: strconv.FormatUint(startVersion, 10), Predicate: storage.Everything})
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
@ -2046,14 +2046,14 @@ func TestDispatchEventWillNotBeBlockedByTimedOutWatcher(t *testing.T) {
totalPods := 50 totalPods := 50
// Create watcher that will be blocked. // Create watcher that will be blocked.
w1, err := cacher.Watch(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: "999", Predicate: storage.Everything}) w1, err := cacher.Watch(context.TODO(), "/pods/ns", storage.ListOptions{ResourceVersion: "999", Predicate: storage.Everything})
if err != nil { if err != nil {
t.Fatalf("Failed to create watch: %v", err) t.Fatalf("Failed to create watch: %v", err)
} }
defer w1.Stop() defer w1.Stop()
// Create fast watcher and ensure it will get all objects. // Create fast watcher and ensure it will get all objects.
w2, err := cacher.Watch(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: "999", Predicate: storage.Everything}) w2, err := cacher.Watch(context.TODO(), "/pods/ns", storage.ListOptions{ResourceVersion: "999", Predicate: storage.Everything})
if err != nil { if err != nil {
t.Fatalf("Failed to create watch: %v", err) t.Fatalf("Failed to create watch: %v", err)
} }
@ -2168,7 +2168,7 @@ func TestCachingDeleteEvents(t *testing.T) {
} }
createWatch := func(pred storage.SelectionPredicate) watch.Interface { createWatch := func(pred storage.SelectionPredicate) watch.Interface {
w, err := cacher.Watch(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: "999", Predicate: pred}) w, err := cacher.Watch(context.TODO(), "/pods/ns", storage.ListOptions{ResourceVersion: "999", Predicate: pred})
if err != nil { if err != nil {
t.Fatalf("Failed to create watch: %v", err) t.Fatalf("Failed to create watch: %v", err)
} }
@ -2249,7 +2249,7 @@ func testCachingObjects(t *testing.T, watchersCount int) {
watchers := make([]watch.Interface, 0, watchersCount) watchers := make([]watch.Interface, 0, watchersCount)
for i := 0; i < watchersCount; i++ { for i := 0; i < watchersCount; i++ {
w, err := cacher.Watch(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: "1000", Predicate: storage.Everything}) w, err := cacher.Watch(context.TODO(), "/pods/ns", storage.ListOptions{ResourceVersion: "1000", Predicate: storage.Everything})
if err != nil { if err != nil {
t.Fatalf("Failed to create watch: %v", err) t.Fatalf("Failed to create watch: %v", err)
} }
@ -2385,7 +2385,7 @@ func TestCacheIntervalInvalidationStopsWatch(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
w, err := cacher.Watch(ctx, "pods/ns", storage.ListOptions{ w, err := cacher.Watch(ctx, "/pods/ns", storage.ListOptions{
ResourceVersion: "999", ResourceVersion: "999",
Predicate: storage.Everything, Predicate: storage.Everything,
}) })
@ -2547,7 +2547,7 @@ func TestWaitUntilWatchCacheFreshAndForceAllEvents(t *testing.T) {
} }
} }
w, err := cacher.Watch(context.Background(), "pods/ns", scenario.opts) w, err := cacher.Watch(context.Background(), "/pods/ns", scenario.opts)
require.NoError(t, err, "failed to create watch: %v") require.NoError(t, err, "failed to create watch: %v")
defer w.Stop() defer w.Stop()
var expectedErr *apierrors.StatusError var expectedErr *apierrors.StatusError
@ -2573,7 +2573,7 @@ func TestWaitUntilWatchCacheFreshAndForceAllEvents(t *testing.T) {
t.Errorf("failed adding a pod to the watchCache %v", err) t.Errorf("failed adding a pod to the watchCache %v", err)
} }
}(t) }(t)
w, err = cacher.Watch(context.Background(), "pods/ns", scenario.opts) w, err = cacher.Watch(context.Background(), "/pods/ns", scenario.opts)
require.NoError(t, err, "failed to create watch: %v") require.NoError(t, err, "failed to create watch: %v")
defer w.Stop() defer w.Stop()
verifyEvents(t, w, []watch.Event{ verifyEvents(t, w, []watch.Event{
@ -2680,7 +2680,7 @@ func BenchmarkCacher_GetList(b *testing.B) {
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
result := &example.PodList{} result := &example.PodList{}
err = delegator.GetList(context.TODO(), "pods", storage.ListOptions{ err = delegator.GetList(context.TODO(), "/pods", storage.ListOptions{
Predicate: pred, Predicate: pred,
Recursive: true, Recursive: true,
ResourceVersion: "12345", ResourceVersion: "12345",
@ -2717,7 +2717,7 @@ func TestWatchListIsSynchronisedWhenNoEventsFromStoreReceived(t *testing.T) {
Predicate: pred, Predicate: pred,
SendInitialEvents: ptr.To(true), SendInitialEvents: ptr.To(true),
} }
w, err := cacher.Watch(context.Background(), "pods/ns", opts) w, err := cacher.Watch(context.Background(), "/pods/ns", opts)
require.NoError(t, err, "failed to create watch: %v") require.NoError(t, err, "failed to create watch: %v")
defer w.Stop() defer w.Stop()

View File

@ -33,7 +33,7 @@ import (
) )
func TestCacherListerWatcher(t *testing.T) { func TestCacherListerWatcher(t *testing.T) {
prefix := "pods" prefix := "/pods"
fn := func() runtime.Object { return &example.PodList{} } fn := func() runtime.Object { return &example.PodList{} }
server, store := newEtcdTestStorage(t, prefix) server, store := newEtcdTestStorage(t, prefix)
defer server.Terminate(t) defer server.Terminate(t)
@ -67,7 +67,7 @@ func TestCacherListerWatcher(t *testing.T) {
} }
func TestCacherListerWatcherPagination(t *testing.T) { func TestCacherListerWatcherPagination(t *testing.T) {
prefix := "pods" prefix := "/pods"
fn := func() runtime.Object { return &example.PodList{} } fn := func() runtime.Object { return &example.PodList{} }
server, store := newEtcdTestStorage(t, prefix) server, store := newEtcdTestStorage(t, prefix)
defer server.Terminate(t) defer server.Terminate(t)
@ -130,7 +130,7 @@ func TestCacherListerWatcherPagination(t *testing.T) {
func TestCacherListerWatcherListWatch(t *testing.T) { func TestCacherListerWatcherListWatch(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.WatchList, true) featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.WatchList, true)
prefix := "pods" prefix := "/pods"
fn := func() runtime.Object { return &example.PodList{} } fn := func() runtime.Object { return &example.PodList{} }
server, store := newEtcdTestStorage(t, prefix) server, store := newEtcdTestStorage(t, prefix)
defer server.Terminate(t) defer server.Terminate(t)
@ -181,7 +181,7 @@ func TestCacherListerWatcherListWatch(t *testing.T) {
func TestCacherListerWatcherWhenListWatchDisabled(t *testing.T) { func TestCacherListerWatcherWhenListWatchDisabled(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.WatchList, false) featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.WatchList, false)
prefix := "pods" prefix := "/pods"
fn := func() runtime.Object { return &example.PodList{} } fn := func() runtime.Object { return &example.PodList{} }
server, store := newEtcdTestStorage(t, prefix) server, store := newEtcdTestStorage(t, prefix)
defer server.Terminate(t) defer server.Terminate(t)

View File

@ -37,7 +37,7 @@ func TestLinearizedReadRevisionInvariant(t *testing.T) {
// [1] https://etcd.io/docs/v3.5/learning/api_guarantees/#isolation-level-and-consistency-of-replicas // [1] https://etcd.io/docs/v3.5/learning/api_guarantees/#isolation-level-and-consistency-of-replicas
ctx, store, etcdClient := testSetup(t) ctx, store, etcdClient := testSetup(t)
dir := "/testing" dir := "/pods"
key := dir + "/testkey" key := dir + "/testkey"
out := &example.Pod{} out := &example.Pod{}
obj := &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", SelfLink: "testlink"}} obj := &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", SelfLink: "testlink"}}

View File

@ -524,15 +524,15 @@ func TestLeaseMaxObjectCount(t *testing.T) {
expectAttachedCount int64 expectAttachedCount int64
}{ }{
{ {
key: "testkey1", key: "/pods/testkey1",
expectAttachedCount: 1, expectAttachedCount: 1,
}, },
{ {
key: "testkey2", key: "/pods/testkey2",
expectAttachedCount: 2, expectAttachedCount: 2,
}, },
{ {
key: "testkey3", key: "/pods/testkey3",
// We assume each time has 1 object attached to the lease // We assume each time has 1 object attached to the lease
// so after granting a new lease, the recorded count is set to 1 // so after granting a new lease, the recorded count is set to 1
expectAttachedCount: 1, expectAttachedCount: 1,
@ -925,14 +925,14 @@ func TestGetCurrentResourceVersion(t *testing.T) {
} }
} }
createPod := func(obj *example.Pod) *example.Pod { createPod := func(obj *example.Pod) *example.Pod {
key := "pods/" + obj.Namespace + "/" + obj.Name key := "/pods/" + obj.Namespace + "/" + obj.Name
out := &example.Pod{} out := &example.Pod{}
err := store.Create(context.TODO(), key, obj, out, 0) err := store.Create(context.TODO(), key, obj, out, 0)
require.NoError(t, err) require.NoError(t, err)
return out return out
} }
getPod := func(name, ns string) *example.Pod { getPod := func(name, ns string) *example.Pod {
key := "pods/" + ns + "/" + name key := "/pods/" + ns + "/" + name
out := &example.Pod{} out := &example.Pod{}
err := store.Get(context.TODO(), key, storage.GetOptions{}, out) err := store.Get(context.TODO(), key, storage.GetOptions{}, out)
require.NoError(t, err) require.NoError(t, err)
@ -1014,7 +1014,7 @@ func BenchmarkStatsCacheCleanKeys(b *testing.B) {
} }
func TestPrefixGetKeys(t *testing.T) { func TestPrefixGetKeys(t *testing.T) {
ctx, store, c := testSetup(t, withPrefix("/registry"), withResourcePrefix("pods")) ctx, store, c := testSetup(t, withPrefix("/registry"), withResourcePrefix("/pods"))
_, err := c.KV.Put(ctx, "key", "a") _, err := c.KV.Put(ctx, "key", "a")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -1065,7 +1065,7 @@ func TestPrefixStats(t *testing.T) {
} }
for _, tc := range tcs { for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
ctx, store, c := testSetup(t, withPrefix("/registry"), withResourcePrefix("pods")) ctx, store, c := testSetup(t, withPrefix("/registry"), withResourcePrefix("/pods"))
if tc.estimate { if tc.estimate {
err := store.EnableResourceSizeEstimation(store.getKeys) err := store.EnableResourceSizeEstimation(store.getKeys)
if err != nil { if err != nil {
@ -1094,7 +1094,7 @@ func TestPrefixStats(t *testing.T) {
listOut := &example.PodList{} listOut := &example.PodList{}
// Ignore error as decode is expected to fail // Ignore error as decode is expected to fail
_ = store.GetList(ctx, "pods", storage.ListOptions{Predicate: storage.Everything, Recursive: true}, listOut) _ = store.GetList(ctx, "/pods", storage.ListOptions{Predicate: storage.Everything, Recursive: true}, listOut)
gotStats, err := store.Stats(ctx) gotStats, err := store.Stats(ctx)
if err != nil { if err != nil {

View File

@ -85,7 +85,7 @@ func TestTLSConnection(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = storage.Create(context.TODO(), "/abc", &example.Pod{}, nil, 0) err = storage.Create(context.TODO(), "/pods/abc", &example.Pod{}, nil, 0)
if err != nil { if err != nil {
t.Fatalf("Create failed: %v", err) t.Fatalf("Create failed: %v", err)
} }

View File

@ -193,12 +193,12 @@ func RunTestGet(ctx context.Context, t *testing.T, store storage.Interface) {
rv: strconv.FormatInt(math.MaxInt64, 10), rv: strconv.FormatInt(math.MaxInt64, 10),
}, { }, {
name: "get non-existing", name: "get non-existing",
key: "/non-existing", key: "/pods/non-existing",
ignoreNotFound: false, ignoreNotFound: false,
expectNotFoundErr: true, expectNotFoundErr: true,
}, { }, {
name: "get non-existing, ignore not found", name: "get non-existing, ignore not found",
key: "/non-existing", key: "/pods/non-existing",
ignoreNotFound: true, ignoreNotFound: true,
expectNotFoundErr: false, expectNotFoundErr: false,
expectedOut: &example.Pod{}, expectedOut: &example.Pod{},
@ -258,7 +258,7 @@ func RunTestUnconditionalDelete(ctx context.Context, t *testing.T, store storage
expectNotFoundErr: false, expectNotFoundErr: false,
}, { }, {
name: "non-existing key", name: "non-existing key",
key: "/non-existing", key: "/pods/non-existing",
expectedObj: nil, expectedObj: nil,
expectNotFoundErr: true, expectNotFoundErr: true,
}} }}
@ -640,11 +640,11 @@ func RunTestList(ctx context.Context, t *testing.T, store storage.Interface, com
Predicate: storage.Everything, Predicate: storage.Everything,
Recursive: true, Recursive: true,
} }
if err := store.GetList(ctx, "/second", storageOpts, list); err != nil { if err := store.GetList(ctx, "/pods/second", storageOpts, list); err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
continueRV, _ := strconv.Atoi(list.ResourceVersion) continueRV, _ := strconv.Atoi(list.ResourceVersion)
secondContinuation, err := storage.EncodeContinue("/second/foo", "/second/", int64(continueRV)) secondContinuation, err := storage.EncodeContinue("/pods/second/foo", "/pods/second/", int64(continueRV))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -2037,12 +2037,12 @@ func RunTestGetListNonRecursive(ctx context.Context, t *testing.T, increaseRV In
expectRVTooLarge: true, expectRVTooLarge: true,
}, { }, {
name: "non-existing key", name: "non-existing key",
key: "/non-existing", key: "/pods/non-existing",
pred: storage.Everything, pred: storage.Everything,
expectedOut: []example.Pod{}, expectedOut: []example.Pod{},
}, { }, {
name: "with matching pod name", name: "with matching pod name",
key: "/non-existing", key: "/pods/non-existing",
pred: storage.SelectionPredicate{ pred: storage.SelectionPredicate{
Label: labels.Everything(), Label: labels.Everything(),
Field: fields.ParseSelectorOrDie("metadata.name!=" + storedObj.Name), Field: fields.ParseSelectorOrDie("metadata.name!=" + storedObj.Name),
@ -2784,7 +2784,7 @@ func RunTestGuaranteedUpdate(ctx context.Context, t *testing.T, store InterfaceW
hasSelfLink bool hasSelfLink bool
}{{ }{{
name: "non-existing key, ignoreNotFound=false", name: "non-existing key, ignoreNotFound=false",
key: "/non-existing", key: "/pods/non-existing",
ignoreNotFound: false, ignoreNotFound: false,
precondition: nil, precondition: nil,
expectNotFoundErr: true, expectNotFoundErr: true,
@ -2792,7 +2792,7 @@ func RunTestGuaranteedUpdate(ctx context.Context, t *testing.T, store InterfaceW
expectNoUpdate: false, expectNoUpdate: false,
}, { }, {
name: "non-existing key, ignoreNotFound=true", name: "non-existing key, ignoreNotFound=true",
key: "/non-existing", key: "/pods/non-existing",
ignoreNotFound: true, ignoreNotFound: true,
precondition: nil, precondition: nil,
expectNotFoundErr: false, expectNotFoundErr: false,

View File

@ -762,7 +762,7 @@ func RunTestClusterScopedWatch(ctx context.Context, t *testing.T, store storage.
currentObjs := map[string]*example.Pod{} currentObjs := map[string]*example.Pod{}
for _, watchTest := range tt.watchTests { for _, watchTest := range tt.watchTests {
out := &example.Pod{} out := &example.Pod{}
key := "pods/" + watchTest.obj.Name key := "/pods/" + watchTest.obj.Name
err := store.GuaranteedUpdate(ctx, key, out, true, nil, storage.SimpleUpdate( err := store.GuaranteedUpdate(ctx, key, out, true, nil, storage.SimpleUpdate(
func(runtime.Object) (runtime.Object, error) { func(runtime.Object) (runtime.Object, error) {
obj := watchTest.obj.DeepCopy() obj := watchTest.obj.DeepCopy()
@ -1076,7 +1076,7 @@ func RunTestNamespaceScopedWatch(ctx context.Context, t *testing.T, store storag
currentObjs := map[string]*example.Pod{} currentObjs := map[string]*example.Pod{}
for _, watchTest := range tt.watchTests { for _, watchTest := range tt.watchTests {
out := &example.Pod{} out := &example.Pod{}
key := "pods/" + watchTest.obj.Namespace + "/" + watchTest.obj.Name key := "/pods/" + watchTest.obj.Namespace + "/" + watchTest.obj.Name
err := store.GuaranteedUpdate(ctx, key, out, true, nil, storage.SimpleUpdate( err := store.GuaranteedUpdate(ctx, key, out, true, nil, storage.SimpleUpdate(
func(runtime.Object) (runtime.Object, error) { func(runtime.Object) (runtime.Object, error) {
obj := watchTest.obj.DeepCopy() obj := watchTest.obj.DeepCopy()