-
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
XPreserveUnknownFields: util.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.
same here with the XPreserveUnknownFields
. Yes there are other fields where are doing it like this, but lets get it right for new additions. I know, it's tedious to reflect the full schema because we don use a framework like kubeBulder. But it should be the trade-off for contributors when they go the "easy way" with allowing full specs in our manifest over custom stripped-down designs better suitable for end users.
@laiminhtrung1997 have you tested how topology spread constraints behave together with specified nodeAffinity in the manifest and globally configured pod anti affinity rules. How easy is it to create a scenario where they contradict themselves and lead to scheduling problems? Should one be used over the other? Maybe @monotek can answer this, too? |
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. |
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.