Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karanthukral committed Jul 25, 2017
1 parent c28b09b commit 8e44ad3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def sync
if @found
daemonset_data = JSON.parse(raw_json)
@current_generation = daemonset_data["metadata"]["generation"]
@observedGeneration = daemonset_data["status"]["observedGeneration"]
@observed_generation = daemonset_data["status"]["observedGeneration"]
@rollout_data = daemonset_data["status"]
.slice("currentNumberScheduled", "desiredNumberScheduled", "numberReady", "numberAvailable")
@status = @rollout_data.map { |state_replicas, num| "#{num} #{state_replicas}" }.join(", ")
@pods = find_pods(daemonset_data)
else # reset
@rollout_data = { "currentNumberScheduled" => 0 }
@current_generation = 1 # to make sure the current and observed generations are different
@observedGeneration = 0
@observed_generation = 0
@status = nil
@pods = []
end
Expand All @@ -27,7 +27,7 @@ def sync
def deploy_succeeded?
@rollout_data["desiredNumberScheduled"].to_i == @rollout_data["currentNumberScheduled"].to_i &&
@rollout_data["desiredNumberScheduled"].to_i == @rollout_data["numberAvailable"].to_i &&
@current_generation == @observedGeneration
@current_generation == @observed_generation
end

def deploy_failed?
Expand Down Expand Up @@ -74,7 +74,7 @@ def find_pods(ds_data)

latest_pods = all_pods.find_all do |pods|
pods["metadata"]["ownerReferences"].any? { |ref| ref["uid"] == ds_data["metadata"]["uid"] } &&
pods["metadata"]["labels"]["pod-template-generation"] == current_generation
pods["metadata"]["labels"]["pod-template-generation"].to_i == current_generation.to_i
end
return unless latest_pods.present?

Expand Down
12 changes: 11 additions & 1 deletion test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,20 @@ def test_bad_container_on_daemon_sets_fails
success = deploy_fixtures("hello-cloud", subset: ["daemon_set.yml"]) do |fixtures|
daemon_set = fixtures['daemon_set.yml']['DaemonSet'].first
container = daemon_set['spec']['template']['spec']['containers'].first
container["image"] = "busybox:not-exist"
container["image"] = "busybox"
container["command"] = ["ls", "/not-a-dir"]
end

refute success
assert_logs_match_all([
"DaemonSet/nginx: FAILED",
"nginx: Crashing repeatedly (exit 1). See logs for more information.",
"Final status: 1 currentNumberScheduled, 1 desiredNumberScheduled, 0 numberReady",
"Events (common success events excluded):",
"[Pod/nginx-m3lnd] BackOff: Back-off restarting failed container (2 events)",
"Logs from container 'nginx' (last 250 lines shown):",
"ls: /not-a-dir: No such file or directory"
], in_order: true)
end

private
Expand Down

0 comments on commit 8e44ad3

Please sign in to comment.