k8s: add support for configuring the gRPC server address (#84006)

* k8s: add support for configuring the gRPC server address
This commit is contained in:
Georges Chaudy 2024-03-11 10:23:03 +01:00 committed by GitHub
parent 4d7220dbdf
commit 15e358e3b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package options
import ( import (
"fmt" "fmt"
"net"
"github.com/spf13/pflag" "github.com/spf13/pflag"
genericapiserver "k8s.io/apiserver/pkg/server" genericapiserver "k8s.io/apiserver/pkg/server"
@ -21,17 +22,20 @@ const (
type StorageOptions struct { type StorageOptions struct {
StorageType StorageType StorageType StorageType
DataPath string DataPath string
Address string
} }
func NewStorageOptions() *StorageOptions { func NewStorageOptions() *StorageOptions {
return &StorageOptions{ return &StorageOptions{
StorageType: StorageTypeLegacy, StorageType: StorageTypeLegacy,
Address: "localhost:10000",
} }
} }
func (o *StorageOptions) AddFlags(fs *pflag.FlagSet) { func (o *StorageOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar((*string)(&o.StorageType), "grafana-apiserver-storage-type", string(o.StorageType), "Storage type") 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.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 { func (o *StorageOptions) Validate() []error {
@ -42,6 +46,10 @@ func (o *StorageOptions) Validate() []error {
default: default:
errs = append(errs, fmt.Errorf("--grafana-apiserver-storage-type must be one of %s, %s, %s, %s, %s", StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc)) 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 return errs
} }

View File

@ -261,8 +261,7 @@ func (s *service) start(ctx context.Context) error {
case grafanaapiserveroptions.StorageTypeUnifiedGrpc: case grafanaapiserveroptions.StorageTypeUnifiedGrpc:
// Create a connection to the gRPC server // Create a connection to the gRPC server
// TODO: support configuring the gRPC server address conn, err := grpc.Dial(o.StorageOptions.Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.Dial("localhost:10000", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil { if err != nil {
return err return err
} }