From 991bf69a4a362a0ded7ef1a337b22a06fea4afe1 Mon Sep 17 00:00:00 2001 From: Mario Fernandez Date: Wed, 5 Jul 2023 13:21:43 +0200 Subject: [PATCH] Add topology spread constrains Signed-off-by: Mario Fernandez --- Documentation/api.md | 1 + .../modules/thanosquerierconfig.adoc | 2 ++ pkg/manifests/manifests.go | 4 +++ pkg/manifests/manifests_test.go | 31 ++++++++++++++++++- pkg/manifests/types.go | 2 ++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Documentation/api.md b/Documentation/api.md index 5040545f5c..aed093e93a 100644 --- a/Documentation/api.md +++ b/Documentation/api.md @@ -542,6 +542,7 @@ The `ThanosQuerierConfig` resource defines settings for the Thanos Querier compo | nodeSelector | map[string]string | Defines the nodes on which the pods are scheduled. | | resources | *[v1.ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#resourcerequirements-v1-core) | Defines resource requests and limits for the Thanos Querier container. | | 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. | [Back to TOC](#table-of-contents) diff --git a/Documentation/openshiftdocs/modules/thanosquerierconfig.adoc b/Documentation/openshiftdocs/modules/thanosquerierconfig.adoc index fc418a5c52..d11850f8ac 100644 --- a/Documentation/openshiftdocs/modules/thanosquerierconfig.adoc +++ b/Documentation/openshiftdocs/modules/thanosquerierconfig.adoc @@ -30,6 +30,8 @@ Appears in: link:clustermonitoringconfiguration.adoc[ClusterMonitoringConfigurat |tolerations|[]v1.Toleration|Defines tolerations for the pods. +|topologySpreadConstraints|[]v1.TopologySpreadConstraint|Defines a pod's topology spread constraints. + |=== link:../index.adoc[Back to TOC] diff --git a/pkg/manifests/manifests.go b/pkg/manifests/manifests.go index c792cba6bf..4249be5da3 100644 --- a/pkg/manifests/manifests.go +++ b/pkg/manifests/manifests.go @@ -2799,6 +2799,10 @@ func (f *Factory) ThanosQuerierDeployment(grpcTLS *v1.Secret, enableUserWorkload if len(f.config.ClusterMonitoringConfiguration.ThanosQuerierConfig.Tolerations) > 0 { d.Spec.Template.Spec.Tolerations = f.config.ClusterMonitoringConfiguration.ThanosQuerierConfig.Tolerations } + if len(f.config.ClusterMonitoringConfiguration.ThanosQuerierConfig.TopologySpreadConstraints) > 0 { + d.Spec.Template.Spec.TopologySpreadConstraints = + f.config.ClusterMonitoringConfiguration.ThanosQuerierConfig.TopologySpreadConstraints + } return d, nil } diff --git a/pkg/manifests/manifests_test.go b/pkg/manifests/manifests_test.go index a479511aa8..5ff138649a 100644 --- a/pkg/manifests/manifests_test.go +++ b/pkg/manifests/manifests_test.go @@ -3348,7 +3348,14 @@ func TestThanosQuerierConfiguration(t *testing.T) { memory: 4Mi logLevel: debug enableRequestLogging: true - enableCORS: true`, false) + enableCORS: true + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: type + whenUnsatisfiable: DoNotSchedule + labelSelector: + matchLabels: + foo: bar`, false) if err != nil { t.Fatal(err) @@ -3391,6 +3398,28 @@ func TestThanosQuerierConfiguration(t *testing.T) { }) } + for _, tc := range []struct { + name string + want, got interface{} + }{ + { + name: "Topology", + want: []v1.TopologySpreadConstraint{ + { + MaxSkew: 1, + WhenUnsatisfiable: "DoNotSchedule", + }, + }, + got: d.Spec.Template.Spec.TopologySpreadConstraints[0], + }, + } { + t.Run(tc.name, func(t *testing.T) { + if reflect.DeepEqual(tc.got, tc.want) { + t.Errorf("thanos-querier topology spread contraints WhenUnsatisfiable not configured correctly: want %+v, got %+v", tc.want, tc.got) + } + }) + } + kubeRbacProxyTLSCipherSuitesArg := "" kubeRbacProxyMinTLSVersionArg := "" for _, c := range d.Spec.Template.Spec.Containers { diff --git a/pkg/manifests/types.go b/pkg/manifests/types.go index 356690fcd8..2d098abf26 100644 --- a/pkg/manifests/types.go +++ b/pkg/manifests/types.go @@ -270,6 +270,8 @@ type ThanosQuerierConfig struct { Resources *v1.ResourceRequirements `json:"resources,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"` } // The `NodeExporterConfig` resource defines settings for the `node-exporter` agent.