Skip to content

Commit 28ed497

Browse files
committed
Detect conversion webhook panics
1 parent 7b7a901 commit 28ed497

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

internal/test/envtest/environment.go

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

618626
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: 5 additions & 2 deletions
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: "panics 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,8 +84,11 @@ 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 2
8790
`),
88-
wantErr: "1 panics occurred in webhooks (check logs for more details)",
91+
wantErr: "[1 panics occurred in webhooks (check logs for more details), 2 panics occurred in conversion webhooks (check logs for more details)]",
8992
},
9093
}
9194
for _, tt := range tests {

0 commit comments

Comments
 (0)