@@ -27,6 +27,7 @@ import (
2727 "github.com/streamnative/function-mesh/pkg/monitoring"
2828 "sigs.k8s.io/controller-runtime/pkg/cache"
2929 "sigs.k8s.io/controller-runtime/pkg/healthz"
30+ "sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3031 "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3132
3233 "github.com/go-logr/logr"
@@ -77,7 +78,8 @@ func main() {
7778 var globalBackendConfig string
7879 var globalBackendConfigNamespace string
7980 var namespacedBackendConfig string
80- flag .StringVar (& metricsAddr , "metrics-addr" , lookupEnvOrString ("METRICS_ADDR" , ":8080" ),
81+ var secureMetrics bool
82+ flag .StringVar (& metricsAddr , "metrics-addr" , lookupEnvOrString ("METRICS_ADDR" , ":8443" ),
8183 "The address the metric endpoint binds to." )
8284 flag .StringVar (& leaderElectionID , "leader-election-id" ,
8385 lookupEnvOrString ("LEADER_ELECTION_ID" , "a3f45fce.functionmesh.io" ),
@@ -108,6 +110,8 @@ func main() {
108110 "The namespace of the global backend config name used for all functions&sinks&sources" )
109111 flag .StringVar (& namespacedBackendConfig , "namespaced-backend-config" , lookupEnvOrString ("NAMESPACED_BACKEND_CONFIG" , "backend-config" ),
110112 "The backend config name used for functions&sinks&sources in the same namespace" )
113+ flag .BoolVar (& secureMetrics , "metrics-secure" , true , "If set, the metrics endpoint is served securely via HTTPS." +
114+ " Use --metrics-secure=false to use HTTP instead." )
111115 flag .Parse ()
112116
113117 ctrl .SetLogger (zap .New (zap .UseDevMode (true )))
@@ -133,11 +137,18 @@ func main() {
133137 }
134138 }
135139
140+ metricOpts := server.Options {
141+ BindAddress : metricsAddr ,
142+ SecureServing : secureMetrics ,
143+ }
144+
145+ if secureMetrics {
146+ metricOpts .FilterProvider = filters .WithAuthenticationAndAuthorization
147+ }
148+
136149 options := ctrl.Options {
137- Scheme : scheme ,
138- Metrics : server.Options {
139- BindAddress : metricsAddr ,
140- },
150+ Scheme : scheme ,
151+ Metrics : metricOpts ,
141152 HealthProbeBindAddress : healthProbeAddr ,
142153 LeaderElection : enableLeaderElection ,
143154 LeaderElectionNamespace : leaderElectionNamespace ,
0 commit comments