AlertmanagerConfig conversion fails for email receivers without threading and drops Pushover ttl

Author: Sanchit2662Created Sep 23, 2026Updated Sep 25, 2026
Labelskind/bug

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Description

I was looking at test coverage for the AlertmanagerConfig conversion code in pkg/apis/monitoring/v1beta1/ and found two bugs.

1. Email receivers without threading fail to convert

convertEmailThreadingConfigTo and convertEmailThreadingConfigFrom dereference Threading without a nil check. threading is optional, so most email receivers don't set it and hit this panic. controller-runtime recovers from the panic, but the ConversionReview still fails with internal error occurred during conversion, and the API server rejects the request.

2. Pushover ttl is silently dropped

PushoverConfig has a TTL field in both versions but neither Pushover converter copies it. v1alpha1 is the storage version, so a ttl set through v1beta1 is never stored and never reaches the generated Alertmanager config. A ttl set through v1alpha1 is also lost if someone reads the object as v1beta1 and writes it back.

Missing tests for the conversion code

Neither bug is a one-off. conversion_to.go and conversion_from.go (about 1,400 lines) convert 15 receiver types plus routes, inhibit rules, matchers and HTTP config, and they have no tests of their own. The only coverage comes from TestAlertmanagerConfigConversion in pkg/admission/admission_test.go, which uses a single WeChat receiver. When I ran the tests with -coverpkg, 46 of the 60 conversion functions had 0% coverage.

Every new receiver field has to be copied by hand into both files. Recent PRs like #8506, #8507 and #8628 did that correctly, but nothing checks it, which is how ttl stayed missing since v0.75.0. A round-trip test would catch this whole class of bug automatically.

Steps to Reproduce

With AlertmanagerConfig v1beta1 served through the conversion webhook, applying this object fails:

yaml
apiVersion: monitoring.coreos.com/v1beta1
kind: AlertmanagerConfig
metadata:
  name: email
spec:
  route:
    receiver: email
  receivers:
  - name: email
    emailConfigs:
    - to: [email protected]

To reproduce without a cluster, add these tests in pkg/apis/monitoring/v1beta1:

go
func TestEmailWithoutThreading(t *testing.T) {
	to := "[email protected]"
	src := &AlertmanagerConfig{Spec: AlertmanagerConfigSpec{Receivers: []Receiver{{
		Name: "r", EmailConfigs: []EmailConfig{{To: &to}},
	}}}}
	_ = src.ConvertTo(&v1alpha1.AlertmanagerConfig{}) // panics at conversion_to.go:457
}

func TestPushoverTTL(t *testing.T) {
	ttl := monitoringv1.Duration("1h")
	src := &AlertmanagerConfig{Spec: AlertmanagerConfigSpec{Receivers: []Receiver{{
		Name: "r", PushoverConfigs: []PushoverConfig{{TTL: &ttl}},
	}}}}
	dst := &v1alpha1.AlertmanagerConfig{}
	_ = src.ConvertTo(dst)
	t.Log(dst.Spec.Receivers[0].PushoverConfigs[0].TTL) // prints <nil>
}

Expected Result

Email receivers without threading convert successfully, and ttl is kept in both directions.

Actual Result

These are the results I got from sending ConversionReviews to the /convert handler:

Input v1beta1 to v1alpha1 v1alpha1 to v1beta1
email, no threading Failure: internal error occurred during conversion Failure: internal error occurred during conversion
email, threading: {} Success Success
pushover, ttl: 1h Success, but the output is pushoverConfigs: [{}] Success, but the output is pushoverConfigs: [{}]

Anything else?

Here's how I'd fix it:

  • Add nil checks to both threading converters and copy TTL in both Pushover converters.
  • Add pkg/apis/monitoring/v1beta1/conversion_test.go with two tests:
    • A randomized round-trip test using sigs.k8s.io/randfill, which is already in the module graph. It would also catch any new field that gets added to the types but not to the converters.
    • A table test that converts a minimal config for each receiver type, with all optional fields left unset.

I also have a question. The round-trip test shows that opsgenieConfigs[].updateAlerts is lost when an object goes from v1alpha1 to v1beta1 and back, because the field only exists in v1alpha1. Is that intended? If it is, I'll allow-list it in the test.

I'm happy to work on both bugs. Once we've agreed on the approach, I'll also add full test coverage for the conversion code.

Source: prometheus-operator/prometheus-operator