From 71b06e984518833cc8b5277bba9b233975969c6a Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Tue, 15 Apr 2025 22:52:56 +0200 Subject: [PATCH] Alerting: Return an empty array for contact points with no integrations (#104063) Co-authored-by: Matthew Jacobson --- .../alerting/notifications/receiver/conversions.go | 3 ++- .../alerting/notifications/receivers/receiver_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/registry/apis/alerting/notifications/receiver/conversions.go b/pkg/registry/apis/alerting/notifications/receiver/conversions.go index 6ba2b6b5975..fb8d49ad6e1 100644 --- a/pkg/registry/apis/alerting/notifications/receiver/conversions.go +++ b/pkg/registry/apis/alerting/notifications/receiver/conversions.go @@ -58,7 +58,8 @@ func convertToK8sResource( namespacer request.NamespaceMapper, ) (*model.Receiver, error) { spec := model.Spec{ - Title: receiver.Name, + Title: receiver.Name, + Integrations: make([]model.Integration, 0, len(receiver.Integrations)), } for _, integration := range receiver.Integrations { spec.Integrations = append(spec.Integrations, model.Integration{ diff --git a/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go b/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go index 43bc217123b..3105c526e7b 100644 --- a/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go +++ b/pkg/tests/apis/alerting/notifications/receivers/receiver_test.go @@ -75,7 +75,7 @@ func TestIntegrationResourceIdentifier(t *testing.T) { }, Spec: v0alpha1.Spec{ Title: "Test-Receiver", - Integrations: nil, + Integrations: []v0alpha1.Integration{}, }, } @@ -307,7 +307,7 @@ func TestIntegrationResourcePermissions(t *testing.T) { }, Spec: v0alpha1.Spec{ Title: "receiver-1", - Integrations: nil, + Integrations: []v0alpha1.Integration{}, }, } d, err := json.Marshal(created) @@ -573,7 +573,7 @@ func TestIntegrationAccessControl(t *testing.T) { }, Spec: v0alpha1.Spec{ Title: fmt.Sprintf("receiver-1-%s", tc.user.Identity.GetLogin()), - Integrations: nil, + Integrations: []v0alpha1.Integration{}, }, } d, err := json.Marshal(expected) @@ -929,7 +929,7 @@ func TestIntegrationOptimisticConcurrency(t *testing.T) { }, Spec: v0alpha1.Spec{ Title: "receiver-1", - Integrations: nil, + Integrations: []v0alpha1.Integration{}, }, } @@ -1271,7 +1271,7 @@ func TestIntegrationCRUD(t *testing.T) { }, Spec: v0alpha1.Spec{ Title: defaultReceiver.Spec.Title, - Integrations: nil, + Integrations: []v0alpha1.Integration{}, }, } _, err := adminClient.Create(ctx, newReceiver, v1.CreateOptions{})