Skip to content

Commit f43c87e

Browse files
Merge pull request #1624 from jan--f/mon-1261
MON-1261: exposing topology spread constraints through config
2 parents 764df12 + 9497272 commit f43c87e

File tree

4 files changed

+76
-8
lines changed

4 files changed

+76
-8
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Note: This CHANGELOG is only for the monitoring team to track all monitoring related changes. Please see OpenShift release notes for official changes.
22

3+
## 4.12
4+
- [#1624](https://github.com/openshift/cluster-monitoring-operator/pull/1624) Add option to specify TopologySpreadConstraints for Prometheus, Alertmanager, and ThanosRuler.
5+
36
## 4.11
47
- [#1652](https://github.com/openshift/cluster-monitoring-operator/pull/1652) Double scrape interval for all CMO controlled ServiceMonitors on single node deployments
58
- [#1567](https://github.com/openshift/cluster-monitoring-operator/pull/1567) Enable validating webhook for AlertmanagerConfig custom resources

pkg/manifests/config.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ type PrometheusK8sConfig struct {
205205
* 2. a value in Prometheus size format, e.g. "64MB"
206206
* 3. string "automatic", which means the limit will be automatically calculated based on cluster capacity.
207207
*/
208-
EnforcedBodySizeLimit string `json:"enforcedBodySizeLimit,omitempty"`
208+
EnforcedBodySizeLimit string `json:"enforcedBodySizeLimit,omitempty"`
209+
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints"`
209210
}
210211

211212
type AdditionalAlertmanagerConfig struct {
@@ -247,20 +248,22 @@ type AlertmanagerMainConfig struct {
247248
Tolerations []v1.Toleration `json:"tolerations"`
248249
Resources *v1.ResourceRequirements `json:"resources"`
249250
VolumeClaimTemplate *monv1.EmbeddedPersistentVolumeClaim `json:"volumeClaimTemplate"`
251+
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints"`
250252
}
251253

252254
func (a AlertmanagerMainConfig) IsEnabled() bool {
253255
return a.Enabled == nil || *a.Enabled
254256
}
255257

256258
type ThanosRulerConfig struct {
257-
LogLevel string `json:"logLevel"`
258-
NodeSelector map[string]string `json:"nodeSelector"`
259-
Retention string `json:"retention"`
260-
Tolerations []v1.Toleration `json:"tolerations"`
261-
Resources *v1.ResourceRequirements `json:"resources"`
262-
VolumeClaimTemplate *monv1.EmbeddedPersistentVolumeClaim `json:"volumeClaimTemplate"`
263-
AlertmanagersConfigs []AdditionalAlertmanagerConfig `json:"additionalAlertmanagerConfigs"`
259+
LogLevel string `json:"logLevel"`
260+
NodeSelector map[string]string `json:"nodeSelector"`
261+
Retention string `json:"retention"`
262+
Tolerations []v1.Toleration `json:"tolerations"`
263+
Resources *v1.ResourceRequirements `json:"resources"`
264+
VolumeClaimTemplate *monv1.EmbeddedPersistentVolumeClaim `json:"volumeClaimTemplate"`
265+
AlertmanagersConfigs []AdditionalAlertmanagerConfig `json:"additionalAlertmanagerConfigs"`
266+
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints"`
264267
}
265268

266269
type ThanosQuerierConfig struct {

pkg/manifests/manifests.go

+14
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,11 @@ func (f *Factory) AlertmanagerMain(trustedCABundleCM *v1.ConfigMap) (*monv1.Aler
676676
a.Spec.Tolerations = f.config.ClusterMonitoringConfiguration.AlertmanagerMainConfig.Tolerations
677677
}
678678

679+
if len(f.config.ClusterMonitoringConfiguration.AlertmanagerMainConfig.TopologySpreadConstraints) > 0 {
680+
a.Spec.TopologySpreadConstraints =
681+
f.config.ClusterMonitoringConfiguration.AlertmanagerMainConfig.TopologySpreadConstraints
682+
}
683+
679684
for i, c := range a.Spec.Containers {
680685
switch c.Name {
681686
case "alertmanager-proxy":
@@ -1650,6 +1655,11 @@ func (f *Factory) PrometheusK8s(grpcTLS *v1.Secret, trustedCABundleCM *v1.Config
16501655
p.Spec.Tolerations = f.config.ClusterMonitoringConfiguration.PrometheusK8sConfig.Tolerations
16511656
}
16521657

1658+
if len(f.config.ClusterMonitoringConfiguration.PrometheusK8sConfig.TopologySpreadConstraints) > 0 {
1659+
p.Spec.TopologySpreadConstraints =
1660+
f.config.ClusterMonitoringConfiguration.PrometheusK8sConfig.TopologySpreadConstraints
1661+
}
1662+
16531663
if f.config.ClusterMonitoringConfiguration.PrometheusK8sConfig.ExternalLabels != nil {
16541664
p.Spec.ExternalLabels = f.config.ClusterMonitoringConfiguration.PrometheusK8sConfig.ExternalLabels
16551665
}
@@ -4058,6 +4068,10 @@ func (f *Factory) ThanosRulerCustomResource(
40584068
t.Spec.Retention = monv1.Duration(f.config.UserWorkloadConfiguration.ThanosRuler.Retention)
40594069
}
40604070

4071+
if len(f.config.UserWorkloadConfiguration.ThanosRuler.TopologySpreadConstraints) > 0 {
4072+
t.Spec.TopologySpreadConstraints = f.config.UserWorkloadConfiguration.ThanosRuler.TopologySpreadConstraints
4073+
}
4074+
40614075
if len(f.config.UserWorkloadConfiguration.ThanosRuler.Tolerations) > 0 {
40624076
t.Spec.Tolerations = f.config.UserWorkloadConfiguration.ThanosRuler.Tolerations
40634077
}

pkg/manifests/manifests_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,13 @@ func TestPrometheusK8sConfiguration(t *testing.T) {
14921492
resources:
14931493
requests:
14941494
storage: 15Gi
1495+
topologySpreadConstraints:
1496+
- maxSkew: 1
1497+
topologyKey: type
1498+
whenUnsatisfiable: DoNotSchedule
1499+
labelSelector:
1500+
matchLabels:
1501+
foo: bar
14951502
resources:
14961503
limits:
14971504
cpu: 200m
@@ -1624,6 +1631,14 @@ ingress:
16241631
t.Fatal("Prometheus toleration effect not configured correctly")
16251632
}
16261633

1634+
if p.Spec.TopologySpreadConstraints[0].MaxSkew != 1 {
1635+
t.Fatal("Prometheus topology spread contraints MaxSkew not configured correctly")
1636+
}
1637+
1638+
if p.Spec.TopologySpreadConstraints[0].WhenUnsatisfiable != "DoNotSchedule" {
1639+
t.Fatal("Prometheus topology spread contraints WhenUnsatisfiable not configured correctly")
1640+
}
1641+
16271642
if p.Spec.ExternalLabels["datacenter"] != "eu-west" {
16281643
t.Fatal("Prometheus external labels are not configured correctly")
16291644
}
@@ -2620,6 +2635,13 @@ func TestAlertmanagerMainConfiguration(t *testing.T) {
26202635
tolerations:
26212636
- effect: PreferNoSchedule
26222637
operator: Exists
2638+
topologySpreadConstraints:
2639+
- maxSkew: 1
2640+
topologyKey: type
2641+
whenUnsatisfiable: DoNotSchedule
2642+
labelSelector:
2643+
matchLabels:
2644+
foo: bar
26232645
resources:
26242646
limits:
26252647
cpu: 20m
@@ -2690,6 +2712,14 @@ ingress:
26902712
t.Fatal("Prometheus toleration effect not configured correctly")
26912713
}
26922714

2715+
if a.Spec.TopologySpreadConstraints[0].MaxSkew != 1 {
2716+
t.Fatal("Alertmanager main topology spread contraints MaxSkew not configured correctly")
2717+
}
2718+
2719+
if a.Spec.TopologySpreadConstraints[0].WhenUnsatisfiable != "DoNotSchedule" {
2720+
t.Fatal("Alertmanager main topology spread contraints WhenUnsatisfiable not configured correctly")
2721+
}
2722+
26932723
storageRequest := a.Spec.Storage.VolumeClaimTemplate.Spec.Resources.Requests[v1.ResourceStorage]
26942724
storageRequestPtr := &storageRequest
26952725
if storageRequestPtr.String() != "10Gi" {
@@ -3287,6 +3317,16 @@ func TestTelemeterConfiguration(t *testing.T) {
32873317

32883318
func TestThanosRulerConfiguration(t *testing.T) {
32893319
c, err := NewConfigFromString(``)
3320+
uwc, err := NewUserConfigFromString(`thanosRuler:
3321+
topologySpreadConstraints:
3322+
- maxSkew: 1
3323+
topologyKey: type
3324+
whenUnsatisfiable: DoNotSchedule
3325+
labelSelector:
3326+
matchLabels:
3327+
foo: bar`)
3328+
3329+
c.UserWorkloadConfiguration = uwc
32903330
if err != nil {
32913331
t.Fatal(err)
32923332
}
@@ -3312,6 +3352,14 @@ func TestThanosRulerConfiguration(t *testing.T) {
33123352
}
33133353
}
33143354
}
3355+
if tr.Spec.TopologySpreadConstraints[0].MaxSkew != 1 {
3356+
t.Fatal("Thanos ruler topology spread contraints MaxSkew not configured correctly")
3357+
}
3358+
3359+
if tr.Spec.TopologySpreadConstraints[0].WhenUnsatisfiable != "DoNotSchedule" {
3360+
t.Fatal("Thanos ruler topology spread contraints WhenUnsatisfiable not configured correctly")
3361+
}
3362+
33153363
}
33163364

33173365
func TestThanosRulerRetentionConfig(t *testing.T) {

0 commit comments

Comments
 (0)