diff --git a/Documentation/api-reference/api.md b/Documentation/api-reference/api.md index 7b6cb46ca..4a7b1a898 100644 --- a/Documentation/api-reference/api.md +++ b/Documentation/api-reference/api.md @@ -34283,7 +34283,9 @@ bool
apiURLstring alias)-(Appears on:DiscordConfig, KumaSDConfig, OpsGenieConfig, PagerDutyConfig, PagerDutyImageConfig, PagerDutyLinkConfig, PushoverConfig, RocketChatActionConfig, RocketChatConfig, SlackAction, SlackConfig, TelegramConfig, VictorOpsConfig, WeChatConfig, WebexConfig, WebhookConfig) +(Appears on:DiscordConfig, KumaSDConfig, OpsGenieConfig, PagerDutyConfig, PagerDutyImageConfig, PagerDutyLinkConfig, PushoverConfig, RocketChatActionConfig, RocketChatConfig, SNSConfig, SlackAction, SlackConfig, TelegramConfig, VictorOpsConfig, WeChatConfig, WebexConfig, WebhookConfig)
URL represents a valid URL
@@ -39965,7 +39967,9 @@ boolapiURLstring alias)-(Appears on:DiscordConfig, OpsGenieConfig, PagerDutyConfig, PagerDutyImageConfig, PagerDutyLinkConfig, PushoverConfig, RocketChatActionConfig, RocketChatConfig, SlackAction, SlackConfig, TelegramConfig, VictorOpsConfig, WeChatConfig, WebexConfig, WebhookConfig) +(Appears on:DiscordConfig, OpsGenieConfig, PagerDutyConfig, PagerDutyImageConfig, PagerDutyLinkConfig, PushoverConfig, RocketChatActionConfig, RocketChatConfig, SNSConfig, SlackAction, SlackConfig, TelegramConfig, VictorOpsConfig, WeChatConfig, WebexConfig, WebhookConfig)
URL represents a valid URL
diff --git a/bundle.yaml b/bundle.yaml index 5610716ea..f1aaad5bb 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -7368,6 +7368,7 @@ 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: @@ -8086,11 +8087,13 @@ spec: description: |- message defines the message content of the SNS notification. This is the actual notification text that will be sent to subscribers. + minLength: 1 type: string phoneNumber: description: |- phoneNumber defines the phone number if message is delivered via SMS in E.164 format. If you don't specify this value, you must specify a value for the TopicARN or TargetARN. + minLength: 1 type: string sendResolved: description: sendResolved defines whether or not to notify @@ -8175,16 +8178,19 @@ spec: description: |- subject defines the subject line when the message is delivered to email endpoints. This field is only used when sending to email subscribers of an SNS topic. + minLength: 1 type: string targetARN: description: |- targetARN defines the mobile platform endpoint ARN if message is delivered via mobile notifications. If you don't specify this value, you must specify a value for the TopicARN or PhoneNumber. + minLength: 1 type: string topicARN: description: |- topicARN defines the SNS topic ARN, e.g. arn:aws:sns:us-east-2:698519295917:My-Topic. If you don't specify this value, you must specify a value for the PhoneNumber or TargetARN. + minLength: 1 type: string type: object type: array 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 a9ce7832f..a1c1c42d1 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_alertmanagerconfigs.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_alertmanagerconfigs.yaml @@ -7367,6 +7367,7 @@ 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: @@ -8085,11 +8086,13 @@ spec: description: |- message defines the message content of the SNS notification. This is the actual notification text that will be sent to subscribers. + minLength: 1 type: string phoneNumber: description: |- phoneNumber defines the phone number if message is delivered via SMS in E.164 format. If you don't specify this value, you must specify a value for the TopicARN or TargetARN. + minLength: 1 type: string sendResolved: description: sendResolved defines whether or not to notify @@ -8174,16 +8177,19 @@ spec: description: |- subject defines the subject line when the message is delivered to email endpoints. This field is only used when sending to email subscribers of an SNS topic. + minLength: 1 type: string targetARN: description: |- targetARN defines the mobile platform endpoint ARN if message is delivered via mobile notifications. If you don't specify this value, you must specify a value for the TopicARN or PhoneNumber. + minLength: 1 type: string topicARN: description: |- topicARN defines the SNS topic ARN, e.g. arn:aws:sns:us-east-2:698519295917:My-Topic. If you don't specify this value, you must specify a value for the PhoneNumber or TargetARN. + minLength: 1 type: string type: object type: array @@ -19429,6 +19435,7 @@ 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: @@ -20140,11 +20147,13 @@ spec: description: |- message defines the message content of the SNS notification. This is the actual notification text that will be sent to subscribers. + minLength: 1 type: string phoneNumber: description: |- phoneNumber defines the phone number if message is delivered via SMS in E.164 format. If you don't specify this value, you must specify a value for the TopicARN or TargetARN. + minLength: 1 type: string sendResolved: description: sendResolved defines whether or not to notify @@ -20229,16 +20238,19 @@ spec: description: |- subject defines the subject line when the message is delivered to email endpoints. This field is only used when sending to email subscribers of an SNS topic. + minLength: 1 type: string targetARN: description: |- targetARN defines the mobile platform endpoint ARN if message is delivered via mobile notifications. If you don't specify this value, you must specify a value for the TopicARN or PhoneNumber. + minLength: 1 type: string topicARN: description: |- topicARN defines the SNS topic ARN, e.g. arn:aws:sns:us-east-2:698519295917:My-Topic. If you don't specify this value, you must specify a value for the PhoneNumber or TargetARN. + minLength: 1 type: string type: object type: array diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml index c43adc089..7e3e99fa4 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml @@ -7368,6 +7368,7 @@ 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: @@ -8086,11 +8087,13 @@ spec: description: |- message defines the message content of the SNS notification. This is the actual notification text that will be sent to subscribers. + minLength: 1 type: string phoneNumber: description: |- phoneNumber defines the phone number if message is delivered via SMS in E.164 format. If you don't specify this value, you must specify a value for the TopicARN or TargetARN. + minLength: 1 type: string sendResolved: description: sendResolved defines whether or not to notify @@ -8175,16 +8178,19 @@ spec: description: |- subject defines the subject line when the message is delivered to email endpoints. This field is only used when sending to email subscribers of an SNS topic. + minLength: 1 type: string targetARN: description: |- targetARN defines the mobile platform endpoint ARN if message is delivered via mobile notifications. If you don't specify this value, you must specify a value for the TopicARN or PhoneNumber. + minLength: 1 type: string topicARN: description: |- topicARN defines the SNS topic ARN, e.g. arn:aws:sns:us-east-2:698519295917:My-Topic. If you don't specify this value, you must specify a value for the PhoneNumber or TargetARN. + minLength: 1 type: string type: object type: array diff --git a/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json b/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json index 63717d3f6..3a284278d 100644 --- a/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json +++ b/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json @@ -6714,6 +6714,7 @@ "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": { @@ -7366,10 +7367,12 @@ }, "message": { "description": "message defines the message content of the SNS notification.\nThis is the actual notification text that will be sent to subscribers.", + "minLength": 1, "type": "string" }, "phoneNumber": { "description": "phoneNumber defines the phone number if message is delivered via SMS in E.164 format.\nIf you don't specify this value, you must specify a value for the TopicARN or TargetARN.", + "minLength": 1, "type": "string" }, "sendResolved": { @@ -7446,14 +7449,17 @@ }, "subject": { "description": "subject defines the subject line when the message is delivered to email endpoints.\nThis field is only used when sending to email subscribers of an SNS topic.", + "minLength": 1, "type": "string" }, "targetARN": { "description": "targetARN defines the mobile platform endpoint ARN if message is delivered via mobile notifications.\nIf you don't specify this value, you must specify a value for the TopicARN or PhoneNumber.", + "minLength": 1, "type": "string" }, "topicARN": { "description": "topicARN defines the SNS topic ARN, e.g. arn:aws:sns:us-east-2:698519295917:My-Topic.\nIf you don't specify this value, you must specify a value for the PhoneNumber or TargetARN.", + "minLength": 1, "type": "string" } }, diff --git a/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet b/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet index 86a759ad4..88c0d950f 100644 --- a/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet +++ b/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet @@ -6507,6 +6507,7 @@ 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: { @@ -7156,10 +7157,12 @@ }, message: { description: 'message defines the message content of the SNS notification.\nThis is the actual notification text that will be sent to subscribers.', + minLength: 1, type: 'string', }, phoneNumber: { description: "phoneNumber defines the phone number if message is delivered via SMS in E.164 format.\nIf you don't specify this value, you must specify a value for the TopicARN or TargetARN.", + minLength: 1, type: 'string', }, sendResolved: { @@ -7236,14 +7239,17 @@ }, subject: { description: 'subject defines the subject line when the message is delivered to email endpoints.\nThis field is only used when sending to email subscribers of an SNS topic.', + minLength: 1, type: 'string', }, targetARN: { description: "targetARN defines the mobile platform endpoint ARN if message is delivered via mobile notifications.\nIf you don't specify this value, you must specify a value for the TopicARN or PhoneNumber.", + minLength: 1, type: 'string', }, topicARN: { description: "topicARN defines the SNS topic ARN, e.g. arn:aws:sns:us-east-2:698519295917:My-Topic.\nIf you don't specify this value, you must specify a value for the PhoneNumber or TargetARN.", + minLength: 1, type: 'string', }, }, diff --git a/pkg/alertmanager/amcfg.go b/pkg/alertmanager/amcfg.go index a2303ea19..63ebca8c6 100644 --- a/pkg/alertmanager/amcfg.go +++ b/pkg/alertmanager/amcfg.go @@ -1438,15 +1438,33 @@ func (cb *ConfigBuilder) convertTelegramConfig(ctx context.Context, in monitorin func (cb *ConfigBuilder) convertSnsConfig(ctx context.Context, in monitoringv1alpha1.SNSConfig, crKey types.NamespacedName) (*snsConfig, error) { out := &snsConfig{ VSendResolved: in.SendResolved, - APIUrl: in.ApiURL, - TopicARN: in.TopicARN, - PhoneNumber: in.PhoneNumber, - TargetARN: in.TargetARN, - Subject: in.Subject, - Message: in.Message, Attributes: in.Attributes, } + if in.ApiURL != nil { + out.APIUrl = string(*in.ApiURL) + } + + if in.TopicARN != nil { + out.TopicARN = *in.TopicARN + } + + if in.PhoneNumber != nil { + out.PhoneNumber = *in.PhoneNumber + } + + if in.TargetARN != nil { + out.TargetARN = *in.TargetARN + } + + if in.Subject != nil { + out.Subject = *in.Subject + } + + if in.Message != nil { + out.Message = *in.Message + } + httpConfig, err := cb.convertHTTPConfig(ctx, in.HTTPConfig, crKey) if err != nil { return nil, err diff --git a/pkg/alertmanager/amcfg_test.go b/pkg/alertmanager/amcfg_test.go index 45074d092..6fb6caf7b 100644 --- a/pkg/alertmanager/amcfg_test.go +++ b/pkg/alertmanager/amcfg_test.go @@ -3183,7 +3183,7 @@ func TestGenerateConfig(t *testing.T) { Name: "test", SNSConfigs: []monitoringv1alpha1.SNSConfig{ { - ApiURL: "https://sns.us-east-2.amazonaws.com", + ApiURL: ptr.To(monitoringv1alpha1.URL("https://sns.us-east-2.amazonaws.com")), Sigv4: &monitoringv1.Sigv4{ Region: "us-east-2", AccessKey: &corev1.SecretKeySelector{ @@ -3199,7 +3199,7 @@ func TestGenerateConfig(t *testing.T) { Key: "secret", }, }, - TopicARN: "test-topicARN", + TopicARN: ptr.To("test-topicARN"), }, }, }}, @@ -3241,12 +3241,12 @@ func TestGenerateConfig(t *testing.T) { Name: "test", SNSConfigs: []monitoringv1alpha1.SNSConfig{ { - ApiURL: "https://sns.us-east-2.amazonaws.com", + ApiURL: ptr.To(monitoringv1alpha1.URL("https://sns.us-east-2.amazonaws.com")), Sigv4: &monitoringv1.Sigv4{ Region: "us-east-2", RoleArn: "test-roleARN", }, - TopicARN: "test-topicARN", + TopicARN: ptr.To("test-topicARN"), }, }, }}, diff --git a/pkg/alertmanager/operator_test.go b/pkg/alertmanager/operator_test.go index 245fcb07b..091791c72 100644 --- a/pkg/alertmanager/operator_test.go +++ b/pkg/alertmanager/operator_test.go @@ -1117,6 +1117,30 @@ func TestCheckAlertmanagerConfig(t *testing.T) { }, ok: false, }, + { + amConfig: &monitoringv1alpha1.AlertmanagerConfig{ + ObjectMeta: metav1.ObjectMeta{ + Name: "sns-with-invalid-api-url", + Namespace: "ns1", + }, + Spec: monitoringv1alpha1.AlertmanagerConfigSpec{ + Receivers: []monitoringv1alpha1.Receiver{{ + Name: "recv1", + SNSConfigs: []monitoringv1alpha1.SNSConfig{ + { + ApiURL: ptr.To(monitoringv1alpha1.URL("https:://sns.us-east-2.amazonaws.com")), + Sigv4: &monitoringv1.Sigv4{ + Region: "us-east-2", + RoleArn: "test-roleARN", + }, + TopicARN: ptr.To("test-topicARN"), + }, + }, + }}, + }, + }, + ok: false, + }, } { t.Run(tc.amConfig.Name, func(t *testing.T) { store := assets.NewStoreBuilder(c.CoreV1(), c.CoreV1()) diff --git a/pkg/alertmanager/validation/v1alpha1/validation.go b/pkg/alertmanager/validation/v1alpha1/validation.go index 78c0e139e..3bfe82c78 100644 --- a/pkg/alertmanager/validation/v1alpha1/validation.go +++ b/pkg/alertmanager/validation/v1alpha1/validation.go @@ -350,9 +350,13 @@ func validatePushoverConfigs(configs []monitoringv1alpha1.PushoverConfig) error } func validateSnsConfigs(configs []monitoringv1alpha1.SNSConfig) error { - for _, config := range configs { - if (config.TargetARN == "") != (config.TopicARN == "") != (config.PhoneNumber == "") { - return fmt.Errorf("must provide either a Target ARN, Topic ARN, or Phone Number for SNS config") + for i, config := range configs { + if (ptr.Deref(config.TargetARN, "") == "") != (ptr.Deref(config.TopicARN, "") == "") != (ptr.Deref(config.PhoneNumber, "") == "") { + 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 err := config.HTTPConfig.Validate(); err != nil { diff --git a/pkg/alertmanager/validation/v1beta1/validation.go b/pkg/alertmanager/validation/v1beta1/validation.go index f7161d6cc..47323b47b 100644 --- a/pkg/alertmanager/validation/v1beta1/validation.go +++ b/pkg/alertmanager/validation/v1beta1/validation.go @@ -327,9 +327,13 @@ func validatePushoverConfigs(configs []monitoringv1beta1.PushoverConfig) error { } func validateSnsConfigs(configs []monitoringv1beta1.SNSConfig) error { - for _, config := range configs { - if (config.TargetARN == "") != (config.TopicARN == "") != (config.PhoneNumber == "") { - return fmt.Errorf("must provide either a Target ARN, Topic ARN, or Phone Number for SNS config") + for i, config := range configs { + if (ptr.Deref(config.TargetARN, "") == "") != (ptr.Deref(config.TopicARN, "") == "") != (ptr.Deref(config.PhoneNumber, "") == "") { + 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 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 b9e34dec6..b6ac61425 100644 --- a/pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go +++ b/pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go @@ -1151,31 +1151,36 @@ 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 string `json:"apiURL,omitempty"` + ApiURL *URL `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 Sigv4 *monitoringv1.Sigv4 `json:"sigv4,omitempty"` // topicARN defines the SNS topic ARN, e.g. arn:aws:sns:us-east-2:698519295917:My-Topic. // If you don't specify this value, you must specify a value for the PhoneNumber or TargetARN. + // +kubebuilder:validation:MinLength=1 // +optional - TopicARN string `json:"topicARN,omitempty"` + TopicARN *string `json:"topicARN,omitempty"` // subject defines the subject line when the message is delivered to email endpoints. // This field is only used when sending to email subscribers of an SNS topic. + // +kubebuilder:validation:MinLength=1 // +optional - Subject string `json:"subject,omitempty"` + Subject *string `json:"subject,omitempty"` // phoneNumber defines the phone number if message is delivered via SMS in E.164 format. + // +kubebuilder:validation:MinLength=1 // If you don't specify this value, you must specify a value for the TopicARN or TargetARN. // +optional - PhoneNumber string `json:"phoneNumber,omitempty"` + PhoneNumber *string `json:"phoneNumber,omitempty"` // targetARN defines the mobile platform endpoint ARN if message is delivered via mobile notifications. // If you don't specify this value, you must specify a value for the TopicARN or PhoneNumber. + // +kubebuilder:validation:MinLength=1 // +optional - TargetARN string `json:"targetARN,omitempty"` + TargetARN *string `json:"targetARN,omitempty"` // message defines the message content of the SNS notification. // This is the actual notification text that will be sent to subscribers. + // +kubebuilder:validation:MinLength=1 // +optional - Message string `json:"message,omitempty"` + Message *string `json:"message,omitempty"` // attributes defines SNS message attributes as key-value pairs. // These provide additional metadata that can be used for message filtering and routing. // +optional diff --git a/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go index e3ff7b807..9effc2cce 100644 --- a/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go @@ -2654,11 +2654,41 @@ func (in *SNSConfig) DeepCopyInto(out *SNSConfig) { *out = new(bool) **out = **in } + if in.ApiURL != nil { + in, out := &in.ApiURL, &out.ApiURL + *out = new(URL) + **out = **in + } if in.Sigv4 != nil { in, out := &in.Sigv4, &out.Sigv4 *out = new(monitoringv1.Sigv4) (*in).DeepCopyInto(*out) } + if in.TopicARN != nil { + in, out := &in.TopicARN, &out.TopicARN + *out = new(string) + **out = **in + } + if in.Subject != nil { + in, out := &in.Subject, &out.Subject + *out = new(string) + **out = **in + } + if in.PhoneNumber != nil { + in, out := &in.PhoneNumber, &out.PhoneNumber + *out = new(string) + **out = **in + } + if in.TargetARN != nil { + in, out := &in.TargetARN, &out.TargetARN + *out = new(string) + **out = **in + } + if in.Message != nil { + in, out := &in.Message, &out.Message + *out = new(string) + **out = **in + } if in.Attributes != nil { in, out := &in.Attributes, &out.Attributes *out = make(map[string]string, len(*in)) diff --git a/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go b/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go index 67cd147c3..8277b15a7 100644 --- a/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go +++ b/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go @@ -1117,31 +1117,36 @@ 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 string `json:"apiURL,omitempty"` + ApiURL *URL `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 Sigv4 *monitoringv1.Sigv4 `json:"sigv4,omitempty"` // topicARN defines the SNS topic ARN, e.g. arn:aws:sns:us-east-2:698519295917:My-Topic. // If you don't specify this value, you must specify a value for the PhoneNumber or TargetARN. + // +kubebuilder:validation:MinLength=1 // +optional - TopicARN string `json:"topicARN,omitempty"` + TopicARN *string `json:"topicARN,omitempty"` // subject defines the subject line when the message is delivered to email endpoints. // This field is only used when sending to email subscribers of an SNS topic. + // +kubebuilder:validation:MinLength=1 // +optional - Subject string `json:"subject,omitempty"` + Subject *string `json:"subject,omitempty"` // phoneNumber defines the phone number if message is delivered via SMS in E.164 format. + // +kubebuilder:validation:MinLength=1 // If you don't specify this value, you must specify a value for the TopicARN or TargetARN. // +optional - PhoneNumber string `json:"phoneNumber,omitempty"` + PhoneNumber *string `json:"phoneNumber,omitempty"` // targetARN defines the mobile platform endpoint ARN if message is delivered via mobile notifications. // If you don't specify this value, you must specify a value for the TopicARN or PhoneNumber. + // +kubebuilder:validation:MinLength=1 // +optional - TargetARN string `json:"targetARN,omitempty"` + TargetARN *string `json:"targetARN,omitempty"` // message defines the message content of the SNS notification. // This is the actual notification text that will be sent to subscribers. + // +kubebuilder:validation:MinLength=1 // +optional - Message string `json:"message,omitempty"` + Message *string `json:"message,omitempty"` // attributes defines SNS message attributes as key-value pairs. // These provide additional metadata that can be used for message filtering and routing. // +optional diff --git a/pkg/apis/monitoring/v1beta1/conversion_from.go b/pkg/apis/monitoring/v1beta1/conversion_from.go index 714dde394..a4f622208 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: in.ApiURL, + ApiURL: (*URL)(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 931b5373b..dae1ae2dc 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: in.ApiURL, + ApiURL: (*v1alpha1.URL)(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 8ef9391cf..a134c5f96 100644 --- a/pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go @@ -1168,11 +1168,41 @@ func (in *SNSConfig) DeepCopyInto(out *SNSConfig) { *out = new(bool) **out = **in } + if in.ApiURL != nil { + in, out := &in.ApiURL, &out.ApiURL + *out = new(URL) + **out = **in + } if in.Sigv4 != nil { in, out := &in.Sigv4, &out.Sigv4 *out = new(monitoringv1.Sigv4) (*in).DeepCopyInto(*out) } + if in.TopicARN != nil { + in, out := &in.TopicARN, &out.TopicARN + *out = new(string) + **out = **in + } + if in.Subject != nil { + in, out := &in.Subject, &out.Subject + *out = new(string) + **out = **in + } + if in.PhoneNumber != nil { + in, out := &in.PhoneNumber, &out.PhoneNumber + *out = new(string) + **out = **in + } + if in.TargetARN != nil { + in, out := &in.TargetARN, &out.TargetARN + *out = new(string) + **out = **in + } + if in.Message != nil { + in, out := &in.Message, &out.Message + *out = new(string) + **out = **in + } if in.Attributes != nil { in, out := &in.Attributes, &out.Attributes *out = make(map[string]string, len(*in)) diff --git a/pkg/client/applyconfiguration/monitoring/v1alpha1/snsconfig.go b/pkg/client/applyconfiguration/monitoring/v1alpha1/snsconfig.go index ec078b022..39738b2b5 100644 --- a/pkg/client/applyconfiguration/monitoring/v1alpha1/snsconfig.go +++ b/pkg/client/applyconfiguration/monitoring/v1alpha1/snsconfig.go @@ -17,6 +17,7 @@ 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" ) @@ -24,7 +25,7 @@ import ( // with apply. type SNSConfigApplyConfiguration struct { SendResolved *bool `json:"sendResolved,omitempty"` - ApiURL *string `json:"apiURL,omitempty"` + ApiURL *monitoringv1alpha1.URL `json:"apiURL,omitempty"` Sigv4 *v1.Sigv4ApplyConfiguration `json:"sigv4,omitempty"` TopicARN *string `json:"topicARN,omitempty"` Subject *string `json:"subject,omitempty"` @@ -52,7 +53,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 string) *SNSConfigApplyConfiguration { +func (b *SNSConfigApplyConfiguration) WithApiURL(value monitoringv1alpha1.URL) *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 dece1067c..6a6b9d617 100644 --- a/pkg/client/applyconfiguration/monitoring/v1beta1/snsconfig.go +++ b/pkg/client/applyconfiguration/monitoring/v1beta1/snsconfig.go @@ -17,6 +17,7 @@ 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" ) @@ -24,7 +25,7 @@ import ( // with apply. type SNSConfigApplyConfiguration struct { SendResolved *bool `json:"sendResolved,omitempty"` - ApiURL *string `json:"apiURL,omitempty"` + ApiURL *monitoringv1beta1.URL `json:"apiURL,omitempty"` Sigv4 *v1.Sigv4ApplyConfiguration `json:"sigv4,omitempty"` TopicARN *string `json:"topicARN,omitempty"` Subject *string `json:"subject,omitempty"` @@ -52,7 +53,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 string) *SNSConfigApplyConfiguration { +func (b *SNSConfigApplyConfiguration) WithApiURL(value monitoringv1beta1.URL) *SNSConfigApplyConfiguration { b.ApiURL = &value return b } diff --git a/test/e2e/alertmanager_test.go b/test/e2e/alertmanager_test.go index 5f9ef606b..938ab26ca 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: "https://sns.us-east-2.amazonaws.com", + ApiURL: ptr.To(monitoringv1alpha1.URL("https://sns.us-east-2.amazonaws.com")), Sigv4: &monitoringv1.Sigv4{ Region: "us-east-2", AccessKey: &v1.SecretKeySelector{ @@ -1220,7 +1220,7 @@ func testAlertmanagerConfigCRD(t *testing.T) { Key: testingSecretKey, }, }, - TopicARN: "test-topicARN", + TopicARN: ptr.To("test-topicARN"), }, }, WebexConfigs: []monitoringv1alpha1.WebexConfig{{