Fix tests to to only accesses keys from under resourcePrefix
Kubernetes-commit: 1ac067ae0e68b14a7a6eff464aacdaf7d70e838d
This commit is contained in:
parent
6d430c71ae
commit
677aaf0c38
|
@ -65,12 +65,12 @@ func TestDryRunCreateDoesntCreate(t *testing.T) {
|
|||
obj := UnstructuredOrDie(`{"kind": "Pod"}`)
|
||||
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 {
|
||||
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 {
|
||||
t.Errorf("Expected key to be not found, error: %v", err)
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ func TestDryRunCreateReturnsObject(t *testing.T) {
|
|||
obj := UnstructuredOrDie(`{"kind": "Pod"}`)
|
||||
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 {
|
||||
t.Fatalf("Failed to create new dry-run object: %v", err)
|
||||
}
|
||||
|
@ -100,12 +100,12 @@ func TestDryRunCreateExistingObjectFails(t *testing.T) {
|
|||
obj := UnstructuredOrDie(`{"kind": "Pod"}`)
|
||||
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 {
|
||||
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 {
|
||||
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")
|
||||
}
|
||||
|
||||
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 {
|
||||
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"}}`)
|
||||
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 {
|
||||
t.Fatalf("Failed to create new object: %v", err)
|
||||
}
|
||||
|
@ -149,12 +149,12 @@ func TestDryRunUpdatePreconditions(t *testing.T) {
|
|||
}
|
||||
wrongID := types.UID("wrong-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 {
|
||||
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 {
|
||||
t.Fatalf("Failed to update with valid precondition: %v", err)
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ func TestDryRunUpdateDoesntUpdate(t *testing.T) {
|
|||
obj := UnstructuredOrDie(`{"kind": "Pod"}`)
|
||||
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 {
|
||||
t.Fatalf("Failed to create new object: %v", err)
|
||||
}
|
||||
|
@ -181,12 +181,12 @@ func TestDryRunUpdateDoesntUpdate(t *testing.T) {
|
|||
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 {
|
||||
t.Fatalf("Failed to dry-run update: %v", err)
|
||||
}
|
||||
out := UnstructuredOrDie(`{}`)
|
||||
err = s.Get(context.Background(), "key", storage.GetOptions{}, out)
|
||||
err = s.Get(context.Background(), "/pods/key", storage.GetOptions{}, out)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get storage: %v", err)
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ func TestDryRunUpdateReturnsObject(t *testing.T) {
|
|||
obj := UnstructuredOrDie(`{"kind": "Pod"}`)
|
||||
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 {
|
||||
t.Fatalf("Failed to create new object: %v", err)
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ func TestDryRunUpdateReturnsObject(t *testing.T) {
|
|||
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 {
|
||||
t.Fatalf("Failed to dry-run update: %v", err)
|
||||
}
|
||||
|
@ -233,17 +233,17 @@ func TestDryRunDeleteDoesntDelete(t *testing.T) {
|
|||
obj := UnstructuredOrDie(`{"kind": "Pod"}`)
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
t.Fatalf("Failed to retrieve dry-run deleted object: %v", err)
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ func TestDryRunDeleteMissingObjectFails(t *testing.T) {
|
|||
defer destroy()
|
||||
|
||||
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 {
|
||||
t.Errorf("Expected key to be not found, error: %v", err)
|
||||
}
|
||||
|
@ -267,14 +267,14 @@ func TestDryRunDeleteReturnsObject(t *testing.T) {
|
|||
obj := UnstructuredOrDie(`{"kind": "Pod"}`)
|
||||
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 {
|
||||
t.Fatalf("Failed to create new object: %v", err)
|
||||
}
|
||||
|
||||
out = UnstructuredOrDie(`{}`)
|
||||
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 {
|
||||
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"}}`)
|
||||
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 {
|
||||
t.Fatalf("Failed to create new object: %v", err)
|
||||
}
|
||||
|
||||
wrongID := types.UID("wrong-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 {
|
||||
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 {
|
||||
t.Fatalf("Failed to delete with valid precondition: %v", err)
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ import (
|
|||
)
|
||||
|
||||
func newTestCacherWithoutSyncing(s storage.Interface, c clock.WithTicker) (*Cacher, storage.Versioner, error) {
|
||||
prefix := "pods"
|
||||
prefix := "/pods"
|
||||
config := Config{
|
||||
Storage: s,
|
||||
Versioner: storage.APIObjectVersioner{},
|
||||
|
@ -626,7 +626,7 @@ apiserver_watch_cache_consistent_read_total{fallback="true", group="", resource=
|
|||
}
|
||||
|
||||
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()
|
||||
duration := cacher.clock.Since(start)
|
||||
if (err != nil) != tc.expectError {
|
||||
|
@ -718,7 +718,7 @@ func TestMatchExactResourceVersionFallback(t *testing.T) {
|
|||
delegator := NewCacheDelegator(cacher, backingStorage)
|
||||
|
||||
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 {
|
||||
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.
|
||||
backingStorage.injectGetListError(errDummy)
|
||||
err = delegator.GetList(context.TODO(), "pods/ns", storage.ListOptions{
|
||||
err = delegator.GetList(context.TODO(), "/pods/ns", storage.ListOptions{
|
||||
ResourceVersion: "0",
|
||||
Predicate: pred,
|
||||
}, 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)
|
||||
}
|
||||
|
||||
err = delegator.GetList(context.TODO(), "pods/ns", storage.ListOptions{
|
||||
err = delegator.GetList(context.TODO(), "/pods/ns", storage.ListOptions{
|
||||
ResourceVersion: "",
|
||||
Predicate: pred,
|
||||
}, result)
|
||||
|
@ -842,7 +842,7 @@ func TestGetListNonRecursiveCacheWithConsistentListFromCache(t *testing.T) {
|
|||
defer delegator.Stop()
|
||||
|
||||
// Setup test object
|
||||
key := "pods/ns"
|
||||
key := "/pods/ns"
|
||||
input := &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "ns"}}
|
||||
if err := v.UpdateObject(input, 100); err != nil {
|
||||
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.
|
||||
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,
|
||||
ResourceVersion: "0",
|
||||
}, result)
|
||||
|
@ -925,7 +925,7 @@ func TestGetCacheBypass(t *testing.T) {
|
|||
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,
|
||||
ResourceVersion: "",
|
||||
}, result)
|
||||
|
@ -1120,7 +1120,7 @@ func TestWatchNotHangingOnStartupFailure(t *testing.T) {
|
|||
// Watch hangs waiting on watchcache being initialized.
|
||||
// Ensure that it terminates when its context is cancelled
|
||||
// (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 err == nil || err.Error() != apierrors.NewServiceUnavailable(context.Canceled.Error()).Error() {
|
||||
t.Errorf("Unexpected error: %#v", err)
|
||||
|
@ -1165,7 +1165,7 @@ func TestWatcherNotGoingBackInTime(t *testing.T) {
|
|||
totalPods := 100
|
||||
|
||||
// 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",
|
||||
Predicate: storage.Everything,
|
||||
})
|
||||
|
@ -1190,7 +1190,7 @@ func TestWatcherNotGoingBackInTime(t *testing.T) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
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 {
|
||||
t.Fatalf("Failed to create watch: %v", err)
|
||||
}
|
||||
|
@ -1255,13 +1255,13 @@ func TestCacherDontAcceptRequestsStopped(t *testing.T) {
|
|||
|
||||
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 {
|
||||
t.Fatalf("Success to create Watch: %v", err)
|
||||
}
|
||||
|
||||
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,
|
||||
ResourceVersion: "1",
|
||||
}, result)
|
||||
|
@ -1276,7 +1276,7 @@ func TestCacherDontAcceptRequestsStopped(t *testing.T) {
|
|||
}
|
||||
|
||||
listResult := &example.PodList{}
|
||||
err = delegator.GetList(context.TODO(), "pods/ns", storage.ListOptions{
|
||||
err = delegator.GetList(context.TODO(), "/pods/ns", storage.ListOptions{
|
||||
ResourceVersion: "1",
|
||||
Recursive: true,
|
||||
Predicate: storage.SelectionPredicate{
|
||||
|
@ -1374,7 +1374,7 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
|
|||
for i := 0; i < concurrency; i++ {
|
||||
go func() {
|
||||
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 {
|
||||
// Watch failed to initialize (this most probably means that cacher
|
||||
// already moved back to Pending state before watch initialized.
|
||||
|
@ -1443,7 +1443,7 @@ func TestCacherNoLeakWithMultipleWatchers(t *testing.T) {
|
|||
default:
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
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 {
|
||||
watchErr = fmt.Errorf("Failed to create watch: %v", err)
|
||||
return
|
||||
|
@ -1508,7 +1508,7 @@ func testCacherSendBookmarkEvents(t *testing.T, allowWatchBookmarks, expectedBoo
|
|||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
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 {
|
||||
t.Fatalf("Failed to create watch: %v", err)
|
||||
}
|
||||
|
@ -1677,7 +1677,7 @@ func TestInitialEventsEndBookmark(t *testing.T) {
|
|||
pred.AllowWatchBookmarks = scenario.allowWatchBookmarks
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
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 {
|
||||
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)
|
||||
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 {
|
||||
t.Fatalf("Failed to create watch: %v", err)
|
||||
}
|
||||
|
@ -1795,7 +1795,7 @@ func TestDispatchingBookmarkEventsWithConcurrentStop(t *testing.T) {
|
|||
pred.AllowWatchBookmarks = true
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
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 {
|
||||
t.Fatalf("Failed to create watch: %v", err)
|
||||
}
|
||||
|
@ -1969,7 +1969,7 @@ func TestStartingResourceVersion(t *testing.T) {
|
|||
// Advance RV by 10.
|
||||
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 {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
|
@ -2046,14 +2046,14 @@ func TestDispatchEventWillNotBeBlockedByTimedOutWatcher(t *testing.T) {
|
|||
totalPods := 50
|
||||
|
||||
// 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 {
|
||||
t.Fatalf("Failed to create watch: %v", err)
|
||||
}
|
||||
defer w1.Stop()
|
||||
|
||||
// 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 {
|
||||
t.Fatalf("Failed to create watch: %v", err)
|
||||
}
|
||||
|
@ -2168,7 +2168,7 @@ func TestCachingDeleteEvents(t *testing.T) {
|
|||
}
|
||||
|
||||
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 {
|
||||
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)
|
||||
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 {
|
||||
t.Fatalf("Failed to create watch: %v", err)
|
||||
}
|
||||
|
@ -2385,7 +2385,7 @@ func TestCacheIntervalInvalidationStopsWatch(t *testing.T) {
|
|||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
w, err := cacher.Watch(ctx, "pods/ns", storage.ListOptions{
|
||||
w, err := cacher.Watch(ctx, "/pods/ns", storage.ListOptions{
|
||||
ResourceVersion: "999",
|
||||
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")
|
||||
defer w.Stop()
|
||||
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)
|
||||
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")
|
||||
defer w.Stop()
|
||||
verifyEvents(t, w, []watch.Event{
|
||||
|
@ -2680,7 +2680,7 @@ func BenchmarkCacher_GetList(b *testing.B) {
|
|||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := &example.PodList{}
|
||||
err = delegator.GetList(context.TODO(), "pods", storage.ListOptions{
|
||||
err = delegator.GetList(context.TODO(), "/pods", storage.ListOptions{
|
||||
Predicate: pred,
|
||||
Recursive: true,
|
||||
ResourceVersion: "12345",
|
||||
|
@ -2717,7 +2717,7 @@ func TestWatchListIsSynchronisedWhenNoEventsFromStoreReceived(t *testing.T) {
|
|||
Predicate: pred,
|
||||
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")
|
||||
defer w.Stop()
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import (
|
|||
)
|
||||
|
||||
func TestCacherListerWatcher(t *testing.T) {
|
||||
prefix := "pods"
|
||||
prefix := "/pods"
|
||||
fn := func() runtime.Object { return &example.PodList{} }
|
||||
server, store := newEtcdTestStorage(t, prefix)
|
||||
defer server.Terminate(t)
|
||||
|
@ -67,7 +67,7 @@ func TestCacherListerWatcher(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCacherListerWatcherPagination(t *testing.T) {
|
||||
prefix := "pods"
|
||||
prefix := "/pods"
|
||||
fn := func() runtime.Object { return &example.PodList{} }
|
||||
server, store := newEtcdTestStorage(t, prefix)
|
||||
defer server.Terminate(t)
|
||||
|
@ -130,7 +130,7 @@ func TestCacherListerWatcherPagination(t *testing.T) {
|
|||
func TestCacherListerWatcherListWatch(t *testing.T) {
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.WatchList, true)
|
||||
|
||||
prefix := "pods"
|
||||
prefix := "/pods"
|
||||
fn := func() runtime.Object { return &example.PodList{} }
|
||||
server, store := newEtcdTestStorage(t, prefix)
|
||||
defer server.Terminate(t)
|
||||
|
@ -181,7 +181,7 @@ func TestCacherListerWatcherListWatch(t *testing.T) {
|
|||
func TestCacherListerWatcherWhenListWatchDisabled(t *testing.T) {
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.WatchList, false)
|
||||
|
||||
prefix := "pods"
|
||||
prefix := "/pods"
|
||||
fn := func() runtime.Object { return &example.PodList{} }
|
||||
server, store := newEtcdTestStorage(t, prefix)
|
||||
defer server.Terminate(t)
|
||||
|
|
|
@ -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
|
||||
ctx, store, etcdClient := testSetup(t)
|
||||
|
||||
dir := "/testing"
|
||||
dir := "/pods"
|
||||
key := dir + "/testkey"
|
||||
out := &example.Pod{}
|
||||
obj := &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo", SelfLink: "testlink"}}
|
||||
|
|
|
@ -524,15 +524,15 @@ func TestLeaseMaxObjectCount(t *testing.T) {
|
|||
expectAttachedCount int64
|
||||
}{
|
||||
{
|
||||
key: "testkey1",
|
||||
key: "/pods/testkey1",
|
||||
expectAttachedCount: 1,
|
||||
},
|
||||
{
|
||||
key: "testkey2",
|
||||
key: "/pods/testkey2",
|
||||
expectAttachedCount: 2,
|
||||
},
|
||||
{
|
||||
key: "testkey3",
|
||||
key: "/pods/testkey3",
|
||||
// We assume each time has 1 object attached to the lease
|
||||
// so after granting a new lease, the recorded count is set to 1
|
||||
expectAttachedCount: 1,
|
||||
|
@ -925,14 +925,14 @@ func TestGetCurrentResourceVersion(t *testing.T) {
|
|||
}
|
||||
}
|
||||
createPod := func(obj *example.Pod) *example.Pod {
|
||||
key := "pods/" + obj.Namespace + "/" + obj.Name
|
||||
key := "/pods/" + obj.Namespace + "/" + obj.Name
|
||||
out := &example.Pod{}
|
||||
err := store.Create(context.TODO(), key, obj, out, 0)
|
||||
require.NoError(t, err)
|
||||
return out
|
||||
}
|
||||
getPod := func(name, ns string) *example.Pod {
|
||||
key := "pods/" + ns + "/" + name
|
||||
key := "/pods/" + ns + "/" + name
|
||||
out := &example.Pod{}
|
||||
err := store.Get(context.TODO(), key, storage.GetOptions{}, out)
|
||||
require.NoError(t, err)
|
||||
|
@ -1014,7 +1014,7 @@ func BenchmarkStatsCacheCleanKeys(b *testing.B) {
|
|||
}
|
||||
|
||||
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")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -1065,7 +1065,7 @@ func TestPrefixStats(t *testing.T) {
|
|||
}
|
||||
for _, tc := range tcs {
|
||||
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 {
|
||||
err := store.EnableResourceSizeEstimation(store.getKeys)
|
||||
if err != nil {
|
||||
|
@ -1094,7 +1094,7 @@ func TestPrefixStats(t *testing.T) {
|
|||
|
||||
listOut := &example.PodList{}
|
||||
// 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)
|
||||
if err != nil {
|
||||
|
|
|
@ -85,7 +85,7 @@ func TestTLSConnection(t *testing.T) {
|
|||
if err != nil {
|
||||
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 {
|
||||
t.Fatalf("Create failed: %v", err)
|
||||
}
|
||||
|
|
|
@ -193,12 +193,12 @@ func RunTestGet(ctx context.Context, t *testing.T, store storage.Interface) {
|
|||
rv: strconv.FormatInt(math.MaxInt64, 10),
|
||||
}, {
|
||||
name: "get non-existing",
|
||||
key: "/non-existing",
|
||||
key: "/pods/non-existing",
|
||||
ignoreNotFound: false,
|
||||
expectNotFoundErr: true,
|
||||
}, {
|
||||
name: "get non-existing, ignore not found",
|
||||
key: "/non-existing",
|
||||
key: "/pods/non-existing",
|
||||
ignoreNotFound: true,
|
||||
expectNotFoundErr: false,
|
||||
expectedOut: &example.Pod{},
|
||||
|
@ -258,7 +258,7 @@ func RunTestUnconditionalDelete(ctx context.Context, t *testing.T, store storage
|
|||
expectNotFoundErr: false,
|
||||
}, {
|
||||
name: "non-existing key",
|
||||
key: "/non-existing",
|
||||
key: "/pods/non-existing",
|
||||
expectedObj: nil,
|
||||
expectNotFoundErr: true,
|
||||
}}
|
||||
|
@ -640,11 +640,11 @@ func RunTestList(ctx context.Context, t *testing.T, store storage.Interface, com
|
|||
Predicate: storage.Everything,
|
||||
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)
|
||||
}
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -2037,12 +2037,12 @@ func RunTestGetListNonRecursive(ctx context.Context, t *testing.T, increaseRV In
|
|||
expectRVTooLarge: true,
|
||||
}, {
|
||||
name: "non-existing key",
|
||||
key: "/non-existing",
|
||||
key: "/pods/non-existing",
|
||||
pred: storage.Everything,
|
||||
expectedOut: []example.Pod{},
|
||||
}, {
|
||||
name: "with matching pod name",
|
||||
key: "/non-existing",
|
||||
key: "/pods/non-existing",
|
||||
pred: storage.SelectionPredicate{
|
||||
Label: labels.Everything(),
|
||||
Field: fields.ParseSelectorOrDie("metadata.name!=" + storedObj.Name),
|
||||
|
@ -2784,7 +2784,7 @@ func RunTestGuaranteedUpdate(ctx context.Context, t *testing.T, store InterfaceW
|
|||
hasSelfLink bool
|
||||
}{{
|
||||
name: "non-existing key, ignoreNotFound=false",
|
||||
key: "/non-existing",
|
||||
key: "/pods/non-existing",
|
||||
ignoreNotFound: false,
|
||||
precondition: nil,
|
||||
expectNotFoundErr: true,
|
||||
|
@ -2792,7 +2792,7 @@ func RunTestGuaranteedUpdate(ctx context.Context, t *testing.T, store InterfaceW
|
|||
expectNoUpdate: false,
|
||||
}, {
|
||||
name: "non-existing key, ignoreNotFound=true",
|
||||
key: "/non-existing",
|
||||
key: "/pods/non-existing",
|
||||
ignoreNotFound: true,
|
||||
precondition: nil,
|
||||
expectNotFoundErr: false,
|
||||
|
|
|
@ -762,7 +762,7 @@ func RunTestClusterScopedWatch(ctx context.Context, t *testing.T, store storage.
|
|||
currentObjs := map[string]*example.Pod{}
|
||||
for _, watchTest := range tt.watchTests {
|
||||
out := &example.Pod{}
|
||||
key := "pods/" + watchTest.obj.Name
|
||||
key := "/pods/" + watchTest.obj.Name
|
||||
err := store.GuaranteedUpdate(ctx, key, out, true, nil, storage.SimpleUpdate(
|
||||
func(runtime.Object) (runtime.Object, error) {
|
||||
obj := watchTest.obj.DeepCopy()
|
||||
|
@ -1076,7 +1076,7 @@ func RunTestNamespaceScopedWatch(ctx context.Context, t *testing.T, store storag
|
|||
currentObjs := map[string]*example.Pod{}
|
||||
for _, watchTest := range tt.watchTests {
|
||||
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(
|
||||
func(runtime.Object) (runtime.Object, error) {
|
||||
obj := watchTest.obj.DeepCopy()
|
||||
|
|
Loading…
Reference in New Issue