ResourceClient: Exercise resource client in k8s apis tests (#93473)

This commit is contained in:
Ryan McKinley
2024-09-19 17:16:48 +03:00
committed by GitHub
parent 63195664f4
commit 542105b680
9 changed files with 68 additions and 28 deletions
+2 -2
View File
@@ -25,11 +25,11 @@ import (
var _ generic.RESTOptionsGetter = (*RESTOptionsGetter)(nil)
type RESTOptionsGetter struct {
client resource.ResourceStoreClient
client resource.ResourceClient
original storagebackend.Config
}
func NewRESTOptionsGetterForClient(client resource.ResourceStoreClient, original storagebackend.Config) *RESTOptionsGetter {
func NewRESTOptionsGetterForClient(client resource.ResourceClient, original storagebackend.Config) *RESTOptionsGetter {
return &RESTOptionsGetter{
client: client,
original: original,
+2 -2
View File
@@ -48,7 +48,7 @@ type Storage struct {
trigger storage.IndexerFuncs
indexers *cache.Indexers
store resource.ResourceStoreClient
store resource.ResourceClient
getKey func(string) (*resource.ResourceKey, error)
watchSet *WatchSet
@@ -64,7 +64,7 @@ var ErrNamespaceNotExists = errors.New("namespace does not exist")
// NewStorage instantiates a new Storage.
func NewStorage(
config *storagebackend.ConfigForResource,
store resource.ResourceStoreClient,
store resource.ResourceClient,
keyFunc func(obj runtime.Object) (string, error),
keyParser func(key string) (*resource.ResourceKey, error),
newFunc func() runtime.Object,
+5
View File
@@ -2,6 +2,7 @@ package unified
import (
"context"
"fmt"
"path/filepath"
infraDB "github.com/grafana/grafana/pkg/infra/db"
@@ -59,6 +60,10 @@ func ProvideUnifiedStorageClient(
return resource.NewLocalResourceClient(server), nil
case options.StorageTypeUnifiedGrpc:
if opts.Address == "" {
return nil, fmt.Errorf("expecting address for storage_type: %s", opts.StorageType)
}
// Create a connection to the gRPC server
conn, err := grpc.NewClient(opts.Address,
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
+14 -9
View File
@@ -35,15 +35,20 @@ func NewLocalResourceClient(server ResourceServer) ResourceClient {
channel := &inprocgrpc.Channel{}
auth := &grpcUtils.Authenticator{}
channel.RegisterService(
grpchan.InterceptServer(
&ResourceStore_ServiceDesc,
grpcAuth.UnaryServerInterceptor(auth.Authenticate),
grpcAuth.StreamServerInterceptor(auth.Authenticate),
),
server, // Implements all the things
)
for _, desc := range []*grpc.ServiceDesc{
&ResourceStore_ServiceDesc,
&ResourceIndex_ServiceDesc,
&Diagnostics_ServiceDesc,
} {
channel.RegisterService(
grpchan.InterceptServer(
desc,
grpcAuth.UnaryServerInterceptor(auth.Authenticate),
grpcAuth.StreamServerInterceptor(auth.Authenticate),
),
server,
)
}
cc := grpchan.InterceptClientConn(channel, grpcUtils.UnaryClientInterceptor, grpcUtils.StreamClientInterceptor)
return &resourceClient{
+5 -2
View File
@@ -98,8 +98,11 @@ func (s *service) start(ctx context.Context) error {
return err
}
resource.RegisterResourceStoreServer(s.handler.GetServer(), server)
grpc_health_v1.RegisterHealthServer(s.handler.GetServer(), healthService)
srv := s.handler.GetServer()
resource.RegisterResourceStoreServer(srv, server)
resource.RegisterResourceIndexServer(srv, server)
resource.RegisterDiagnosticsServer(srv, server)
grpc_health_v1.RegisterHealthServer(srv, healthService)
// register reflection service
_, err = grpcserver.ProvideReflectionService(s.cfg, s.handler)