8000 Fix panic · nginx/kubernetes-ingress@6b2e372 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b2e372

Browse files
committed
Fix panic
1 parent 4b8eb16 commit 6b2e372

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

internal/k8s/controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,10 @@ func (lbc *LoadBalancerController) updateVirtualServerMetrics() {
16421642
}
16431643

16441644
func (lbc *LoadBalancerController) updateTransportServerMetrics() {
1645+
if !lbc.areCustomResourcesEnabled {
1646+
return
1647+
}
1648+
16451649
metrics := lbc.configuration.GetTransportServerMetrics()
16461650
lbc.metricsCollector.SetTransportServers(metrics.TotalTLSPassthrough, metrics.TotalTCP, metrics.TotalUDP)
16471651
}

internal/metrics/collectors/controller.go

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,51 +34,56 @@ func NewControllerMetricsCollector(crdsEnabled bool, constLabels map[string]stri
3434
labelNamesController,
3535
)
3636

37-
if !crdsEnabled {
38-
return &ControllerMetricsCollector{ingressesTotal: ingResTotal}
37+
var vsResTotal, vsrResTotal prometheus.Gauge
38+
var tsResTotal *prometheus.GaugeVec
39+
40+
if crdsEnabled {
41+
vsResTotal = prometheus.NewGauge(
42+
prometheus.GaugeOpts{
43+
Name: "virtualserver_resources_total",
44+
Namespace: metricsNamespace,
45+
Help: "Number of handled VirtualServer resources",
46+
ConstLabels: constLabels,
47+
},
48+
)
49+
50+
vsrResTotal = prometheus.NewGauge(
51+
prometheus.GaugeOpts{
52+
Name: "virtualserverroute_resources_total",
53+
Namespace: metricsNamespace,
54+
Help: "Number of handled VirtualServerRoute resources",
55+
ConstLabels: constLabels,
56+
},
57+
)
58+
59+
tsResTotal = prometheus.NewGaugeVec(
60+
prometheus.GaugeOpts{
61+
Name: "transportserver_resources_total",
62+
Namespace: metricsNamespace,
63+
Help: "Number of handled TransportServer resources",
64+
ConstLabels: constLabels,
65+
},
66+
labelNamesController,
67+
)
3968
}
4069

41-
vsResTotal := prometheus.NewGauge(
42-
prometheus.GaugeOpts{
43-
Name: "virtualserver_resources_total",
44-
Namespace: metricsNamespace,
45-
Help: "Number of handled VirtualServer resources",
46-
ConstLabels: constLabels,
47-
},
48-
)
49-
50-
vsrResTotal := prometheus.NewGauge(
51-
prometheus.GaugeOpts{
52-
Name: "virtualserverroute_resources_total",
53-
Namespace: metricsNamespace,
54-
Help: "Number of handled VirtualServerRoute resources",
55-
ConstLabels: constLabels,
56-
},
57-
)
58-
59-
tsResTotal := prometheus.NewGaugeVec(
60-
prometheus.GaugeOpts{
61-
Name: "transportserver_resources_total",
62-
Namespace: metricsNamespace,
63-
Help: "Number of handled TransportServer resources",
64-
ConstLabels: constLabels,
65-
},
66-
labelNamesController,
67-
)
68-
6970
c := &ControllerMetricsCollector{
70-
crdsEnabled: true,
71+
crdsEnabled: crdsEnabled,
7172
ingressesTotal: ingResTotal,
7273
virtualServersTotal: vsResTotal,
7374
virtualServerRoutesTotal: vsrResTotal,
7475
transportServersTotal: tsResTotal,
7576
}
7677

77-
// if we don't set to 0 metrics with types, the metrics will not be created initially
78+
// if we don't set to 0 metrics with the label type, the metrics will not be created initially
79+
7880
c.SetIngresses("regular", 0)
7981
c.SetIngresses("master", 0)
8082
c.SetIngresses("minion", 0)
81-
c.SetTransportServers(0, 0, 0)
83+
84+
if crdsEnabled {
85+
c.SetTransportServers(0, 0, 0)
86+
}
8287

8388
return c
8489
}

0 commit comments

Comments
 (0)
0