Skip to content

Add topologySpreadConstraints configuration to pod spec.#2530

Open
laiminhtrung1997 wants to merge 15 commits intozalando:masterfrom
laiminhtrung1997:add-topologySpreadConstraints
Open

Add topologySpreadConstraints configuration to pod spec.#2530
laiminhtrung1997 wants to merge 15 commits intozalando:masterfrom
laiminhtrung1997:add-topologySpreadConstraints

Conversation

@laiminhtrung1997
Copy link
Contributor

@laiminhtrung1997 laiminhtrung1997 commented Feb 4, 2024

Dear all,

I think we should configure topologySpreadConstraints to pod spec so these pods can spread zones for high availability.

Could someone review it, please? Thank you very much.

Best regards.

@laiminhtrung1997 laiminhtrung1997 force-pushed the add-topologySpreadConstraints branch 2 times, most recently from b948c94 to 44fcb1f Compare February 4, 2024 16:16
@FxKu FxKu added this to the 2.0 milestone Feb 13, 2024
@monotek
Copy link

monotek commented May 16, 2024

We need that feature too.

@FxKu FxKu modified the milestones: 2.0, 1.13.0 May 24, 2024
}
if !reflect.DeepEqual(c.Statefulset.Spec.Template.Spec.TopologySpreadConstraints, statefulSet.Spec.Template.Spec.TopologySpreadConstraints) {
needsReplace = true
needsRollUpdate = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this really need to trigger a rolling update of pods executed by operator? Will not K8s take care of it then once the statefulset is replaced?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm good point. Maybe we can leave as is for now. With rolling update we make sure pods immediately adhere the new constraints.

InitContainersOld []v1.Container `json:"init_containers,omitempty"`
PodPriorityClassNameOld string `json:"pod_priority_class_name,omitempty"`

TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when introducing new fields to the api you have to update the CRDs, too. Unfortunately, we don't use a modern framework where this can be generated and you have to the manifests and in go code.

Plus, you need to run code generation -> ./hack/update-codegen.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated.

false,
"",
false,
[]v1.TopologySpreadConstraint{},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atm we reuse configured tolerations also for logical backup so I guess we can do the same with constraints

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I got it.

return podAntiAffinity
}

func generateTopologySpreadConstraints(labels labels.Set, topologySpreadConstraintObjs []v1.TopologySpreadConstraint) []v1.TopologySpreadConstraint {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would like to see a unit test for this function :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a unit test for this function.

@FxKu
Copy link
Member

FxKu commented Jun 26, 2024

Can you also write an e2e test that tests that the constraints work as expected, please?

@FxKu FxKu modified the milestones: 1.13.0, 1.14.0 Jun 26, 2024
@laiminhtrung1997
Copy link
Contributor Author

Can you also write an e2e test that tests that the constraints work as expected, please?

Dear @FxKu
Thanks so much for your comments, I haven't written the UT or e2e test many, but I'll try my best. I'll mark it ready and let you know when I fixed the comments.
Best regards.

@laiminhtrung1997 laiminhtrung1997 force-pushed the add-topologySpreadConstraints branch 8 times, most recently from 530f847 to 18023cb Compare July 7, 2024 06:56
@laiminhtrung1997 laiminhtrung1997 requested a review from FxKu October 19, 2025 08:02
@laiminhtrung1997
Copy link
Contributor Author

Can you please provide

  1. an example in the complete manifest (somewhere here)
  2. support in helm chart
  3. add documentation behind this paragraph

Dear @FxKu
I completed the requests above. Please review it.

@zalando-robot
Copy link

Cannot start a pipeline due to:

No accountable user for this pipeline: no Zalando employee associated to this GitHub username

Click on pipeline status check Details link below for more information.

@laiminhtrung1997 laiminhtrung1997 force-pushed the add-topologySpreadConstraints branch from fb8fb84 to c6f58ef Compare January 9, 2026 05:40
@zalando-robot
Copy link

Cannot start a pipeline due to:

No accountable user for this pipeline: no Zalando employee associated to this GitHub username

Click on pipeline status check Details link below for more information.

1 similar comment
@zalando-robot
Copy link

Cannot start a pipeline due to:

No accountable user for this pipeline: no Zalando employee associated to this GitHub username

Click on pipeline status check Details link below for more information.

@laiminhtrung1997 laiminhtrung1997 force-pushed the add-topologySpreadConstraints branch from ebcd892 to 1312388 Compare January 26, 2026 13:42
@zalando-robot
Copy link

Cannot start a pipeline due to:

No accountable user for this pipeline: no Zalando employee associated to this GitHub username

Click on pipeline status check Details link below for more information.

2 similar comments
@zalando-robot
Copy link

Cannot start a pipeline due to:

No accountable user for this pipeline: no Zalando employee associated to this GitHub username

Click on pipeline status check Details link below for more information.

@zalando-robot
Copy link

Cannot start a pipeline due to:

No accountable user for this pipeline: no Zalando employee associated to this GitHub username

Click on pipeline status check Details link below for more information.

@laiminhtrung1997 laiminhtrung1997 force-pushed the add-topologySpreadConstraints branch from bb47325 to b824a6f Compare January 30, 2026 14:49
@zalando-robot
Copy link

Cannot start a pipeline due to:

No accountable user for this pipeline: no Zalando employee associated to this GitHub username

Click on pipeline status check Details link below for more information.

@zalando-robot
Copy link

Cannot start a pipeline due to:

No accountable user for this pipeline: no Zalando employee associated to this GitHub username

Click on pipeline status check Details link below for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Open Questions

Development

Successfully merging this pull request may close these issues.

4 participants