From c0556e57127c80f2946be21cf33e193884913bd4 Mon Sep 17 00:00:00 2001 From: Aqeel Nazeer Date: Fri, 20 Nov 2026 20:31:24 +0530 Subject: [PATCH 1/2] Offer the Kubernetes restart task only when namespace and context are 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 --- CHANGELOG.md | 3 ++ .../deploy_spec/kubernetes_discovery.rb | 9 +++- test/models/deploy_spec_test.rb | 49 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9eaa93ec..df5eb338c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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, + so `CacheDeploySpecJob` failed and retried, and the stack kept its old cached deploy spec. * (bugfix) Retry GitHub server errors in background jobs with polynomial backoff for ten attempts (about 4.3 hours plus jitter), retaining error reporting when retries are exhausted. diff --git a/app/models/shipit/deploy_spec/kubernetes_discovery.rb b/app/models/shipit/deploy_spec/kubernetes_discovery.rb index 0dc126999..9f91d5d23 100644 --- a/app/models/shipit/deploy_spec/kubernetes_discovery.rb +++ b/app/models/shipit/deploy_spec/kubernetes_discovery.rb @@ -12,7 +12,7 @@ def discover_rollback_steps end def discover_task_definitions - if kube_config.present? + if kubernetes_target? { 'restart' => { 'action' => "Restart application", @@ -52,6 +52,13 @@ def kube_config @kube_config ||= config('kubernetes') || {} end + # `kubernetes-restart` needs both the namespace and the context. A + # `kubernetes` section without them (for example on a stack that + # deploys another way) offers no restart task. + def kubernetes_target? + kube_config['namespace'].present? && kube_config['context'].present? + end + def kubernetes_restart_cmd cmd = [ "kubernetes-restart", diff --git a/test/models/deploy_spec_test.rb b/test/models/deploy_spec_test.rb index e492331ec..455384b0f 100644 --- a/test/models/deploy_spec_test.rb +++ b/test/models/deploy_spec_test.rb @@ -286,6 +286,55 @@ class DeploySpecTest < ActiveSupport::TestCase assert_equal tasks, @spec.discover_task_definitions end + test "#discover_task_definitions skips the kubernetes restart command if `kubernetes` has no namespace" do + @spec.stubs(:load_config).returns( + 'kubernetes' => { + 'context' => 'bar', + 'timeout' => '20m' + } + ) + assert_equal({}, @spec.discover_task_definitions) + end + + test "#discover_task_definitions skips the kubernetes restart command if `kubernetes` has no context" do + @spec.stubs(:load_config).returns( + 'kubernetes' => { + 'namespace' => 'foo' + } + ) + assert_equal({}, @spec.discover_task_definitions) + end + + test "#discover_task_definitions keeps the user defined tasks if `kubernetes` has no namespace" do + tasks = { + 'some-other-task' => { + 'action' => 'Do something else', + 'description' => 'Eat some chips!', + 'steps' => ['echo chips'] + } + } + @spec.stubs(:load_config).returns( + 'kubernetes' => { + 'timeout' => '20m' + }, + 'tasks' => tasks + ) + assert_equal tasks, @spec.discover_task_definitions + end + + test "#cacheable caches a spec with no kubernetes restart task if `kubernetes` has no namespace" do + @spec.stubs(:load_config).returns( + 'deploy' => { 'override' => ['./deploy'] }, + 'rollback' => { 'override' => ['./rollback'] }, + 'kubernetes' => { + 'context' => 'bar' + } + ) + cached_spec = DeploySpec.load(DeploySpec.dump(@spec)) + assert_equal ['./deploy'], cached_spec.deploy_steps + assert_equal({}, cached_spec.config('tasks')) + end + test "#discover_task_definitions include the user defined restart command even if `kubernetes` is present" do tasks = { 'restart' => { From 55099b82278105ea340b2e0515c607da3f714802 Mon Sep 17 00:00:00 2001 From: Aqeel Nazeer Date: Fri, 20 Nov 2026 21:25:04 +0530 Subject: [PATCH 2/2] Narrow the CHANGELOG entry to stacks whose deploy and rollback steps come from elsewhere --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df5eb338c..f8a3c3c9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # 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, - so `CacheDeploySpecJob` failed and retried, and the stack kept its old cached deploy spec. + and `context`. On stacks whose deploy and rollback steps come from elsewhere, a `kubernetes` section + without them raised `KeyError` while the deploy spec was cached, so `CacheDeploySpecJob` failed and + retried, and the stack kept its old cached deploy spec. * (bugfix) Retry GitHub server errors in background jobs with polynomial backoff for ten attempts (about 4.3 hours plus jitter), retaining error reporting when retries are exhausted.