Skip to content

Commit

Permalink
Add failure test for ds
Browse files Browse the repository at this point in the history
  • Loading branch information
karanthukral committed Jul 24, 2017
1 parent 9991eba commit 6e0ef23
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
3 changes: 2 additions & 1 deletion lib/kubernetes-deploy/kubernetes_resource/daemon_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def find_pods(ds_data)
context: context,
definition: pod_data,
logger: @logger,
parent: "#{@name.capitalize} daemon set"
parent: "#{@name.capitalize} daemon set",
deploy_started: @deploy_started
)
pod.sync(pod_data)
relevant_pods << pod
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/fixture_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ def assert_service_account_present(name)

def assert_daemon_set_present(name)
found = false
daemon_sets = v1beta1_kubeclient.get_daemon_sets(namespace: namespace, label_selector: "name=#{name},app=#{app_name}")
labels = "name=#{name},app=#{app_name}"
daemon_sets = v1beta1_kubeclient.get_daemon_sets(namespace: namespace, label_selector: labels)
daemon_sets.each do |ds|
found = true if ds.metadata.name == name
end
assert found
assert found, "Daemon set #{name} does not exist"
end

def assert_annotated(obj, annotation)
Expand Down
27 changes: 10 additions & 17 deletions test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_full_hello_cloud_set_deploy_succeeds
assert_logs_match_all([
%r{ReplicaSet/bare-replica-set\s+1 replica, 1 availableReplica, 1 readyReplica},
%r{Deployment/web\s+1 replica, 1 updatedReplica, 1 availableReplica},
%r{Service/web\s+Selects at least 1 pod}
%r{Service/web\s+Selects at least 1 pod},
%r{DaemonSet/nginx\s+1 currentNumberSchedule, 1 desiredNumberSchedule, 1 numberRead, 1 numberAvailabl}
])
end

Expand Down Expand Up @@ -550,30 +551,22 @@ def test_success_detection_tolerates_out_of_band_deployment_scaling
assert_equal true, success, "Failed to deploy deployment with dynamic replica count"
end

def test_successful_daemon_set_deploy
assert deploy_fixtures("hello-cloud", subset: ["daemon_set.yml"])

assert_logs_match_all([
'Successfully deployed 1 resource',
'1 currentNumberSchedule, 1 desiredNumberSchedule, 1 numberRead'
])
end

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)
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['readinessProbe'] = { "exec" => { "command" => ['- ls'] } }
container["image"] = "busybox"
container["command"] = ["ls", "/not-a-dir"]
end

refute success

assert_logs_match_all([
'Failed to deploy 1 resource',
'DaemonSet/busybox: TIMED OUT (limit: 2s)'
])
"DaemonSet/nginx: FAILED",
"The following containers are in a state that is unlikely to be recoverable:",
"Logs from container 'nginx' (last 250 lines shown):",
"ls: /not-a-dir: No such file or directory" # logs
], in_order: true)
end

private
Expand Down

0 comments on commit 6e0ef23

Please sign in to comment.