From 15e358e3b9e59861dcd34f73ef2082a53f931c2b Mon Sep 17 00:00:00 2001 From: Georges Chaudy Date: Mon, 11 Mar 2024 10:23:03 +0100 Subject: [PATCH] k8s: add support for configuring the gRPC server address (#84006) * k8s: add support for configuring the gRPC server address --- pkg/services/apiserver/options/storage.go | 8 ++++++++ pkg/services/apiserver/service.go | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/services/apiserver/options/storage.go b/pkg/services/apiserver/options/storage.go index 55c2933583e..dc99d98e9b4 100644 --- a/pkg/services/apiserver/options/storage.go +++ b/pkg/services/apiserver/options/storage.go @@ -2,6 +2,7 @@ package options import ( "fmt" + "net" "github.com/spf13/pflag" genericapiserver "k8s.io/apiserver/pkg/server" @@ -21,17 +22,20 @@ const ( type StorageOptions struct { StorageType StorageType DataPath string + Address string } func NewStorageOptions() *StorageOptions { return &StorageOptions{ StorageType: StorageTypeLegacy, + Address: "localhost:10000", } } func (o *StorageOptions) AddFlags(fs *pflag.FlagSet) { fs.StringVar((*string)(&o.StorageType), "grafana-apiserver-storage-type", string(o.StorageType), "Storage type") fs.StringVar(&o.DataPath, "grafana-apiserver-storage-path", o.DataPath, "Storage path for file storage") + fs.StringVar(&o.Address, "grafana-apiserver-storage-address", o.Address, "Remote grpc address endpoint") } func (o *StorageOptions) Validate() []error { @@ -42,6 +46,10 @@ func (o *StorageOptions) Validate() []error { default: errs = append(errs, fmt.Errorf("--grafana-apiserver-storage-type must be one of %s, %s, %s, %s, %s", StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc)) } + + if _, _, err := net.SplitHostPort(o.Address); err != nil { + errs = append(errs, fmt.Errorf("--grafana-apiserver-storage-address must be a valid network address: %v", err)) + } return errs } diff --git a/pkg/services/apiserver/service.go b/pkg/services/apiserver/service.go index 7a4bb27ef3a..e6d32610dbe 100644 --- a/pkg/services/apiserver/service.go +++ b/pkg/services/apiserver/service.go @@ -261,8 +261,7 @@ func (s *service) start(ctx context.Context) error { case grafanaapiserveroptions.StorageTypeUnifiedGrpc: // Create a connection to the gRPC server - // TODO: support configuring the gRPC server address - conn, err := grpc.Dial("localhost:10000", grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.Dial(o.StorageOptions.Address, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return err }