Skip to content

Commit 862e312

Browse files
committed
Detect conversion webhook panics
1 parent b98aa13 commit 862e312

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

internal/test/envtest/environment.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,14 @@ func verifyPanicMetrics() error {
611611
}
612612
}
613613
}
614+
615+
if metricFamily.GetName() == "controller_runtime_conversion_webhook_panics_total" {
616+
for _, webhookPanicMetric := range metricFamily.Metric {
617+
if webhookPanicMetric.Counter != nil && webhookPanicMetric.Counter.Value != nil && *webhookPanicMetric.Counter.Value > 0 {
618+
errs = append(errs, fmt.Errorf("%.0f panics occurred in conversion webhooks (check logs for more details)", *webhookPanicMetric.Counter.Value))
619+
}
620+
}
621+
}
614622
}
615623

616624
if len(errs) > 0 {

test/framework/deployment_helpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,14 @@ func verifyMetrics(data []byte) error {
447447
}
448448
}
449449
}
450+
451+
if metric == "controller_runtime_conversion_webhook_panics_total" {
452+
for _, webhookPanicMetric := range metricFamily.Metric {
453+
if webhookPanicMetric.Counter != nil && webhookPanicMetric.Counter.Value != nil && *webhookPanicMetric.Counter.Value > 0 {
454+
errs = append(errs, fmt.Errorf("%.0f panics occurred in conversion webhooks (check logs for more details)", *webhookPanicMetric.Counter.Value))
455+
}
456+
}
457+
}
450458
}
451459

452460
if len(errs) > 0 {

test/framework/deployment_helpers_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ controller_runtime_webhook_panics_total 0
7171
wantErr: "1 panics occurred in \"cluster\" controller (check logs for more details)",
7272
},
7373
{
74-
name: "panic occurred in webhook",
74+
name: "panic occurred in webhooks",
7575
data: []byte(`
7676
# HELP controller_runtime_max_concurrent_reconciles Maximum number of concurrent reconciles per controller
7777
# TYPE controller_runtime_max_concurrent_reconciles gauge
@@ -84,9 +84,32 @@ controller_runtime_reconcile_panics_total{controller="clusterclass"} 0
8484
# HELP controller_runtime_webhook_panics_total Total number of webhook panics
8585
# TYPE controller_runtime_webhook_panics_total counter
8686
controller_runtime_webhook_panics_total 1
87+
# HELP controller_runtime_conversion_webhook_panics_total Total number of conversion webhook panics
88+
# TYPE controller_runtime_conversion_webhook_panics_total counter
89+
controller_runtime_conversion_webhook_panics_total 0
8790
`),
8891
wantErr: "1 panics occurred in webhooks (check logs for more details)",
8992
},
93+
{
94+
name: "panics occurred in conversion webhooks",
95+
data: []byte(`
96+
# HELP controller_runtime_max_concurrent_reconciles Maximum number of concurrent reconciles per controller
97+
# TYPE controller_runtime_max_concurrent_reconciles gauge
98+
controller_runtime_max_concurrent_reconciles{controller="cluster"} 10
99+
controller_runtime_max_concurrent_reconciles{controller="clusterclass"} 10
100+
# HELP controller_runtime_reconcile_panics_total Total number of reconciliation panics per controller
101+
# TYPE controller_runtime_reconcile_panics_total counter
102+
controller_runtime_reconcile_panics_total{controller="cluster"} 0
103+
controller_runtime_reconcile_panics_total{controller="clusterclass"} 0
104+
# HELP controller_runtime_webhook_panics_total Total number of webhook panics
105+
# TYPE controller_runtime_webhook_panics_total counter
106+
controller_runtime_webhook_panics_total 0
107+
# HELP controller_runtime_conversion_webhook_panics_total Total number of conversion webhook panics
108+
# TYPE controller_runtime_conversion_webhook_panics_total counter
109+
controller_runtime_conversion_webhook_panics_total 2
110+
`),
111+
wantErr: "2 panics occurred in conversion webhooks (check logs for more details)",
112+
},
90113
}
91114
for _, tt := range tests {
92115
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)