Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 8688302

Browse files
committed
Default only serve metrics on main port
(cherry picked from commit c5ffe39) Signed-off-by: Brian Goff <cpuguy83@gmail.com>
1 parent 250d7aa commit 8688302

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

internal/commands/root/http.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ func setupHTTPServer(ctx context.Context, p provider.Provider, cfg *apiServerCon
9595
}
9696
api.AttachPodRoutes(podRoutes, mux, true)
9797

98+
var summaryHandlerFunc api.PodStatsSummaryHandlerFunc
99+
if mp, ok := p.(provider.PodMetricsProvider); ok {
100+
summaryHandlerFunc = mp.GetStatsSummary
101+
}
102+
podMetricsRoutes := api.PodMetricsConfig{
103+
GetStatsSummary: summaryHandlerFunc,
104+
}
105+
api.AttachPodMetricsRoutes(podMetricsRoutes, mux)
106+
98107
s := &http.Server{
99108
Handler: mux,
100109
TLSConfig: tlsCfg,
@@ -103,23 +112,20 @@ func setupHTTPServer(ctx context.Context, p provider.Provider, cfg *apiServerCon
103112
closers = append(closers, s)
104113
}
105114

106-
if cfg.MetricsAddr == "" {
107-
log.G(ctx).Info("Pod metrics server not setup due to empty metrics address")
108-
} else {
115+
if cfg.MetricsAddr != "" {
109116
l, err := net.Listen("tcp", cfg.MetricsAddr)
110117
if err != nil {
111118
return nil, errors.Wrap(err, "could not setup listener for pod metrics http server")
112119
}
113-
114-
mux := http.NewServeMux()
115-
116120
var summaryHandlerFunc api.PodStatsSummaryHandlerFunc
117121
if mp, ok := p.(provider.PodMetricsProvider); ok {
118122
summaryHandlerFunc = mp.GetStatsSummary
119123
}
120124
podMetricsRoutes := api.PodMetricsConfig{
121125
GetStatsSummary: summaryHandlerFunc,
122126
}
127+
128+
mux := http.NewServeMux()
123129
api.AttachPodMetricsRoutes(podMetricsRoutes, mux)
124130
s := &http.Server{
125131
Handler: mux,

opts/opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
DefaultNodeName = "virtual-kubelet"
3131
DefaultOperatingSystem = "Linux"
3232
DefaultInformerResyncPeriod = 1 * time.Minute
33-
DefaultMetricsAddr = ":10255"
33+
DefaultMetricsAddr = ""
3434
DefaultListenPort = 10250 // TODO(cpuguy83)(VK1.0): Change this to an addr instead of just a port.. we should not be listening on all interfaces.
3535
DefaultPodSyncWorkers = 10
3636
DefaultKubeNamespace = corev1.NamespaceAll

0 commit comments

Comments
 (0)