-
Notifications
You must be signed in to change notification settings - Fork 75
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
Extend ability to set topologySpreadConstraints to all component workloads #589
base: main
Are you sure you want to change the base?
Conversation
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.
the operator-latest.yaml
file has to be updated with the latest CRD too. Additionally, a follow-up PR will have to be made on the vitess repository to update the given operator.yaml
file in the examples.
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.
Thanks, @relu ! It looks good to me. I only had a few minor questions and suggestions. I can come back to this quickly when you have a chance to respond.
Thanks again!
if tsc.MinDomains != nil { | ||
minDomainsSeconds = fmt.Sprint(*tsc.MinDomains) | ||
} | ||
writeStringHash(h, minDomainsSeconds) |
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 tsc.MinDomains != nil { | |
minDomainsSeconds = fmt.Sprint(*tsc.MinDomains) | |
} | |
writeStringHash(h, minDomainsSeconds) | |
if tsc.MinDomains != nil { | |
writeStringHash(h, string(*tsc.MinDomains)) | |
} |
@@ -0,0 +1,64 @@ | |||
/* | |||
Copyright 2020 PlanetScale Inc. |
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.
We should use 2024 for new files.
srcMap, srcErr := metav1.LabelSelectorAsMap(srcObj.LabelSelector) | ||
if srcErr != nil { | ||
// There is no return of error for this function | ||
// or its callers, which makes this a bit of a hack | ||
srcMap = map[string]string{} | ||
} | ||
// If this item is already there, update it. | ||
for dstIndex := range *dst { | ||
dstObj := &(*dst)[dstIndex] | ||
dstMap, dstErr := metav1.LabelSelectorAsMap(dstObj.LabelSelector) | ||
if dstErr != nil { | ||
dstMap = map[string]string{} | ||
} | ||
if reflect.DeepEqual(dstMap, srcMap) { |
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'm not sure why this code was added, so also not sure that this is safe. Reads to me like this was primarily about handling nils and invalid/unexpected data which we lose here. Can you please explain the reasoning?
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.
The way this was intended to work was that the list of corev1.TopologySpreadConstraint
items would be matched exclusively on the labelSelector
, causing any previously existing items having the same labelSelector
to be overridden.
This behavior doesn't make sense because the labelSelector
will most likely be the same across all topology spread constraint items. Instead, we should only append to the list and not touch any existing values.
I've simplified the code a bit and added some test examples.
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 think it's reasonable to do a DeepEqual here as it will catch any potential change to the Topology Spread Constraints.
However, I am a bit afraid of the performance implication that reflect.DeepEqual
brings. Since we are calling it in a nested loop, if the user defines many constraints on their vttablet or etcd pods we might be left with a longer update. To avoid this potential issue, could we create a method to compare two constraints?
Hey @relu! Are you still working on this? It would be nice to include this in the upcoming |
…kloads Signed-off-by: Aurel Canciu <[email protected]>
Signed-off-by: Aurel Canciu <[email protected]>
Signed-off-by: Aurel Canciu <[email protected]>
Signed-off-by: Aurel Canciu <[email protected]>
Signed-off-by: Aurel Canciu <[email protected]>
30ee721
to
ad5616b
Compare
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.
Besides the comments I have left it looks good to me. Do you have a manual E2E test for this, if so, could you share the script and output with us?
Also, please open a follow-up PR on vitessio/vitess
to update the operator.yaml
with what you changed on this PR in operator-latest.yaml
.
@@ -1227,6 +1227,20 @@ ServiceOverrides | |||
<p>Tolerations allow you to schedule pods onto nodes with matching taints.</p> | |||
</td> | |||
</tr> | |||
<tr> | |||
<td> | |||
<code>topologySpreadConstraints</code></br> |
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.
The way we generate documentation changed in #625. We no longer use </br>
as it can break in Markdown. Do you mind merging main
onto your branch and re-generating the docs?
writeStringHash(h, strings.Join(tsc.MatchLabelKeys, "")) | ||
if tsc.MinDomains != nil { | ||
writeStringHash(h, string(*tsc.MinDomains)) | ||
} | ||
if tsc.NodeAffinityPolicy != nil { | ||
writeStringHash(h, string(*tsc.NodeAffinityPolicy)) | ||
} | ||
if tsc.NodeTaintsPolicy != nil { | ||
writeStringHash(h, string(*tsc.NodeTaintsPolicy)) | ||
} |
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.
That is a good catch. I am guessing the hash we were previously computing were not encapsulating all the information we could add?
if nilHash == zeroHash { | ||
t.Errorf("nilHash = zeroHash = %v; expected different values", nilHash) | ||
} |
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.
Instead of checking the equality manually we should use require.NotEqual
. It is something we have adopted a while ago on vitessio/vitess
. We should start doing the same for new tests on the operator. Same applies to TestTopologySpreadConstraintNodeAffinityPolicysNil
and TestTopologySpreadConstraintNodeTaintsPolicysNil
.
} | ||
|
||
func TestTopologySpreadConstraintNodeAffinityPolicysNil(t *testing.T) { | ||
// Make sure nil is distinguishable from 0. |
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.
The comment does not entirely make sense here, same for the following test
srcMap, srcErr := metav1.LabelSelectorAsMap(srcObj.LabelSelector) | ||
if srcErr != nil { | ||
// There is no return of error for this function | ||
// or its callers, which makes this a bit of a hack | ||
srcMap = map[string]string{} | ||
} | ||
// If this item is already there, update it. | ||
for dstIndex := range *dst { | ||
dstObj := &(*dst)[dstIndex] | ||
dstMap, dstErr := metav1.LabelSelectorAsMap(dstObj.LabelSelector) | ||
if dstErr != nil { | ||
dstMap = map[string]string{} | ||
} | ||
if reflect.DeepEqual(dstMap, srcMap) { |
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 think it's reasonable to do a DeepEqual here as it will catch any potential change to the Topology Spread Constraints.
However, I am a bit afraid of the performance implication that reflect.DeepEqual
brings. Since we are calling it in a nested loop, if the user defines many constraints on their vttablet or etcd pods we might be left with a longer update. To avoid this potential issue, could we create a method to compare two constraints?
This should allow users to configure topologySpreadhConstraints for all operator-managed workloads.