Skip to content

Add nodeAffinity to templates - #349

Closed
MonicaMagoniCom wants to merge 1 commit into
apache:masterfrom
MonicaMagoniCom:master
Closed

MonicaMagoniCom wants to merge 1 commit into
apache:masterfrom
MonicaMagoniCom:master

Conversation

@MonicaMagoniCom

Copy link
Copy Markdown
Contributor

As right now it is not possible to specify node affinity, I've added it in the templates yml.

@MonicaMagoniCom MonicaMagoniCom changed the title Add nodeAffinity Add nodeAffinity to templates Mar 7, 2023

@lhotari lhotari left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution. Please add defaults and documentation to values.yaml .

@lhotari

lhotari commented Feb 14, 2024

Copy link
Copy Markdown
Member

Thanks for the contribution. Please add defaults and documentation to values.yaml .

@MonicaMagoniCom Any chance to add this part?

@MonicaMagoniCom MonicaMagoniCom closed this by deleting the head repository May 2, 2024
smbecker added a commit to smbecker/pulsar-helm-chart that referenced this pull request Sep 25, 2026
Extends the nodeAffinity support from apache#349 (issue apache#247) to the two
workloads that were not covered by the original change:

- standalone-deployment.yaml: adds a fully-guarded affinity block so
  .Values.standalone.affinity.node_affinity places the standalone pod,
  matching the existing guarded nodeSelector/tolerations style.
- jwt-secret-init.yaml: broadens the affinity guard so nodeAffinity can
  be set independently of podAntiAffinity, mirroring the statefulset
  layout (nodeAffinity then podAntiAffinity). Existing anti-affinity
  behavior is preserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
lhotari added a commit that referenced this pull request Oct 6, 2026
* Add nodeAffinity

* Add nodeAffinity to standalone deployment and JWT init job

Extends the nodeAffinity support from #349 (issue #247) to the two
workloads that were not covered by the original change:

- standalone-deployment.yaml: adds a fully-guarded affinity block so
  .Values.standalone.affinity.node_affinity places the standalone pod,
  matching the existing guarded nodeSelector/tolerations style.
- jwt-secret-init.yaml: broadens the affinity guard so nodeAffinity can
  be set independently of podAntiAffinity, mirroring the statefulset
  layout (nodeAffinity then podAntiAffinity). Existing anti-affinity
  behavior is preserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Document node_affinity in values.yaml affinity blocks

Adds a commented node_affinity example alongside the existing
anti_affinity documentation for every component whose template
consumes it: zookeeper, bookkeeper, autorecovery, broker, proxy,
standalone, and the JWT generateSecrets job. Kept commented so the
default (no node affinity) behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Add nodeAffinity to function_worker and oxia-server statefulsets

Extends nodeAffinity coverage to the two remaining scheduled workloads
with affinity blocks. Both already emit a static affinity: key with a
conditional podAntiAffinity, so the nodeAffinity block follows the same
layout as the other statefulsets. values.yaml documents a commented
node_affinity example for each. Default behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Add nodeAffinity to broker and zookeeper upgrade jobs

The pre-upgrade StatefulSet cleanup jobs had no scheduling constraints.
Add a guarded nodeAffinity block reusing the existing
broker.affinity.node_affinity / zookeeper.affinity.node_affinity
values so these transient pods honor the same node placement as the
workloads they manage. Default behavior (no affinity) is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Align broker/zookeeper cleanup jobs with component scheduling

The pre-upgrade StatefulSet cleanup jobs previously ran with a bare pod
spec. Bring them in line with their StatefulSets so they schedule the
same way: imagePullSecrets, nodeSelector, priorityClassName,
tolerations, topologySpreadConstraints, and the full affinity block
(nodeAffinity + podAntiAffinity), plus the container imagePullPolicy.
All blocks are guarded, so default behavior is unchanged except that
the jobs now honor the component's existing scheduling settings.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Add nodeAffinity to toolset statefulset

The toolset statefulset already supported nodeSelector, priorityClassName,
tolerations, and topologySpreadConstraints but had no affinity block. Add a
guarded nodeAffinity block keyed on toolset.affinity.node_affinity, with a
nil-safe guard since toolset has no affinity map by default. The toolset
runs a single replica, so pod anti-affinity is not applicable and only
node_affinity is supported. Default behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Pass nodeAffinity through as native Kubernetes syntax

Replaces the bespoke `affinity.node_affinity.matchExpression` schema with a
raw `affinity.nodeAffinity` passthrough rendered via `toYaml | nindent`.

