Skip to content

Commit

Permalink
Add topology spread constrains
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Fernandez <mariofer@redhat.com>
  • Loading branch information
marioferh committed Jul 6, 2023
1 parent 2016486 commit 1945c89
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions Documentation/api.md
Expand Up @@ -111,6 +111,7 @@ The `AlertmanagerUserWorkloadConfig` resource defines the settings for the Alert
| secrets | []string | Defines a list of secrets that need to be mounted into the Alertmanager. The secrets must reside within the same namespace as the Alertmanager object. They will be added as volumes named secret-<secret-name> and mounted at /etc/alertmanager/secrets/<secret-name> within the 'alertmanager' container of the Alertmanager Pods. |
| nodeSelector | map[string]string | Defines the nodes on which the pods are scheduled. |
| tolerations | [][v1.Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#toleration-v1-core) | Defines tolerations for the pods. |
| topologySpreadConstraints | []v1.TopologySpreadConstraint | Defines a pod's topology spread constraints. |
| volumeClaimTemplate | *[monv1.EmbeddedPersistentVolumeClaim](https://github.com/prometheus-operator/prometheus-operator/blob/v0.66.0/Documentation/api.md#embeddedpersistentvolumeclaim) | Defines persistent storage for Alertmanager. Use this setting to configure the persistent volume claim, including storage class, volume size and name. |

[Back to TOC](#table-of-contents)
Expand Down
Expand Up @@ -32,6 +32,8 @@ Appears in: link:userworkloadconfiguration.adoc[UserWorkloadConfiguration]

|tolerations|[]v1.Toleration|Defines tolerations for the pods.

|topologySpreadConstraints|[]v1.TopologySpreadConstraint|Defines a pod's topology spread constraints.

|volumeClaimTemplate|*monv1.EmbeddedPersistentVolumeClaim|Defines persistent storage for Alertmanager. Use this setting to configure the persistent volume claim, including storage class, volume size and name.

|===
Expand Down
5 changes: 5 additions & 0 deletions pkg/manifests/manifests.go
Expand Up @@ -519,6 +519,11 @@ func (f *Factory) AlertmanagerUserWorkload(trustedCABundleCM *v1.ConfigMap) (*mo
a.Spec.Tolerations = alertmanagerConfig.Tolerations
}

if len(alertmanagerConfig.TopologySpreadConstraints) > 0 {
a.Spec.TopologySpreadConstraints =
alertmanagerConfig.TopologySpreadConstraints
}

for i, c := range a.Spec.Containers {
switch c.Name {
case "alertmanager-proxy", "tenancy-proxy", "kube-rbac-proxy-metric":
Expand Down
23 changes: 22 additions & 1 deletion pkg/manifests/manifests_test.go
Expand Up @@ -2824,7 +2824,20 @@ ingress:

func TestAlertManagerUserWorkloadSecretsConfiguration(t *testing.T) {
c := NewDefaultConfig()
c.UserWorkloadConfiguration.Alertmanager.Secrets = []string{"test-secret", "slack-api-token"}
uwc, err := NewUserConfigFromString(`alertmanager:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: type
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
foo: bar
secrets:
- test-secret
- slack-api-token
`)

c.UserWorkloadConfiguration = uwc

f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", c, defaultInfrastructureReader(), &fakeProxyReader{}, NewAssets(assetsPath), &APIServerConfig{}, &configv1.Console{})
a, err := f.AlertmanagerUserWorkload(
Expand All @@ -2842,6 +2855,14 @@ func TestAlertManagerUserWorkloadSecretsConfiguration(t *testing.T) {
if !slices.Contains(a.Spec.Secrets, "slack-api-token") {
t.Fatal("Alertmanager secret `slack-api-token` is not configured correctly")
}

if a.Spec.TopologySpreadConstraints[0].MaxSkew != 1 {
t.Fatal("Alertmanager UWM spread contraints MaxSkew not configured correctly")
}

if a.Spec.TopologySpreadConstraints[0].WhenUnsatisfiable != "DoNotSchedule" {
t.Fatal("Alertmanager UWM spread contraints WhenUnsatisfiable not configured correctly")
}
}

func TestNodeExporter(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/manifests/types.go
Expand Up @@ -500,6 +500,8 @@ type AlertmanagerUserWorkloadConfig struct {
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Defines tolerations for the pods.
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
// Defines a pod's topology spread constraints.
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
// Defines persistent storage for Alertmanager. Use this setting to
// configure the persistent volume claim, including storage class,
// volume size and name.
Expand Down

0 comments on commit 1945c89

Please sign in to comment.