Revert "Unistore : Ensure Watch works in HA mode." (#94097)
Revert "Unistore : Ensure Watch works in HA mode. (#93428)"
This reverts commit 0a26c9e9ae.
This commit is contained in:
@@ -7,9 +7,9 @@ package apistore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -29,20 +29,7 @@ import (
|
||||
"k8s.io/apiserver/pkg/storage/storagebackend/factory"
|
||||
|
||||
storagetesting "github.com/grafana/grafana/pkg/apiserver/storage/testing"
|
||||
infraDB "github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/resource"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/sql"
|
||||
"github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
)
|
||||
|
||||
type StorageType string
|
||||
|
||||
const (
|
||||
StorageTypeFile StorageType = "file"
|
||||
StorageTypeUnified StorageType = "unified"
|
||||
)
|
||||
|
||||
var scheme = runtime.NewScheme()
|
||||
@@ -61,7 +48,6 @@ type setupOptions struct {
|
||||
prefix string
|
||||
resourcePrefix string
|
||||
groupResource schema.GroupResource
|
||||
storageType StorageType
|
||||
}
|
||||
|
||||
type setupOption func(*setupOptions, testing.TB)
|
||||
@@ -73,20 +59,10 @@ func withDefaults(options *setupOptions, t testing.TB) {
|
||||
options.prefix = t.TempDir()
|
||||
options.resourcePrefix = storagetesting.KeyFunc("", "")
|
||||
options.groupResource = schema.GroupResource{Resource: "pods"}
|
||||
options.storageType = StorageTypeFile
|
||||
}
|
||||
func withStorageType(storageType StorageType) setupOption {
|
||||
return func(options *setupOptions, t testing.TB) {
|
||||
options.storageType = storageType
|
||||
}
|
||||
}
|
||||
|
||||
var _ setupOption = withDefaults
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
testsuite.Run(m)
|
||||
}
|
||||
|
||||
func testSetup(t testing.TB, opts ...setupOption) (context.Context, storage.Interface, factory.DestroyFunc, error) {
|
||||
setupOpts := setupOptions{}
|
||||
opts = append([]setupOption{withDefaults}, opts...)
|
||||
@@ -109,56 +85,18 @@ func testSetup(t testing.TB, opts ...setupOption) (context.Context, storage.Inte
|
||||
Metadata: fileblob.MetadataDontWrite, // skip
|
||||
})
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("ROOT: %s\n\n", tmp)
|
||||
}
|
||||
ctx := storagetesting.NewContext()
|
||||
backend, err := resource.NewCDKBackend(ctx, resource.CDKBackendOptions{
|
||||
Bucket: bucket,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
var server resource.ResourceServer
|
||||
switch setupOpts.storageType {
|
||||
case StorageTypeFile:
|
||||
backend, err := resource.NewCDKBackend(ctx, resource.CDKBackendOptions{
|
||||
Bucket: bucket,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
server, err = resource.NewResourceServer(resource.ResourceServerOptions{
|
||||
Backend: backend,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Issue a health check to ensure the server is initialized
|
||||
_, err = server.IsHealthy(ctx, &resource.HealthCheckRequest{})
|
||||
require.NoError(t, err)
|
||||
case StorageTypeUnified:
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
dbstore := infraDB.InitTestDB(t)
|
||||
cfg := setting.NewCfg()
|
||||
features := featuremgmt.WithFeatures()
|
||||
|
||||
eDB, err := dbimpl.ProvideResourceDB(dbstore, cfg, features, nil)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, eDB)
|
||||
|
||||
ret, err := sql.NewBackend(sql.BackendOptions{
|
||||
DBProvider: eDB,
|
||||
PollingInterval: time.Millisecond, // Keep this fast
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, ret)
|
||||
ctx := storagetesting.NewContext()
|
||||
err = ret.Init(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
server, err = resource.NewResourceServer(resource.ResourceServerOptions{
|
||||
Backend: ret,
|
||||
Diagnostics: ret,
|
||||
Lifecycle: ret,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
default:
|
||||
t.Fatalf("unsupported storage type: %s", setupOpts.storageType)
|
||||
}
|
||||
server, err := resource.NewResourceServer(resource.ResourceServerOptions{
|
||||
Backend: backend,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
client := resource.NewLocalResourceClient(server)
|
||||
|
||||
config := storagebackend.NewDefaultConfig(setupOpts.prefix, setupOpts.codec)
|
||||
@@ -186,82 +124,55 @@ func testSetup(t testing.TB, opts ...setupOption) (context.Context, storage.Inte
|
||||
}
|
||||
|
||||
func TestWatch(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t, withStorageType(s))
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatch(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatch(ctx, t, store)
|
||||
}
|
||||
|
||||
func TestClusterScopedWatch(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestClusterScopedWatch(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestClusterScopedWatch(ctx, t, store)
|
||||
}
|
||||
|
||||
func TestNamespaceScopedWatch(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestNamespaceScopedWatch(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestNamespaceScopedWatch(ctx, t, store)
|
||||
}
|
||||
|
||||
func TestDeleteTriggerWatch(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestDeleteTriggerWatch(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestDeleteTriggerWatch(ctx, t, store)
|
||||
}
|
||||
|
||||
// Not Supported by unistore because there is no way to differentiate between:
|
||||
// - SendInitialEvents=nil && resourceVersion=0
|
||||
// - sendInitialEvents=false && resourceVersion=0
|
||||
// This is a Legacy feature in k8s.io/apiserver/pkg/storage/etcd3/watcher_test.go#196
|
||||
// func TestWatchFromZero(t *testing.T) {
|
||||
// ctx, store, destroyFunc, err := testSetup(t)
|
||||
// defer destroyFunc()
|
||||
// assert.NoError(t, err)
|
||||
// storagetesting.RunTestWatchFromZero(ctx, t, store, nil)
|
||||
// }
|
||||
func TestWatchFromZero(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatchFromZero(ctx, t, store, nil)
|
||||
}
|
||||
|
||||
// TestWatchFromNonZero tests that
|
||||
// - watch from non-0 should just watch changes after given version
|
||||
func TestWatchFromNonZero(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatchFromNonZero(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatchFromNonZero(ctx, t, store)
|
||||
}
|
||||
|
||||
/*
|
||||
Only valid when using a cached storage
|
||||
func TestDelayedWatchDelivery(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestDelayedWatchDelivery(ctx, t, store)
|
||||
}
|
||||
/*
|
||||
|
||||
/*
|
||||
func TestWatchError(t *testing.T) {
|
||||
@@ -271,36 +182,24 @@ func TestWatchError(t *testing.T) {
|
||||
*/
|
||||
|
||||
func TestWatchContextCancel(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatchContextCancel(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatchContextCancel(ctx, t, store)
|
||||
}
|
||||
|
||||
func TestWatcherTimeout(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatcherTimeout(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatcherTimeout(ctx, t, store)
|
||||
}
|
||||
|
||||
func TestWatchDeleteEventObjectHaveLatestRV(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatchDeleteEventObjectHaveLatestRV(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatchDeleteEventObjectHaveLatestRV(ctx, t, store)
|
||||
}
|
||||
|
||||
// TODO: enable when we support flow control and priority fairness
|
||||
@@ -322,47 +221,31 @@ func TestWatchDeleteEventObjectHaveLatestRV(t *testing.T) {
|
||||
// setting allowWatchBookmarks query param against
|
||||
// etcd implementation doesn't have any effect.
|
||||
func TestWatchDispatchBookmarkEvents(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatchDispatchBookmarkEvents(ctx, t, store, false)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunTestWatchDispatchBookmarkEvents(ctx, t, store, false)
|
||||
}
|
||||
|
||||
func TestSendInitialEventsBackwardCompatibility(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunSendInitialEventsBackwardCompatibility(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunSendInitialEventsBackwardCompatibility(ctx, t, store)
|
||||
}
|
||||
|
||||
func TestEtcdWatchSemantics(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunWatchSemantics(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunWatchSemantics(ctx, t, store)
|
||||
}
|
||||
|
||||
func TestEtcdWatchSemanticInitialEventsExtended(t *testing.T) {
|
||||
for _, s := range []StorageType{StorageTypeFile, StorageTypeUnified} {
|
||||
t.Run(string(s), func(t *testing.T) {
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunWatchSemanticInitialEventsExtended(ctx, t, store)
|
||||
})
|
||||
}
|
||||
ctx, store, destroyFunc, err := testSetup(t)
|
||||
defer destroyFunc()
|
||||
assert.NoError(t, err)
|
||||
storagetesting.RunWatchSemanticInitialEventsExtended(ctx, t, store)
|
||||
}
|
||||
|
||||
func newPod() runtime.Object {
|
||||
|
||||
Reference in New Issue
Block a user