Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure instance data is synced with pod state before reporting DS success #617

Merged
merged 7 commits into from
Nov 11, 2019
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
7 changes: 5 additions & 2 deletions lib/krane/kubernetes_resource/daemon_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ def relevant_pods_ready?
return true if rollout_data["desiredNumberScheduled"].to_i == rollout_data["numberReady"].to_i # all pods ready
relevant_node_names = @nodes.map(&:name)
considered_pods = @pods.select { |p| relevant_node_names.include?(p.node_name) }
@logger.debug("Considered #{considered_pods.size} pods out of #{@pods.size} for #{@nodes.size} nodes")
considered_pods.present? && considered_pods.all?(&:deploy_succeeded?)
@logger.debug("DaemonSet is reporting #{rollout_data['numberReady']} pods ready." \
" Considered #{considered_pods.size} pods out of #{@pods.size} for #{@nodes.size} nodes.")
considered_pods.present? &&
considered_pods.all?(&:deploy_succeeded?) &&
rollout_data["numberReady"].to_i >= considered_pods.length
end

def find_nodes(cache)
Expand Down
20 changes: 20 additions & 0 deletions test/unit/krane/kubernetes_resource/daemon_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ def test_deploy_fails_when_not_all_pods_ready
refute_predicate(ds, :deploy_succeeded?)
end

def test_deploy_waits_for_daemonset_status_to_converge_to_pod_states
status = {
"desiredNumberScheduled": 1,
"updatedNumberScheduled": 1,
"numberReady": 0,
}
ds_template = build_ds_template(filename: 'daemon_set.yml', status: status)
ready_pod_template = load_fixtures(filenames: ['daemon_set_pods.yml']).first # should be a pod in `Ready` state
node_templates = load_fixtures(filenames: ['nodes.yml'])
ds = build_synced_ds(ds_template: ds_template, pod_templates: [ready_pod_template], node_templates: node_templates)
refute_predicate(ds, :deploy_succeeded?)

status[:numberReady] = 1
ds_template = build_ds_template(filename: 'daemon_set.yml', status: status)
stub_kind_get("DaemonSet", items: [ds_template])
stub_kind_get("Pod", items: [ready_pod_template])
ds.sync(build_resource_cache)
assert_predicate(ds, :deploy_succeeded?)
end

private

def build_ds_template(filename:, status: {})
Expand Down