Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support user_key_file and token_file to the pushover #5886

Merged
merged 21 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions Documentation/api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions bundle.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions jsonnet/prometheus-operator/alertmanagerconfigs-crd.json
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,10 @@
],
"type": "object"
},
"tokenFile": {
"description": "The token file that contains the registered application's API token, see https://pushover.net/apps. The token file needs to be in the same namespace as the AlertmanagerConfig object and accessible by the Prometheus Operator.",
"type": "string"
},
"url": {
"description": "A supplementary URL shown alongside the message.",
"type": "string"
Expand Down Expand Up @@ -2327,6 +2331,10 @@
"key"
],
"type": "object"
},
"userKeyFile": {
"description": "The user key file that contains the recipient user's user key. The user key file needs to be in the same namespace as the AlertmanagerConfig object and accessible by the Prometheus Operator.",
"type": "string"
}
},
"type": "object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,10 @@
],
type: 'object',
},
tokenFile: {
description: "The token file that contains the registered application's API token, see https://pushover.net/apps. The token file needs to be in the same namespace as the AlertmanagerConfig object and accessible by the Prometheus Operator.",
type: 'string',
},
url: {
description: 'A supplementary URL shown alongside the message.',
type: 'string',
Expand Down Expand Up @@ -2186,6 +2190,10 @@
],
type: 'object',
},
userKeyFile: {
description: "The user key file that contains the recipient user's user key. The user key file needs to be in the same namespace as the AlertmanagerConfig object and accessible by the Prometheus Operator.",
type: 'string',
},
},
type: 'object',
},
Expand Down
25 changes: 25 additions & 0 deletions pkg/alertmanager/amcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,31 @@ func (pdc *pagerdutyConfig) sanitize(amVersion semver.Version, logger log.Logger
}

func (poc *pushoverConfig) sanitize(amVersion semver.Version, logger log.Logger) error {
lessThanV0_26 := amVersion.LT(semver.MustParse("0.26.0"))

if poc.UserKeyFile != "" && lessThanV0_26 {
msg := "'use_key_file' supported in Alertmanager >= 0.26.0 only - dropping field from pushover config"
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
level.Warn(logger).Log("msg", msg, "current_version", amVersion.String())
poc.UserKeyFile = ""
}

if poc.TokenFile != "" && lessThanV0_26 {
msg := "'token_file' supported in Alertmanager >= 0.26.0 only - dropping field from pushover config"
level.Warn(logger).Log("msg", msg, "current_version", amVersion.String())
poc.TokenFile = ""
}

if poc.UserKey != "" && poc.UserKeyFile != "" {
msg := "'user_key' and 'user_key_file' are mutually exclusive for pushover config - 'user_key' has taken precedence"
level.Warn(logger).Log("msg", msg)
poc.UserKeyFile = ""
}

if poc.Token != "" && poc.TokenFile != "" {
msg := "'token' and 'token_file' are mutually exclusive for pushover config - 'token' has taken precedence"
level.Warn(logger).Log("msg", msg)
poc.TokenFile = ""
}
return poc.HTTPConfig.sanitize(amVersion, logger)
}

