From 446c84244dea633c77dae155671ea2864573aad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lia=20Barroso?= <66432275+heliapb@users.noreply.github.com> Date: Thu, 29 Jan 2026 10:25:23 +0000 Subject: [PATCH] fix: sns templating issue (#8320) * fix: sns templating issue --- Documentation/api-reference/api.md | 12 ++++-------- bundle.yaml | 1 - .../monitoring.coreos.com_alertmanagerconfigs.yaml | 2 -- .../monitoring.coreos.com_alertmanagerconfigs.yaml | 1 - .../prometheus-operator/alertmanagerconfigs-crd.json | 1 - .../alertmanagerconfigs-v1beta1-crd.libsonnet | 1 - pkg/alertmanager/amcfg.go | 2 +- pkg/alertmanager/amcfg_test.go | 4 ++-- pkg/alertmanager/operator_test.go | 2 +- pkg/alertmanager/validation/v1alpha1/validation.go | 6 ++++-- pkg/alertmanager/validation/v1beta1/validation.go | 6 ++++-- .../monitoring/v1alpha1/alertmanager_config_types.go | 2 +- .../monitoring/v1alpha1/zz_generated.deepcopy.go | 2 +- .../monitoring/v1beta1/alertmanager_config_types.go | 2 +- pkg/apis/monitoring/v1beta1/conversion_from.go | 2 +- pkg/apis/monitoring/v1beta1/conversion_to.go | 2 +- pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go | 2 +- .../monitoring/v1alpha1/snsconfig.go | 5 ++--- .../monitoring/v1beta1/snsconfig.go | 5 ++--- test/e2e/alertmanager_test.go | 2 +- 20 files changed, 27 insertions(+), 35 deletions(-) diff --git a/Documentation/api-reference/api.md b/Documentation/api-reference/api.md index 892650ce9..cff66e403 100644 --- a/Documentation/api-reference/api.md +++ b/Documentation/api-reference/api.md @@ -34301,9 +34301,7 @@ bool apiURL
- -URL - +string @@ -36446,7 +36444,7 @@ Time

URL (string alias)

-(Appears on:DiscordConfig, KumaSDConfig, OpsGenieConfig, PagerDutyConfig, RocketChatConfig, SNSConfig, TelegramConfig, VictorOpsConfig, WeChatConfig, WebexConfig) +(Appears on:DiscordConfig, KumaSDConfig, OpsGenieConfig, PagerDutyConfig, RocketChatConfig, TelegramConfig, VictorOpsConfig, WeChatConfig, WebexConfig)

URL represents a valid URL

@@ -39957,9 +39955,7 @@ bool apiURL
- -URL - +string @@ -41021,7 +41017,7 @@ Time

URL (string alias)

-(Appears on:DiscordConfig, OpsGenieConfig, PagerDutyConfig, RocketChatConfig, SNSConfig, TelegramConfig, VictorOpsConfig, WeChatConfig, WebexConfig) +(Appears on:DiscordConfig, OpsGenieConfig, PagerDutyConfig, RocketChatConfig, TelegramConfig, VictorOpsConfig, WeChatConfig, WebexConfig)

URL represents a valid URL

diff --git a/bundle.yaml b/bundle.yaml index e627a6aa1..1e275ea48 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -7355,7 +7355,6 @@ spec: description: |- apiURL defines the SNS API URL, e.g. https://sns.us-east-2.amazonaws.com. If not specified, the SNS API URL from the SNS SDK will be used. - pattern: ^https?://.+$ type: string attributes: additionalProperties: diff --git a/example/prometheus-operator-crd-full/monitoring.coreos.com_alertmanagerconfigs.yaml b/example/prometheus-operator-crd-full/monitoring.coreos.com_alertmanagerconfigs.yaml index 67f908292..83b44de42 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_alertmanagerconfigs.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_alertmanagerconfigs.yaml @@ -7354,7 +7354,6 @@ spec: description: |- apiURL defines the SNS API URL, e.g. https://sns.us-east-2.amazonaws.com. If not specified, the SNS API URL from the SNS SDK will be used. - pattern: ^https?://.+$ type: string attributes: additionalProperties: @@ -19408,7 +19407,6 @@ spec: description: |- apiURL defines the SNS API URL, e.g. https://sns.us-east-2.amazonaws.com. If not specified, the SNS API URL from the SNS SDK will be used. - pattern: ^https?://.+$ type: string attributes: additionalProperties: diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml index 77e2bc47f..f2bc0fa7e 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml @@ -7355,7 +7355,6 @@ spec: description: |- apiURL defines the SNS API URL, e.g. https://sns.us-east-2.amazonaws.com. If not specified, the SNS API URL from the SNS SDK will be used. - pattern: ^https?://.+$ type: string attributes: additionalProperties: diff --git a/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json b/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json index 496a29b55..799e72829 100644 --- a/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json +++ b/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json @@ -6701,7 +6701,6 @@ "properties": { "apiURL": { "description": "apiURL defines the SNS API URL, e.g. https://sns.us-east-2.amazonaws.com.\nIf not specified, the SNS API URL from the SNS SDK will be used.", - "pattern": "^https?://.+$", "type": "string" }, "attributes": { diff --git a/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet b/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet index 64652373c..45f6bde18 100644 --- a/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet +++ b/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet @@ -6494,7 +6494,6 @@ properties: { apiURL: { description: 'apiURL defines the SNS API URL, e.g. https://sns.us-east-2.amazonaws.com.\nIf not specified, the SNS API URL from the SNS SDK will be used.', - pattern: '^https?://.+$', type: 'string', }, attributes: { diff --git a/pkg/alertmanager/amcfg.go b/pkg/alertmanager/amcfg.go index eeea32b45..1aef38435 100644 --- a/pkg/alertmanager/amcfg.go +++ b/pkg/alertmanager/amcfg.go @@ -1441,7 +1441,7 @@ func (cb *ConfigBuilder) convertSnsConfig(ctx context.Context, in monitoringv1al } if in.ApiURL != nil { - out.APIUrl = string(*in.ApiURL) + out.APIUrl = *in.ApiURL } if in.TopicARN != nil { diff --git a/pkg/alertmanager/amcfg_test.go b/pkg/alertmanager/amcfg_test.go index f3cc8c6ac..c7fbc01e7 100644 --- a/pkg/alertmanager/amcfg_test.go +++ b/pkg/alertmanager/amcfg_test.go @@ -3220,7 +3220,7 @@ func TestGenerateConfig(t *testing.T) { Name: "test", SNSConfigs: []monitoringv1alpha1.SNSConfig{ { - ApiURL: ptr.To(monitoringv1alpha1.URL("https://sns.us-east-2.amazonaws.com")), + ApiURL: ptr.To("https://sns.us-east-2.amazonaws.com"), Sigv4: &monitoringv1.Sigv4{ Region: "us-east-2", AccessKey: &corev1.SecretKeySelector{ @@ -3278,7 +3278,7 @@ func TestGenerateConfig(t *testing.T) { Name: "test", SNSConfigs: []monitoringv1alpha1.SNSConfig{ { - ApiURL: ptr.To(monitoringv1alpha1.URL("https://sns.us-east-2.amazonaws.com")), + ApiURL: ptr.To("https://sns.us-east-2.amazonaws.com"), Sigv4: &monitoringv1.Sigv4{ Region: "us-east-2", RoleArn: "test-roleARN", diff --git a/pkg/alertmanager/operator_test.go b/pkg/alertmanager/operator_test.go index 91472596c..ecbf04fd5 100644 --- a/pkg/alertmanager/operator_test.go +++ b/pkg/alertmanager/operator_test.go @@ -1246,7 +1246,7 @@ func TestCheckAlertmanagerConfig(t *testing.T) { Name: "recv1", SNSConfigs: []monitoringv1alpha1.SNSConfig{ { - ApiURL: ptr.To(monitoringv1alpha1.URL("https:://sns.us-east-2.amazonaws.com")), + ApiURL: ptr.To("https:://sns.us-east-2.amazonaws.com"), Sigv4: &monitoringv1.Sigv4{ Region: "us-east-2", RoleArn: "test-roleARN", diff --git a/pkg/alertmanager/validation/v1alpha1/validation.go b/pkg/alertmanager/validation/v1alpha1/validation.go index ecd8cbdb6..6386f2782 100644 --- a/pkg/alertmanager/validation/v1alpha1/validation.go +++ b/pkg/alertmanager/validation/v1alpha1/validation.go @@ -345,8 +345,10 @@ func validateSnsConfigs(configs []monitoringv1alpha1.SNSConfig) error { return fmt.Errorf("[%d]: must provide either a targetARN, topicARN, or phoneNumber for SNS config", i) } - if err := validation.ValidateURLPtr((*string)(config.ApiURL)); err != nil { - return fmt.Errorf("[%d]: apiURL: %w", i, err) + if config.ApiURL != nil { + if err := validation.ValidateTemplateURL(*config.ApiURL); err != nil { + return fmt.Errorf("[%d]: apiURL: %w", i, err) + } } if err := config.HTTPConfig.Validate(); err != nil { diff --git a/pkg/alertmanager/validation/v1beta1/validation.go b/pkg/alertmanager/validation/v1beta1/validation.go index 832f5e9e9..a9810228c 100644 --- a/pkg/alertmanager/validation/v1beta1/validation.go +++ b/pkg/alertmanager/validation/v1beta1/validation.go @@ -322,8 +322,10 @@ func validateSnsConfigs(configs []monitoringv1beta1.SNSConfig) error { return fmt.Errorf("[%d]: must provide either a targetARN, topicARN, or phoneNumber for SNS config", i) } - if err := validation.ValidateURLPtr((*string)(config.ApiURL)); err != nil { - return fmt.Errorf("[%d]: apiURL: %w", i, err) + if config.ApiURL != nil { + if err := validation.ValidateTemplateURL(*config.ApiURL); err != nil { + return fmt.Errorf("[%d]: apiURL: %w", i, err) + } } if err := config.HTTPConfig.Validate(); err != nil { diff --git a/pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go b/pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go index b64a80845..52798017d 100644 --- a/pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go +++ b/pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go @@ -1053,7 +1053,7 @@ type SNSConfig struct { // apiURL defines the SNS API URL, e.g. https://sns.us-east-2.amazonaws.com. // If not specified, the SNS API URL from the SNS SDK will be used. // +optional - ApiURL *URL `json:"apiURL,omitempty"` + ApiURL *string `json:"apiURL,omitempty"` // sigv4 configures AWS's Signature Verification 4 signing process to sign requests. // This includes AWS credentials and region configuration for authentication. // +optional diff --git a/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go index 0b1eb8d9f..f9071f2d8 100644 --- a/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go @@ -2651,7 +2651,7 @@ func (in *SNSConfig) DeepCopyInto(out *SNSConfig) { } if in.ApiURL != nil { in, out := &in.ApiURL, &out.ApiURL - *out = new(URL) + *out = new(string) **out = **in } if in.Sigv4 != nil { diff --git a/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go b/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go index cce705ee8..a77369ee7 100644 --- a/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go +++ b/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go @@ -1019,7 +1019,7 @@ type SNSConfig struct { // apiURL defines the SNS API URL, e.g. https://sns.us-east-2.amazonaws.com. // If not specified, the SNS API URL from the SNS SDK will be used. // +optional - ApiURL *URL `json:"apiURL,omitempty"` + ApiURL *string `json:"apiURL,omitempty"` // sigv4 configures AWS's Signature Verification 4 signing process to sign requests. // This includes AWS credentials and region configuration for authentication. // +optional diff --git a/pkg/apis/monitoring/v1beta1/conversion_from.go b/pkg/apis/monitoring/v1beta1/conversion_from.go index ed0632805..e15d22bea 100644 --- a/pkg/apis/monitoring/v1beta1/conversion_from.go +++ b/pkg/apis/monitoring/v1beta1/conversion_from.go @@ -491,7 +491,7 @@ func convertPushoverConfigFrom(in v1alpha1.PushoverConfig) PushoverConfig { func convertSNSConfigFrom(in v1alpha1.SNSConfig) SNSConfig { return SNSConfig{ SendResolved: in.SendResolved, - ApiURL: (*URL)(in.ApiURL), + ApiURL: in.ApiURL, Sigv4: in.Sigv4, TopicARN: in.TopicARN, Subject: in.Subject, diff --git a/pkg/apis/monitoring/v1beta1/conversion_to.go b/pkg/apis/monitoring/v1beta1/conversion_to.go index b666a58dc..474aa4900 100644 --- a/pkg/apis/monitoring/v1beta1/conversion_to.go +++ b/pkg/apis/monitoring/v1beta1/conversion_to.go @@ -487,7 +487,7 @@ func convertPushoverConfigTo(in PushoverConfig) v1alpha1.PushoverConfig { func convertSNSConfigTo(in SNSConfig) v1alpha1.SNSConfig { return v1alpha1.SNSConfig{ SendResolved: in.SendResolved, - ApiURL: (*v1alpha1.URL)(in.ApiURL), + ApiURL: in.ApiURL, Sigv4: in.Sigv4, TopicARN: in.TopicARN, Subject: in.Subject, diff --git a/pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go index 6eccf4498..548e8ff87 100644 --- a/pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go @@ -1165,7 +1165,7 @@ func (in *SNSConfig) DeepCopyInto(out *SNSConfig) { } if in.ApiURL != nil { in, out := &in.ApiURL, &out.ApiURL - *out = new(URL) + *out = new(string) **out = **in } if in.Sigv4 != nil { diff --git a/pkg/client/applyconfiguration/monitoring/v1alpha1/snsconfig.go b/pkg/client/applyconfiguration/monitoring/v1alpha1/snsconfig.go index 39738b2b5..ec078b022 100644 --- a/pkg/client/applyconfiguration/monitoring/v1alpha1/snsconfig.go +++ b/pkg/client/applyconfiguration/monitoring/v1alpha1/snsconfig.go @@ -17,7 +17,6 @@ package v1alpha1 import ( - monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1" v1 "github.com/prometheus-operator/prometheus-operator/pkg/client/applyconfiguration/monitoring/v1" ) @@ -25,7 +24,7 @@ import ( // with apply. type SNSConfigApplyConfiguration struct { SendResolved *bool `json:"sendResolved,omitempty"` - ApiURL *monitoringv1alpha1.URL `json:"apiURL,omitempty"` + ApiURL *string `json:"apiURL,omitempty"` Sigv4 *v1.Sigv4ApplyConfiguration `json:"sigv4,omitempty"` TopicARN *string `json:"topicARN,omitempty"` Subject *string `json:"subject,omitempty"` @@ -53,7 +52,7 @@ func (b *SNSConfigApplyConfiguration) WithSendResolved(value bool) *SNSConfigApp // WithApiURL sets the ApiURL field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the ApiURL field is set to the value of the last call. -func (b *SNSConfigApplyConfiguration) WithApiURL(value monitoringv1alpha1.URL) *SNSConfigApplyConfiguration { +func (b *SNSConfigApplyConfiguration) WithApiURL(value string) *SNSConfigApplyConfiguration { b.ApiURL = &value return b } diff --git a/pkg/client/applyconfiguration/monitoring/v1beta1/snsconfig.go b/pkg/client/applyconfiguration/monitoring/v1beta1/snsconfig.go index 6a6b9d617..dece1067c 100644 --- a/pkg/client/applyconfiguration/monitoring/v1beta1/snsconfig.go +++ b/pkg/client/applyconfiguration/monitoring/v1beta1/snsconfig.go @@ -17,7 +17,6 @@ package v1beta1 import ( - monitoringv1beta1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1beta1" v1 "github.com/prometheus-operator/prometheus-operator/pkg/client/applyconfiguration/monitoring/v1" ) @@ -25,7 +24,7 @@ import ( // with apply. type SNSConfigApplyConfiguration struct { SendResolved *bool `json:"sendResolved,omitempty"` - ApiURL *monitoringv1beta1.URL `json:"apiURL,omitempty"` + ApiURL *string `json:"apiURL,omitempty"` Sigv4 *v1.Sigv4ApplyConfiguration `json:"sigv4,omitempty"` TopicARN *string `json:"topicARN,omitempty"` Subject *string `json:"subject,omitempty"` @@ -53,7 +52,7 @@ func (b *SNSConfigApplyConfiguration) WithSendResolved(value bool) *SNSConfigApp // WithApiURL sets the ApiURL field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the ApiURL field is set to the value of the last call. -func (b *SNSConfigApplyConfiguration) WithApiURL(value monitoringv1beta1.URL) *SNSConfigApplyConfiguration { +func (b *SNSConfigApplyConfiguration) WithApiURL(value string) *SNSConfigApplyConfiguration { b.ApiURL = &value return b } diff --git a/test/e2e/alertmanager_test.go b/test/e2e/alertmanager_test.go index ac3505972..476e72227 100644 --- a/test/e2e/alertmanager_test.go +++ b/test/e2e/alertmanager_test.go @@ -1204,7 +1204,7 @@ func testAlertmanagerConfigCRD(t *testing.T) { }}, SNSConfigs: []monitoringv1alpha1.SNSConfig{ { - ApiURL: ptr.To(monitoringv1alpha1.URL("https://sns.us-east-2.amazonaws.com")), + ApiURL: ptr.To("https://sns.us-east-2.amazonaws.com"), Sigv4: &monitoringv1.Sigv4{ Region: "us-east-2", AccessKey: &v1.SecretKeySelector{