Skip to content

Commit 831a919

Browse files
Frapschenliu-cong
andauthored
Adding a flag to control whether auth is added to the EPP metrics server (#1639)
* Adding a flag to control whether auth is added to the EPP metrics server * Update cmd/epp/runner/runner.go Co-authored-by: Cong Liu <conliu@google.com> * update * apply review's suggestion * apply reviewer's suggestion * rollback interval * update * update README.md * revert gke * update --------- Co-authored-by: Cong Liu <conliu@google.com>
1 parent 0707d2f commit 831a919

File tree

7 files changed

+78
-55
lines changed

7 files changed

+78
-55
lines changed

cmd/epp/runner/runner.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
healthPb "google.golang.org/grpc/health/grpc_health_v1"
3737
"k8s.io/apimachinery/pkg/runtime/schema"
3838
"k8s.io/apimachinery/pkg/types"
39+
"k8s.io/client-go/rest"
3940
ctrl "sigs.k8s.io/controller-runtime"
4041
"sigs.k8s.io/controller-runtime/pkg/log"
4142
"sigs.k8s.io/controller-runtime/pkg/log/zap"
@@ -91,17 +92,18 @@ var flowControlConfig = flowcontrol.Config{
9192
}
9293

9394
var (
94-
grpcPort = flag.Int("grpc-port", runserver.DefaultGrpcPort, "The gRPC port used for communicating with Envoy proxy")
95-
grpcHealthPort = flag.Int("grpc-health-port", runserver.DefaultGrpcHealthPort, "The port used for gRPC liveness and readiness probes")
96-
metricsPort = flag.Int("metrics-port", runserver.DefaultMetricsPort, "The metrics port")
97-
enablePprof = flag.Bool("enable-pprof", runserver.DefaultEnablePprof, "Enables pprof handlers. Defaults to true. Set to false to disable pprof handlers.")
98-
poolName = flag.String("pool-name", runserver.DefaultPoolName, "Name of the InferencePool this Endpoint Picker is associated with.")
99-
poolGroup = flag.String("pool-group", runserver.DefaultPoolGroup, "group of the InferencePool this Endpoint Picker is associated with.")
100-
poolNamespace = flag.String("pool-namespace", "", "Namespace of the InferencePool this Endpoint Picker is associated with.")
101-
logVerbosity = flag.Int("v", logging.DEFAULT, "number for the log level verbosity")
102-
secureServing = flag.Bool("secure-serving", runserver.DefaultSecureServing, "Enables secure serving. Defaults to true.")
103-
healthChecking = flag.Bool("health-checking", runserver.DefaultHealthChecking, "Enables health checking")
104-
certPath = flag.String("cert-path", runserver.DefaultCertPath, "The path to the certificate for secure serving. The certificate and private key files "+
95+
grpcPort = flag.Int("grpc-port", runserver.DefaultGrpcPort, "The gRPC port used for communicating with Envoy proxy")
96+
grpcHealthPort = flag.Int("grpc-health-port", runserver.DefaultGrpcHealthPort, "The port used for gRPC liveness and readiness probes")
97+
metricsPort = flag.Int("metrics-port", runserver.DefaultMetricsPort, "The metrics port")
98+
metricsEndpointAuth = flag.Bool("metrics-endpoint-auth", true, "Enables authentication and authorization of the metrics endpoint")
99+
enablePprof = flag.Bool("enable-pprof", runserver.DefaultEnablePprof, "Enables pprof handlers. Defaults to true. Set to false to disable pprof handlers.")
100+
poolName = flag.String("pool-name", runserver.DefaultPoolName, "Name of the InferencePool this Endpoint Picker is associated with.")
101+
poolGroup = flag.String("pool-group", runserver.DefaultPoolGroup, "group of the InferencePool this Endpoint Picker is associated with.")
102+
poolNamespace = flag.String("pool-namespace", "", "Namespace of the InferencePool this Endpoint Picker is associated with.")
103+
logVerbosity = flag.Int("v", logging.DEFAULT, "number for the log level verbosity")
104+
secureServing = flag.Bool("secure-serving", runserver.DefaultSecureServing, "Enables secure serving. Defaults to true.")
105+
healthChecking = flag.Bool("health-checking", runserver.DefaultHealthChecking, "Enables health checking")
106+
certPath = flag.String("cert-path", runserver.DefaultCertPath, "The path to the certificate for secure serving. The certificate and private key files "+
105107
"are assumed to be named tls.crt and tls.key, respectively. If not set, and secureServing is enabled, "+
106108
"then a self-signed certificate is used.")
107109
// metric flags
@@ -211,8 +213,14 @@ func (r *Runner) Run(ctx context.Context) error {
211213
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/metrics/server
212214
// - https://book.kubebuilder.io/reference/metrics.html
213215
metricsServerOptions := metricsserver.Options{
214-
BindAddress: fmt.Sprintf(":%d", *metricsPort),
215-
FilterProvider: filters.WithAuthenticationAndAuthorization,
216+
BindAddress: fmt.Sprintf(":%d", *metricsPort),
217+
FilterProvider: func() func(c *rest.Config, httpClient *http.Client) (metricsserver.Filter, error) {
218+
if *metricsEndpointAuth {
219+
return filters.WithAuthenticationAndAuthorization
220+
}
221+
222+
return nil
223+
}(),
216224
}
217225

218226
// Determine pool namespace: if --pool-namespace is non-empty, use it; else NAMESPACE env var; else default

0 commit comments

Comments
 (0)