From e96b1c0b4291fc50a111a07a0465e62b7223f91a Mon Sep 17 00:00:00 2001 From: Georges Chaudy Date: Mon, 1 Jul 2024 10:32:37 +0200 Subject: [PATCH] Add unified-next-grpc (#89891) --- pkg/services/apiserver/options/storage.go | 17 +++++++++-------- pkg/services/apiserver/service.go | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/pkg/services/apiserver/options/storage.go b/pkg/services/apiserver/options/storage.go index fddd09c09bf..5c2f86ba138 100644 --- a/pkg/services/apiserver/options/storage.go +++ b/pkg/services/apiserver/options/storage.go @@ -14,12 +14,13 @@ import ( type StorageType string const ( - StorageTypeFile StorageType = "file" - StorageTypeEtcd StorageType = "etcd" - StorageTypeLegacy StorageType = "legacy" - StorageTypeUnified StorageType = "unified" - StorageTypeUnifiedGrpc StorageType = "unified-grpc" - StorageTypeUnifiedNext StorageType = "unified-next" + StorageTypeFile StorageType = "file" + StorageTypeEtcd StorageType = "etcd" + StorageTypeLegacy StorageType = "legacy" + StorageTypeUnified StorageType = "unified" + StorageTypeUnifiedGrpc StorageType = "unified-grpc" + StorageTypeUnifiedNext StorageType = "unified-next" + StorageTypeUnifiedNextGrpc StorageType = "unified-next-grpc" ) type StorageOptions struct { @@ -45,10 +46,10 @@ func (o *StorageOptions) AddFlags(fs *pflag.FlagSet) { func (o *StorageOptions) Validate() []error { errs := []error{} switch o.StorageType { - case StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc, StorageTypeUnifiedNext: + case StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc, StorageTypeUnifiedNext, StorageTypeUnifiedNextGrpc: // no-op default: - errs = append(errs, fmt.Errorf("--grafana-apiserver-storage-type must be one of %s, %s, %s, %s, %s, %s", StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc, StorageTypeUnifiedNext)) + errs = append(errs, fmt.Errorf("--grafana-apiserver-storage-type must be one of %s, %s, %s, %s, %s, %s", StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc, StorageTypeUnifiedNext, StorageTypeUnifiedNextGrpc)) } if _, _, err := net.SplitHostPort(o.Address); err != nil { diff --git a/pkg/services/apiserver/service.go b/pkg/services/apiserver/service.go index f8f594e07ce..2b5885a4b52 100644 --- a/pkg/services/apiserver/service.go +++ b/pkg/services/apiserver/service.go @@ -275,6 +275,23 @@ func (s *service) start(ctx context.Context) error { store := resource.NewLocalResourceStoreClient(resourceServer) serverConfig.Config.RESTOptionsGetter = apistore.NewRESTOptionsGetter(store, o.RecommendedOptions.Etcd.StorageConfig.Codec) + case grafanaapiserveroptions.StorageTypeUnifiedNextGrpc: + if !s.features.IsEnabledGlobally(featuremgmt.FlagUnifiedStorage) { + return fmt.Errorf("unified storage requires the unifiedStorage feature flag") + } + // Create a connection to the gRPC server + conn, err := grpc.NewClient(o.StorageOptions.Address, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + return err + } + + // TODO: determine when to close the connection, we cannot defer it here + // defer conn.Close() + + // Create a client instance + store := resource.NewResourceStoreClientGRPC(conn) + + serverConfig.Config.RESTOptionsGetter = apistore.NewRESTOptionsGetter(store, o.RecommendedOptions.Etcd.StorageConfig.Codec) case grafanaapiserveroptions.StorageTypeUnified: if !s.features.IsEnabledGlobally(featuremgmt.FlagUnifiedStorage) {