Skip to content

Offer the Kubernetes restart task only when namespace and context are set - #1515

Merged
aqeelvn merged 2 commits into
mainfrom
kubernetes-restart-needs-namespace
Nov 20, 2026
Merged

aqeelvn merged 2 commits into
mainfrom
kubernetes-restart-needs-namespace

Conversation

@aqeelvn

@aqeelvn aqeelvn commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Vault-Issue: 110043
Related: https://github.com/shop/issues/issues/118514

A kubernetes section in shipit.yml without namespace or context makes KubernetesDiscovery#discover_task_definitions raise KeyError. Shipit runs this discovery when CacheDeploySpecJob caches the deploy spec. So the job fails and retries, and the stack keeps its old cached spec. This happens on stacks that deploy another way and keep a kubernetes section with other keys.

This change adds the kubernetes-restart task only when the section has both namespace and context. The command needs both values, so no working configuration loses its task. Other tasks do not change.

Deploy and rollback discovery do not change. A kubernetes section without namespace still fails there when nothing else gives deploy steps, because Shipit must not choose another deploy tool for that stack in silence.

Validation: the new tests raise the KeyError on the old code, through DeploySpec.dump. The full suite passed with SQLite and Ruby 3.4.12 (1,261 tests, bundle exec rake test), and bundle exec rubocop passes. Locally on Ruby 3.4.9, test/models/deploy_spec_test.rb passes (138 runs) with the fix and fails with the same KeyError without it.

What remains: Shopify's Shipit gets this fix after its Gemfile.lock moves to the new shipit-engine commit and Shipit deploys.

… set

A `kubernetes` section in `shipit.yml` without `namespace` or `context`
made `KubernetesDiscovery#discover_task_definitions` raise `KeyError`
while `CacheDeploySpecJob` cached the deploy spec, so the job failed and
retried and the stack kept its old cached spec. The `kubernetes-restart`
command needs both values, so the task is now only added when both are
present. Deploy and rollback discovery are unchanged.

Vault-Issue: 110043

@collin-miller collin-miller left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for this. I traced how the cached spec gets built (FileSystem#cacheable_config → deploy_steps → rollback_steps → cacheable_tasks). I also looked at the host-app discovery modules in Shopify/shipit that wrap KubernetesDiscovery. The fix is correct for the failure in shop/issues#118514.

  • Why it works in Shopify's Shipit: production_platform and infrastructure stacks get their deploy and rollback steps without calling into Kubernetes discovery, so the task step was the only thing raising.
  • Side benefit: those modules build their task list with own_tasks.merge(super), so a Kubernetes restart task would replace theirs. With this change, their own restart task comes back.
  • Other PRs: I checked your other open PRs (#1497, #1498). They touch file_system.rb and deploy_spec_test.rb in different places. #1497's GitObjectFileSystem subclasses FileSystem, so it inherits this fix. No clashes.
  • CI: green.

Approving, with one comment on how far the CHANGELOG entry reaches. It's worth tightening, but it shouldn't hold the PR.


AI review by pr-patrol (anthropic/claude-opus-5-5), posted as @collin-miller. Findings: medium; approve by pr-patrol's severity thresholds.

Comment thread CHANGELOG.md Outdated
@@ -1,4 +1,7 @@
# Unreleased
* (bugfix) Offer the Kubernetes `restart` task only when the `kubernetes` section names both `namespace`
and `context`. A `kubernetes` section without them raised `KeyError` while the deploy spec was cached,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This fix only applies when deploy and rollback steps both come from somewhere other than Kubernetes discovery.

When the spec is cached, rollback steps are worked out before tasks. KubernetesDiscovery#discover_rollback_steps still calls kube_config.fetch('namespace') in discover_kubernetes.

So take a stack with a deploy.override, no rollback.override, and a kubernetes section holding only other keys such as timeout. Caching it still raises the same KeyError (now from line 45, via rollback_steps), and CacheDeploySpecJob still fails and retries. The same applies in Shopify's Shipit to stacks using orchestrator or publish_release discovery: those only supply deploy steps.

The new #cacheable test sets both overrides, so it doesn't cover this. Could you narrow this entry, e.g. "…when the stack's deploy and rollback steps come from elsewhere"? A test with only a deploy override would pin the current behaviour. Whether rollback discovery should skip a namespace-less section, or raise a clear DeploySpec::Error, can be a follow-up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, confirmed: discover_rollback_steps still reaches kube_config.fetch('namespace') through discover_kubernetes, so a stack with only a deploy.override (or orchestrator / publish_release discovery) still raises. Narrowed the entry in 55099b8 to stacks whose deploy and rollback steps come from elsewhere, which is the case for the two stacks in shop/issues#118514.

I left out the deploy-override-only test: it would assert the raw KeyError as expected behaviour, which is the thing a follow-up should change. Whether rollback discovery should skip a namespace-less section or raise a clear DeploySpec::Error is a separate follow-up.

@aqeelvn
aqeelvn merged commit 4fc0af3 into main Nov 20, 2026
15 checks passed
@aqeelvn
aqeelvn deleted the kubernetes-restart-needs-namespace branch November 20, 2026 16:04
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