The custom schema modelled exactly one nodeSelectorTerm holding exactly one
matchExpression, always under requiredDuringSchedulingIgnoredDuringExecution.
It could not express a weighted preferredDuringSchedulingIgnoredDuringExecution,
multiple terms (OR), multiple expressions within a term (AND), or matchFields --
all common for node pinning. It also interpolated `key` and `values` unquoted,
so any label value YAML reads as a scalar (`true`, `123`, `on`) rendered with
the wrong type and was rejected by the API; `--set-string` was no workaround
because the template output re-introduced the type. That made `Gt`/`Lt`
unusable entirely, since they require numeric-looking strings.

Native syntax removes the whole class of problem: users write real YAML, so
quoting is theirs to control, and every affinity feature is reachable. It also
matches the convention of every adjacent scheduling knob in this chart
(nodeSelector, tolerations, topologySpreadConstraints are all toYaml
passthroughs), and replaces 12 lines of template per component with 3.

Nothing was released with the old shape, so there is no compatibility break.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Drop pod anti-affinity from the sts-cleanup hooks

Commit 6f1ffb3 gave the broker and zookeeper sts-cleanup Jobs the same
podAntiAffinity block as their component StatefulSets. The guard is
`and .Values.affinity.anti_affinity .Values.<component>.affinity.anti_affinity`
and both default to true, so it guarded nothing: `helm template` with no values
overridden at all differed from master in exactly these two Jobs.

For zookeeper that is a broken upgrade. `zookeeper.affinity.type` defaults to
requiredDuringSchedulingIgnoredDuringExecution and `zookeeper.replicaCount` to
3, so on a 3-node cluster the same required rule that spreads the 3 ZK pods
one-per-node also excludes every hostname for the hook pod. The Job carries
`helm.sh/hook: pre-upgrade`, so it stays Pending, the hook never completes, and
`helm upgrade` blocks until timeout and fails. The broker Job escaped only
because `broker.affinity.type` happens to default to preferred.

These are short-lived single-shot pods that run kubectl. Spreading them across
nodes buys nothing, so they get node affinity (which is opt-in and reflects
where the operator wants Pulsar to run at all) and no pod anti-affinity.

Verified: `helm template test charts/pulsar` on default values now has zero
scheduling-related differences against master, and neither Job renders
podAntiAffinity even with `affinity.anti_affinity=true`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Add nodeAffinity to the remaining six pod templates

Six of the chart's 18 pod-producing templates had no node affinity support, so
"all scheduled workloads" was not accurate. All six already honour nodeSelector
and tolerations, so all six are workloads an operator can already place --
node affinity was simply missing.

  bookkeeper-cluster-initialize.yaml      pulsar_metadata.affinity.nodeAffinity
  pulsar-cluster-initialize.yaml          pulsar_metadata.affinity.nodeAffinity
  pulsar-manager-cluster-initialize.yaml  pulsar_metadata.affinity.nodeAffinity
  dekaf-deployment.yaml                   dekaf.deployment.affinity.nodeAffinity
  oxia-coordinator-deployment.yaml        oxia.coordinator.affinity.nodeAffinity
  pulsar-manager-statefulset.yaml         pulsar_manager.affinity.nodeAffinity

The three init Jobs share pulsar_metadata, matching how they already share its
nodeSelector and tolerations. The other three components had no affinity block
in values.yaml at all, so one is added carrying nodeAffinity only -- they have
no pod anti-affinity to configure.

Access is written nil-safe -- `(.Values.x.affinity).nodeAffinity` -- so an
explicit `affinity: null` in a user's values file is not a nil dereference.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Cover nodeAffinity in CI values and document it in the README

.ci/templates-all-values.yaml gets a nodeAffinity on every component, using a
deliberately awkward value -- two nodeSelectorTerms, several matchExpressions
per term, matchFields, and required plus preferred together -- so the CI sweep
exercises the `toYaml | nindent` passthrough against a deeply nested
multi-element value, which is what that file exists to do. The patch1 overlay
swaps in a two-entry weighted preferred list, and carries the function worker,
whose StatefulSet only renders under that overlay.

README gains a node-pinning example next to the existing anti-affinity note,
since pinning to a dedicated node pool is the case issue #247 asked for.

Verified: helm lint clean; kubeconform -strict passes on k8s 1.25/1.31/1.36
across default values and all 19 .ci/clusters configs, with and without node
affinity set on every component (120 combinations), plus both
templates-all-values renders at 1.36.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Cover standalone nodeAffinity in CI

The all-values runs keep standalone disabled, so standalone-deployment.yaml's
nodeAffinity passthrough was the only one CI never rendered. Set it in
values-standalone.yaml, which is both kubeconform-validated and installed on
kind, using terms that every kind node satisfies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Monica Magoni <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Lari Hotari <[email protected]>
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.

2 participants