Skip to content

Commit d36d2ca

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

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
@@ -2170,6 +2170,11 @@ func (f *Factory) PrometheusOperatorAdmissionWebhookDeployment() (*appsv1.Deploy
21702170
d.Spec.Template.Spec.Tolerations = f.config.ClusterMonitoringConfiguration.PrometheusOperatorConfig.Tolerations
21712171
}
21722172

2173+
if len(f.config.ClusterMonitoringConfiguration.PrometheusOperatorAdmissionWebhookConfig.TopologySpreadConstraints) > 0 {
2174+
d.Spec.Template.Spec.TopologySpreadConstraints =
2175+
f.config.ClusterMonitoringConfiguration.PrometheusOperatorAdmissionWebhookConfig.TopologySpreadConstraints
2176+
}
2177+
21732178
for i, container := range d.Spec.Template.Spec.Containers {
21742179
switch container.Name {
21752180
case "prometheus-operator-admission-webhook":

pkg/manifests/manifests_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,13 @@ prometheusOperatorAdmissionWebhook:
899899
limits:
900900
cpu: 200m
901901
memory: 200Mi
902+
topologySpreadConstraints:
903+
- maxSkew: 1
904+
topologyKey: type
905+
whenUnsatisfiable: DoNotSchedule
906+
labelSelector:
907+
matchLabels:
908+
foo: bar
902909
`, false)
903910
if err != nil {
904911
t.Fatal(err)
@@ -910,6 +917,14 @@ prometheusOperatorAdmissionWebhook:
910917
t.Fatal(err)
911918
}
912919

920+
if d.Spec.Template.Spec.TopologySpreadConstraints[0].MaxSkew != 1 {
921+
t.Fatal("prometheus-operator-admission-webhook topology spread constraints MaxSkew not configured correctly")
922+
}
923+
924+
if d.Spec.Template.Spec.TopologySpreadConstraints[0].WhenUnsatisfiable != "DoNotSchedule" {
925+
t.Fatal("prometheus-operator-admission-webhook topology spread constraints WhenUnsatisfiable not configured correctly")
926+
}
927+
913928
for _, container := range d.Spec.Template.Spec.Containers {
914929
switch container.Name {
915930
case "prometheus-operator-admission-webhook":

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)