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 7be0b56
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions Documentation/api.md
Expand Up @@ -451,6 +451,7 @@ The `PrometheusRestrictedConfig` resource defines the settings for the Prometheu
| retention | string | Defines the duration for which Prometheus retains data. This definition must be specified using the following regular expression pattern: `[0-9]+(ms\|s\|m\|h\|d\|w\|y)` (ms = milliseconds, s= seconds,m = minutes, h = hours, d = days, w = weeks, y = years). The default value is `15d`. |
| retentionSize | string | Defines the maximum amount of disk space used by data blocks plus the write-ahead log (WAL). Supported values are `B`, `KB`, `KiB`, `MB`, `MiB`, `GB`, `GiB`, `TB`, `TiB`, `PB`, `PiB`, `EB`, and `EiB`. The default value is `nil`. |
| 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 Prometheus. Use this setting to configure the storage class and size of a volume. |

[Back to TOC](#table-of-contents)
Expand Down
Expand Up @@ -48,6 +48,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 Prometheus. Use this setting to configure the storage class and size of a volume.

|===
Expand Down
5 changes: 5 additions & 0 deletions pkg/manifests/manifests.go
Expand Up @@ -1705,6 +1705,11 @@ func (f *Factory) PrometheusUserWorkload(grpcTLS *v1.Secret, trustedCABundleCM *
p.Spec.Tolerations = f.config.UserWorkloadConfiguration.Prometheus.Tolerations
}

if len(f.config.UserWorkloadConfiguration.Prometheus.TopologySpreadConstraints) > 0 {
p.Spec.TopologySpreadConstraints =
f.config.UserWorkloadConfiguration.Prometheus.TopologySpreadConstraints
}

if f.config.UserWorkloadConfiguration.Prometheus.ExternalLabels != nil {
p.Spec.ExternalLabels = f.config.UserWorkloadConfiguration.Prometheus.ExternalLabels
}
Expand Down
34 changes: 34 additions & 0 deletions pkg/manifests/manifests_test.go
Expand Up @@ -1608,6 +1608,40 @@ ingress:
}
}

func TestPrometheusUserWorkloadConfiguration(t *testing.T) {
c := NewDefaultConfig()

uwc, err := NewUserConfigFromString(`prometheus:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: type
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
foo: bar`)

c.UserWorkloadConfiguration = uwc
if err != nil {
t.Fatal(err)
}
f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", c, defaultInfrastructureReader(), &fakeProxyReader{}, NewAssets(assetsPath), &APIServerConfig{}, &configv1.Console{})
p, err := f.PrometheusUserWorkload(
&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
)
if err != nil {
t.Fatal(err)
}

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

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

func TestPrometheusQueryLogFileConfig(t *testing.T) {
for _, tc := range []struct {
name string
Expand Down
2 changes: 2 additions & 0 deletions pkg/manifests/types.go
Expand Up @@ -586,6 +586,8 @@ type PrometheusRestrictedConfig struct {
RetentionSize string `json:"retentionSize,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 Prometheus. Use this setting to
// configure the storage class and size of a volume.
VolumeClaimTemplate *monv1.EmbeddedPersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"`
Expand Down

0 comments on commit 7be0b56

Please sign in to comment.