Skip to content

propagate nodeSelector to pod spec#69

Merged
jdheyburn merged 2 commits into
valkey-io:mainfrom
ysqyang:node-selector
Feb 4, 2026
Merged

propagate nodeSelector to pod spec#69
jdheyburn merged 2 commits into
valkey-io:mainfrom
ysqyang:node-selector

Conversation

@ysqyang
Copy link
Copy Markdown
Contributor

@ysqyang ysqyang commented Jan 30, 2026

Issue

Testing in an EKS cluster with 2 values for label topology.kubernetes.io/zone:
Screenshot 2026-01-29 at 6 10 52 PM

Without adding nodeSelector, when applying config/samples/v1alpha1_valkeycluster.yaml, valkey pods were placed on nodes with labels topology.kubernetes.io/zone=us-east-1b and topology.kubernetes.io/zone=us-east-1c:

Screenshot 2026-01-29 at 4 51 43 PM

After adding nodeSelector: topology.kubernetes.io/zone: us-east-1b in the manifest, nodeSelector was successfully applied:
Screenshot 2026-01-29 at 5 27 54 PM

and valkey pods were only placed on nodes with label topology.kubernetes.io/zone=us-east-1b.
Screenshot 2026-01-29 at 4 52 38 PM

If we change the node selector to topology.kubernetes.io/zone: us-east-1a, the pods stayed pending indefinitely because there's no node with this label:
Screenshot 2026-01-29 at 11 16 01 PM

Multiple selectors:
Adding nodeSelector: topology.kubernetes.io/zone: us-east-1b kubernetes.io/hostname: ip-10-9-58-63.ec2.internal in the manifest put all valkey pods on the same node in us-east-1b:
Screenshot 2026-01-31 at 3 43 06 PM

Comment thread internal/controller/deployment.go Outdated
containers := generateContainersDef(cluster)
nodeSelector := cluster.Spec.NodeSelector
if cluster.Spec.Affinity != nil {
nodeSelector = nil
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess you could have both Affinity and a NodeSelector configured at the same time (See note at the end of this section).
I might have missed something, is there a reason for blocking a user to finetune placement by resetting nodeSelector here?

Copy link
Copy Markdown
Contributor Author

@ysqyang ysqyang Jan 31, 2026

Choose a reason for hiding this comment

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

This is just to align with line 67 in https://github.com/valkey-io/valkey-operator/blob/main/api/v1alpha1/valkeycluster_types.go. I'm not sure why we wanted the override in the first place TBH, but that’s probably a discussion for another time.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should remove this logic. A user may specify a nodeSelector, and a podAffinity / podAntiAffinity and not a nodeAffinity. If a user has declared a config we should allow it to propagate and not remove on their behalf.

@ysqyang ysqyang marked this pull request as ready for review January 31, 2026 23:50
@ysqyang
Copy link
Copy Markdown
Contributor Author

ysqyang commented Feb 4, 2026

@jdheyburn Could you kindly review this? Thanks!

Copy link
Copy Markdown
Collaborator

@jdheyburn jdheyburn left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I would rather we did not override the nodeSelector when affinity is set.

If we're worried about conflicts, we can address them in a future release.

Does that sound ok?

Comment thread internal/controller/deployment.go Outdated
containers := generateContainersDef(cluster)
nodeSelector := cluster.Spec.NodeSelector
if cluster.Spec.Affinity != nil {
nodeSelector = nil
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should remove this logic. A user may specify a nodeSelector, and a podAffinity / podAntiAffinity and not a nodeAffinity. If a user has declared a config we should allow it to propagate and not remove on their behalf.

Comment thread internal/controller/deployment_test.go Outdated
d := createClusterDeployment(cluster)

assert.Nil(t, d.Spec.Template.Spec.NodeSelector, "node selector should be nil when affinity set")
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test can be removed once the previous comment is addressed.

Signed-off-by: yang.qiu <yang.qiu@reddit.com>
@ysqyang ysqyang force-pushed the node-selector branch 4 times, most recently from dd42d22 to 19a9c1c Compare February 4, 2026 18:43
Signed-off-by: yang.qiu <yang.qiu@reddit.com>
Copy link
Copy Markdown
Collaborator

@jdheyburn jdheyburn left a comment

Choose a reason for hiding this comment

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

Great thank you!

@jdheyburn jdheyburn merged commit 4bad811 into valkey-io:main Feb 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants