Skip to content

Commit b8635c8

Browse files
committed
add topologySpreadConstraints to admission webhook
Signed-off-by: Mario Fernandez <[email protected]>
1 parent 56a6754 commit b8635c8

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

Documentation/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ The `PrometheusOperatorAdmissionWebhookConfig` resource defines settings for the
448448
| Property | Type | Description |
449449
| -------- | ---- | ----------- |
450450
| resources | *[v1.ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#resourcerequirements-v1-core) | Defines resource requests and limits for the prometheus-operator-admission-webhook container. |
451+
| topologySpreadConstraints | []v1.TopologySpreadConstraint | Defines a pod's topology spread constraints. |
451452

452453
[Back to TOC](#table-of-contents)
453454

Documentation/openshiftdocs/modules/prometheusoperatoradmissionwebhookconfig.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Appears in: link:clustermonitoringconfiguration.adoc[ClusterMonitoringConfigurat
2020
| Property | Type | Description
2121
|resources|*v1.ResourceRequirements|Defines resource requests and limits for the prometheus-operator-admission-webhook container.
2222

23+
|topologySpreadConstraints|[]v1.TopologySpreadConstraint|Defines a pod's topology spread constraints.
24+
2325
|===
2426

2527
link:../index.adoc[Back to TOC]

pkg/manifests/manifests.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,11 @@ func (f *Factory) PrometheusOperatorAdmissionWebhookDeployment() (*appsv1.Deploy
21742174
d.Spec.Template.Spec.Tolerations = f.config.ClusterMonitoringConfiguration.PrometheusOperatorConfig.Tolerations
21752175
}
21762176

2177+
if len(f.config.ClusterMonitoringConfiguration.PrometheusOperatorConfig.TopologySpreadConstraints) > 0 {
2178+
d.Spec.Template.Spec.TopologySpreadConstraints =
2179+
f.config.ClusterMonitoringConfiguration.PrometheusOperatorConfig.TopologySpreadConstraints
2180+
}
2181+
21772182
for i, container := range d.Spec.Template.Spec.Containers {
21782183
switch container.Name {
21792184
case "prometheus-operator-admission-webhook":

pkg/manifests/manifests_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,13 @@ func TestPrometheusOperatorAdmissionWebhookConfiguration(t *testing.T) {
827827
c, err := NewConfigFromString(`prometheusOperator:
828828
nodeSelector:
829829
type: master
830+
topologySpreadConstraints:
831+
- maxSkew: 1
832+
topologyKey: type
833+
whenUnsatisfiable: DoNotSchedule
834+
labelSelector:
835+
matchLabels:
836+
foo: bar
830837
`, false)
831838

832839
c.SetImages(map[string]string{
@@ -851,6 +858,14 @@ func TestPrometheusOperatorAdmissionWebhookConfiguration(t *testing.T) {
851858
t.Fatalf("expected node selector to be master, got %q", got)
852859
}
853860

861+
if d.Spec.Template.Spec.TopologySpreadConstraints[0].MaxSkew != 1 {
862+
t.Fatal("k8s-prometheus-operator topology spread contraints MaxSkew not configured correctly")
863+
}
864+
865+
if d.Spec.Template.Spec.TopologySpreadConstraints[0].WhenUnsatisfiable != "DoNotSchedule" {
866+
t.Fatal("k8s-prometheus-operator topology spread contraints WhenUnsatisfiable not configured correctly")
867+
}
868+
854869
webTLSCipherSuitesArg := ""
855870
webTLSVersionArg := ""
856871
for _, container := range d.Spec.Template.Spec.Containers {

pkg/manifests/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ type ThanosRulerConfig struct {
681681
type PrometheusOperatorAdmissionWebhookConfig struct {
682682
// Defines resource requests and limits for the prometheus-operator-admission-webhook container.
683683
Resources *v1.ResourceRequirements `json:"resources,omitempty"`
684+
// Defines a pod's topology spread constraints.
685+
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
684686
}
685687

686688
// The `MonitoringPluginConfig` resource defines settings for the

0 commit comments

Comments
 (0)