Skip to content

fix(planner): hash template before controller changes - #662

Open
D-Joey-G wants to merge 1 commit into
temporalio:mainfrom
D-Joey-G:fix/656-pinned-build-template-hash
Open

D-Joey-G wants to merge 1 commit into
temporalio:mainfrom
D-Joey-G:fix/656-pinned-build-template-hash

Conversation

@D-Joey-G

Copy link
Copy Markdown
Contributor

What was changed

updateDeploymentWithPodTemplateSpec now hashes the user-provided template before controller modifications get applied. This aligns it with the drift check and creation steps.

Also deep-copies the template before modifications. DeploymentSpec() only copied the template on the legacy path when spec.deployment is nil, so applying env vars or volumes could mutate the WorkerDeploymentSpec. This was latent previously, but the change to the hash order made it salient.

Why?

When unsafeCustomBuildID is set, changing a pod template field is applied in place to the existing deployment, so after a first update the controller could see drift every 10s (i.e. per reconcile) and re-send the same update. Thankfully these were no-ops on the server side, but it still cost an API call and a log line, and could be a potential footgun.

This was because the temporal.io/pod-template-spec was computed from differnt inputs at creation vs update time.

Checklist

  1. Closes [Bug] With a pinned build ID, the controller keeps updating the Deployment after a template change #656

  2. How was this tested:

  • TestCheckAndUpdateDeploymentPodTemplateSpec no re-runs the check on its result and asserts that there was no second update. This fails on main but is fixed in this branch. The test also now asserts that the input spec is not mutated.
  1. Any docs updates needed?

None required

With unsafeCustomBuildID set, the in-place update stored a hash of the
template after controller env vars and volumes were applied, but
creation and the drift check hash the user template before them, so the
hashes never matched.

Hash the user template first, and deep-copy it so controller changes
don't mutate.
@D-Joey-G
D-Joey-G requested review from a team, eniko-dif and jlegrone as code owners October 20, 2026 08:34

@tomba7 tomba7 left a comment

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.

Thanks for doing this fix @D-Joey-G!

wdDepSpec := spec.DeploymentSpec()
// Hash the user template, excluding controller-managed fields.
podTemplateSpecHash := k8s.ComputePodTemplateSpecHash(wdDepSpec.Template)
wdDepSpec.Template = *wdDepSpec.Template.DeepCopy()

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.

small nit: could we add a comment explaining this deep copy? It wasn't clear at first glance why it's needed to protect spec.template without looking at the unit test.

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.

[Bug] With a pinned build ID, the controller keeps updating the Deployment after a template change

2 participants