From ba308fa2a3335199682811a7f0f8daed352a4878 Mon Sep 17 00:00:00 2001 From: Ali Aqel Date: Wed, 31 Jan 2024 17:47:41 +0000 Subject: [PATCH] Add flag to override GRPC Authority Header --- CHANGELOG.md | 1 + cmd/adapter/main.go | 18 ++++++++++-------- pkg/metricsservice/client.go | 7 ++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b4a04231b..85ee889d599 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ Here is an overview of all new **experimental** features: ### Improvements +- **General**: Add command-line flag in Adapter to allow override of GRPC Authority Header ([#5449](https://github.com/kedacore/keda/issues/5449)) - **General**: Add OPENTELEMETRY flag in e2e test YAML ([#5375](https://github.com/kedacore/keda/issues/5375)) ### Fixes diff --git a/cmd/adapter/main.go b/cmd/adapter/main.go index c63a973c7f2..73844494fb5 100644 --- a/cmd/adapter/main.go +++ b/cmd/adapter/main.go @@ -56,12 +56,13 @@ type Adapter struct { var logger = klogr.New().WithName("keda_metrics_adapter") var ( - adapterClientRequestQPS float32 - adapterClientRequestBurst int - metricsAPIServerPort int - disableCompression bool - metricsServiceAddr string - profilingAddr string + adapterClientRequestQPS float32 + adapterClientRequestBurst int + metricsAPIServerPort int + disableCompression bool + metricsServiceAddr string + profilingAddr string + metricssServiceGRPCAuthority string ) func (a *Adapter) makeProvider(ctx context.Context) (provider.ExternalMetricsProvider, <-chan struct{}, error) { @@ -123,7 +124,7 @@ func (a *Adapter) makeProvider(ctx context.Context) (provider.ExternalMetricsPro } logger.Info("Connecting Metrics Service gRPC client to the server", "address", metricsServiceAddr) - grpcClient, err := metricsservice.NewGrpcClient(metricsServiceAddr, a.SecureServing.ServerCert.CertDirectory) + grpcClient, err := metricsservice.NewGrpcClient(metricsServiceAddr, a.SecureServing.ServerCert.CertDirectory, metricssServiceGRPCAuthority) if err != nil { logger.Error(err, "error connecting Metrics Service gRPC client to the server", "address", metricsServiceAddr) return nil, nil, err @@ -232,7 +233,8 @@ func main() { cmd.Flags().StringVar(&cmd.Message, "msg", "starting adapter...", "startup message") cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure we get the klog flags cmd.Flags().IntVar(&metricsAPIServerPort, "port", 8080, "Set the port for the metrics API server") - cmd.Flags().StringVar(&metricsServiceAddr, "metrics-service-address", generateDefaultMetricsServiceAddr(), "The address of the gRPRC Metrics Service Server.") + cmd.Flags().StringVar(&metricsServiceAddr, "metrics-service-address", generateDefaultMetricsServiceAddr(), "The address of the GRPC Metrics Service Server.") + cmd.Flags().StringVar(&metricssServiceGRPCAuthority, "metrics-service-grpc-authority", "", "Host Authority override for the Metrics Service if the Host Authority is not the same as the address used for the GRPC Metrics Service Server.") cmd.Flags().StringVar(&profilingAddr, "profiling-bind-address", "", "The address the profiling would be exposed on.") cmd.Flags().Float32Var(&adapterClientRequestQPS, "kube-api-qps", 20.0, "Set the QPS rate for throttling requests sent to the apiserver") cmd.Flags().IntVar(&adapterClientRequestBurst, "kube-api-burst", 30, "Set the burst for throttling requests sent to the apiserver") diff --git a/pkg/metricsservice/client.go b/pkg/metricsservice/client.go index 28b7b49f204..401398b4439 100644 --- a/pkg/metricsservice/client.go +++ b/pkg/metricsservice/client.go @@ -36,7 +36,7 @@ type GrpcClient struct { connection *grpc.ClientConn } -func NewGrpcClient(url, certDir string) (*GrpcClient, error) { +func NewGrpcClient(url, certDir, authority string) (*GrpcClient, error) { defaultConfig := `{ "methodConfig": [{ "timeout": "3s", @@ -57,6 +57,11 @@ func NewGrpcClient(url, certDir string) (*GrpcClient, error) { grpc.WithTransportCredentials(creds), grpc.WithDefaultServiceConfig(defaultConfig), } + + if authority != "" { + opts = append(opts, grpc.WithAuthority(authority)) + } + conn, err := grpc.Dial(url, opts...) if err != nil { return nil, err