Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Unreleased
* (bugfix) Offer the Kubernetes `restart` task only when the `kubernetes` section names both `namespace`
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.

Expand Down
9 changes: 8 additions & 1 deletion app/models/shipit/deploy_spec/kubernetes_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def discover_rollback_steps
end

def discover_task_definitions
if kube_config.present?
if kubernetes_target?
{
'restart' => {
'action' => "Restart application",
Expand Down Expand Up @@ -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",
Expand Down
49 changes: 49 additions & 0 deletions test/models/deploy_spec_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' => {
Expand Down
Loading