Skip to content

Commit

Permalink
Fix pruning test to expect ds
Browse files Browse the repository at this point in the history
  • Loading branch information
karanthukral committed Jul 18, 2017
1 parent 03a0002 commit 8d944d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 5 additions & 6 deletions lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def sync
@status = @rollout_data.map { |state_replicas, num| "#{num} #{state_replicas.chop.pluralize(num)}" }.join(", ")
@pods = find_pods(daemonset_data)
else # reset
@rollout_data = { "replicas" => 0 }
@rollout_data = { "currentNumberScheduled" => 0 }
@status = nil
@pods = []
end
Expand Down Expand Up @@ -76,21 +76,20 @@ def container_names
@definition["spec"]["template"]["spec"]["containers"].map { |c| c["name"] }
end

def find_pods(daemonset_data)
label_string = daemonset_data["spec"]["selector"]["matchLabels"].map { |k, v| "#{k}=#{v}" }.join(",")
def find_pods(ds_data)
label_string = ds_data["spec"]["selector"]["matchLabels"].map { |k, v| "#{k}=#{v}" }.join(",")
raw_json, _err, st = kubectl.run("get", "pods", "-a", "--output=json", "--selector=#{label_string}")
return [] unless st.success?

all_pods = JSON.parse(raw_json)["items"]
all_pods.each_with_object([]) do |pod_data, relevant_pods|
next unless pod_data["metadata"]["ownerReferences"].any? { |ref| ref["uid"] == daemonset_data["metadata"]["uid"] }
next unless pod_data["metadata"]["ownerReferences"].any? { |ref| ref["uid"] == ds_data["metadata"]["uid"] }
pod = Pod.new(
namespace: namespace,
context: context,
definition: pod_data,
logger: @logger,
parent: "#{@name.capitalize} replica set",
deploy_started: @deploy_started
parent: "#{@name.capitalize} daemon set"
)
pod.sync(pod_data)
relevant_pods << pod
Expand Down
5 changes: 2 additions & 3 deletions test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_pruning_works
'deployment "web"',
'ingress "web"'
] # not necessarily listed in this order
expected_msgs = [/Pruned 5 resources and successfully deployed 3 resources/]
expected_msgs = [/Pruned 6 resources and successfully deployed 3 resources/]
expected_pruned.map do |resource|
expected_msgs << /The following resources were pruned:.*#{resource}/
end
Expand Down Expand Up @@ -562,8 +562,7 @@ def test_successful_daemon_set_deploy
def test_timed_out_daemon_set_deploy
forced_timeout = 2 # failure often takes 8s, and want both
KubernetesDeploy::DaemonSet.any_instance.stubs(:timeout).returns(forced_timeout)
success = deploy_fixtures("hello-cloud", subset: ["daemon_set.yml"]) do |fixtures|
puts fixtures
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['readinessProbe'] = { "exec" => { "command" => ['- ls'] } }
Expand Down

0 comments on commit 8d944d1

Please sign in to comment.