Repository navigation
Offer the Kubernetes restart task only when namespace and context are set - #1515
Conversation
… 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
left a comment
There was a problem hiding this comment.
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_platformandinfrastructurestacks 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 Kubernetesrestarttask 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.rbanddeploy_spec_test.rbin different places. #1497'sGitObjectFileSystemsubclassesFileSystem, 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.
| @@ -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, | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…come from elsewhere
Vault-Issue: 110043
Related: https://github.com/shop/issues/issues/118514
A
kubernetessection inshipit.ymlwithoutnamespaceorcontextmakesKubernetesDiscovery#discover_task_definitionsraiseKeyError. Shipit runs this discovery whenCacheDeploySpecJobcaches 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 akubernetessection with other keys.This change adds the
kubernetes-restarttask only when the section has bothnamespaceandcontext. 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
kubernetessection withoutnamespacestill 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
KeyErroron the old code, throughDeploySpec.dump. The full suite passed with SQLite and Ruby 3.4.12 (1,261 tests,bundle exec rake test), andbundle exec rubocoppasses. Locally on Ruby 3.4.9,test/models/deploy_spec_test.rbpasses (138 runs) with the fix and fails with the sameKeyErrorwithout it.What remains: Shopify's Shipit gets this fix after its
Gemfile.lockmoves to the new shipit-engine commit and Shipit deploys.