-
Notifications
You must be signed in to change notification settings - Fork 1k
Add topologySpreadConstraints configuration to pod spec. #2530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add topologySpreadConstraints configuration to pod spec. #2530
Conversation
b948c94
to
44fcb1f
Compare
We need that feature too. |
} | ||
if !reflect.DeepEqual(c.Statefulset.Spec.Template.Spec.TopologySpreadConstraints, statefulSet.Spec.Template.Spec.TopologySpreadConstraints) { | ||
needsReplace = true | ||
needsRollUpdate = true |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but is this wrong too?
https://github.com/zalando/postgres-operator/blob/master/pkg/cluster/cluster.go#L472
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated.
pkg/cluster/k8sres.go
Outdated
false, | ||
"", | ||
false, | ||
[]v1.TopologySpreadConstraint{}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I got it.
pkg/cluster/k8sres.go
Outdated
return podAntiAffinity | ||
} | ||
|
||
func generateTopologySpreadConstraints(labels labels.Set, topologySpreadConstraintObjs []v1.TopologySpreadConstraint) []v1.TopologySpreadConstraint { |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
Can you also write an e2e test that tests that the constraints work as expected, please? |
530f847
to
18023cb
Compare
3e99f92
to
794f6db
Compare
Advice for the future: Don't force push and squash your commits in the middle of a review. Now it's super hard for me to see what feedback you've reflected and I have to review everything again 😞 |
It is note. I am truly sorry for this. It will not happen again. |
Currently, I have configured the operator using topologySpreadConstraints and Affinity.PodAntiAffinity together. My expectation is that the pods are always scheduled in different nodes and availability zones. This is my manifest for them.
Do you want me to put that scenario in the e2e test? |
Excuse me @FxKu Is there any news on this? |
27f69f5
to
b592ce8
Compare
adfafef
to
16caf11
Compare
Hi @FxKu I have fixed all your comments. Please review the PR again. I look forward to hearing from you. Best regards. |
16caf11
to
dbb6aaa
Compare
dbb6aaa
to
a40ba6e
Compare
Cannot start a pipeline due to:
Click on pipeline status check Details link below for more information. |
if len(topologySpreadConstraintsSpec) > 0 { | ||
podSpec.TopologySpreadConstraints = generateTopologySpreadConstraints(labels, topologySpreadConstraintsSpec) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(topologySpreadConstraintsSpec) > 0 { | |
podSpec.TopologySpreadConstraints = generateTopologySpreadConstraints(labels, topologySpreadConstraintsSpec) | |
} | |
podSpec.TopologySpreadConstraints = generateTopologySpreadConstraints(labels, topologySpreadConstraintsSpec) |
you only do a range loop inside the function so this len check is not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated it.
Can you please provide
|
} | ||
} | ||
k8s.api.core_v1.patch_node(master_nodes[0], patch_node_label) | ||
k8s.api.core_v1.patch_node(replica_nodes[0], patch_node_label) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect that the e2e test patches the Postgresql manifest and adds topologySpreadConstraints to then check if the pods spread evenly. But you're only patching the nodes here?
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.