Expand Down
59 changes: 59 additions & 0 deletions pkg/alertmanager/amcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2759,7 +2759,66 @@ func TestTimeInterval(t *testing.T) {
})
}
}
func TestSanitizePushoverConfig(t *testing.T) {
logger := log.NewNopLogger()

for _, tc := range []struct {
name string
againstVersion semver.Version
in *alertmanagerConfig
expect alertmanagerConfig
expectErr bool
}{
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
{
name: "Test pushover use_key_file/token_file takes precedence in pushover config",
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
againstVersion: semver.Version{Major: 0, Minor: 26},
in: &alertmanagerConfig{
Receivers: []*receiver{
{
PushoverConfigs: []*pushoverConfig{
{
UserKey: "foo",
UserKeyFile: "/path/use_key_file",
Token: "bar",
TokenFile: "/path/token_file",
},
},
},
},
},
expect: alertmanagerConfig{
Receivers: []*receiver{
{
PushoverConfigs: []*pushoverConfig{
{
UserKey: "foo",
UserKeyFile: "",
Token: "bar",
TokenFile: "",
},
},
},
},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
err := tc.in.sanitize(tc.againstVersion, logger)
if tc.expectErr {
if err == nil {
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
t.Fatal("expected error but got none")
}
return
}

if err != nil {
t.Fatalf("expected no error but got: %q", err)
}

require.Equal(t, tc.expect, *tc.in)
})
}
}
func TestSanitizeEmailConfig(t *testing.T) {
logger := log.NewNopLogger()

Expand Down
2 changes: 2 additions & 0 deletions pkg/alertmanager/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ type pushoverConfig struct {
VSendResolved *bool `yaml:"send_resolved,omitempty" json:"send_resolved,omitempty"`
HTTPConfig *httpClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
UserKey string `yaml:"user_key,omitempty" json:"user_key,omitempty"`
UserKeyFile string `yaml:"user_key_file,omitempty" json:"user_key_file,omitempty"`
Token string `yaml:"token,omitempty" json:"token,omitempty"`
TokenFile string `yaml:"token_file,omitempty" json:"token_file,omitempty"`
Title string `yaml:"title,omitempty" json:"title,omitempty"`
Message string `yaml:"message,omitempty" json:"message,omitempty"`
URL string `yaml:"url,omitempty" json:"url,omitempty"`
Expand Down
12 changes: 10 additions & 2 deletions pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,21 @@ type PushoverConfig struct {
// The secret's key that contains the recipient user's user key.
// The secret needs to be in the same namespace as the AlertmanagerConfig
// object and accessible by the Prometheus Operator.
// +kubebuilder:validation:Required
UserKey *v1.SecretKeySelector `json:"userKey,omitempty"`
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
// The user key file that contains the recipient user's user key.
// The user key file needs to be in the same namespace as the AlertmanagerConfig
// object and accessible by the Prometheus Operator.
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
// +optional
UserKeyFile string `json:"userKeyFile,omitempty"`
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
// The secret's key that contains the registered application's API token, see https://pushover.net/apps.
// The secret needs to be in the same namespace as the AlertmanagerConfig
// object and accessible by the Prometheus Operator.
// +kubebuilder:validation:Required
Token *v1.SecretKeySelector `json:"token,omitempty"`
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
// The token file that contains the registered application's API token, see https://pushover.net/apps.
// The token file needs to be in the same namespace as the AlertmanagerConfig
// object and accessible by the Prometheus Operator.
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
// +optional
TokenFile string `json:"tokenFile,omitempty"`
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
// Notification title.
// +optional
Title string `json:"title,omitempty"`
Expand Down
12 changes: 10 additions & 2 deletions pkg/apis/monitoring/v1beta1/alertmanager_config_types.go
dongjiang1989 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,21 @@ type PushoverConfig struct {
// The secret's key that contains the recipient user's user key.
// The secret needs to be in the same namespace as the AlertmanagerConfig
// object and accessible by the Prometheus Operator.
// +kubebuilder:validation:Required
UserKey *SecretKeySelector `json:"userKey,omitempty"`
// The user key file that contains the recipient user's user key.
// The user key file needs to be in the same namespace as the AlertmanagerConfig
// object and accessible by the Prometheus Operator.
// +optional
UserKeyFile string `json:"userKeyFile,omitempty"`
// The secret's key that contains the registered application's API token, see https://pushover.net/apps.
// The secret needs to be in the same namespace as the AlertmanagerConfig
// object and accessible by the Prometheus Operator.
// +kubebuilder:validation:Required
Token *SecretKeySelector `json:"token,omitempty"`
// The token file that contains the registered application's API token, see https://pushover.net/apps.
// The token file needs to be in the same namespace as the AlertmanagerConfig
// object and accessible by the Prometheus Operator.
// +optional
TokenFile string `json:"tokenFile,omitempty"`
// Notification title.
// +optional
Title string `json:"title,omitempty"`
Expand Down