Skip to content

Commit

Permalink
Merge pull request #2944 from zendesk/grosser/counter
Browse files Browse the repository at this point in the history
include counter in daemonset error message
  • Loading branch information
grosser authored Sep 21, 2018
2 parents 1618838 + bab9ab0 commit 736a444
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions plugins/kubernetes/app/models/kubernetes/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def delete
return true unless running?
request_delete
backoff_wait([0.0, 0.1, 0.2, 0.5, 1, 2, 4, 8, 16], "delete resource") do
expire_cache
expire_resource_cache
return true unless running?
end
end
Expand Down Expand Up @@ -109,10 +109,10 @@ def backoff_wait(backoff, reason)

def request_delete
request(:delete, name, namespace)
expire_cache
expire_resource_cache
end

def expire_cache
def expire_resource_cache
remove_instance_variable(:@resource) if defined?(@resource)
end

Expand All @@ -123,14 +123,14 @@ def create
@template[:metadata].delete(:resourceVersion)
request(:create, @template)
end
expire_cache
expire_resource_cache
end

# TODO: remove the expire_cache and assign @resource but that breaks a bunch of deploy_executor tests
def update
ensure_not_updating_match_labels
request(:update, template_for_update)
expire_cache
expire_resource_cache
end

def ensure_not_updating_match_labels
Expand Down Expand Up @@ -311,7 +311,7 @@ def desired_pod_count
if i != 0
# last iteration had bad state or does not yet know how many it needs, expire cache
loop_sleep
expire_cache
expire_resource_cache
end

desired = resource.dig_fetch :status, :desiredNumberScheduled
Expand Down Expand Up @@ -340,7 +340,7 @@ def desired_pod_count
# - waits for current to reach 0
# - deletes the daemonset
def request_delete
return super if no_pods_running? # delete when already dead from previous deletion try, update would fail
return super if pods_running_count == 0 # delete when already dead from previous deletion try, update would fail

# make it match no node
restore_template do
Expand All @@ -352,9 +352,8 @@ def request_delete
super # delete it
end

def no_pods_running?
resource.dig_fetch(:status, :currentNumberScheduled).zero? &&
resource.dig_fetch(:status, :numberMisscheduled).zero?
def pods_running_count
resource.dig_fetch(:status, :currentNumberScheduled) + resource.dig_fetch(:status, :numberMisscheduled)
end

def client
Expand All @@ -364,12 +363,13 @@ def client
def wait_for_termination_of_all_pods
30.times do
loop_sleep
expire_cache
return if no_pods_running?
expire_resource_cache
return if pods_running_count == 0
end
count = pods_running_count
raise(
Samson::Hooks::UserError,
"Unable to terminate DaemonSet #{name} #{namespace} #{@deploy_group.name} because it still has pods.\n" \
"Unable to terminate DaemonSet #{error_location} because it still has #{count} #{"pod".pluralize(count)}.\n" \
"Delete it manually and redeploy again."
)
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/kubernetes/test/models/kubernetes/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def daemonset_stub(scheduled, misscheduled)
e = assert_raises Samson::Hooks::UserError do
resource.deploy
end
e.message.must_include "Unable to terminate DaemonSet some-project pod1 Pod1"
e.message.must_include "Unable to terminate DaemonSet some-project pod1 Pod1 because it still has 1 pod."
end
end

Expand Down

0 comments on commit 736a444

Please sign in to comment.