Skip to content

Commit

Permalink
Ensure instance data is synced with pod state before reporting DS suc…
Browse files Browse the repository at this point in the history
…cess (#617)
  • Loading branch information
timothysmith0609 authored Nov 11, 2019
1 parent 390b34e commit d470158
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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

0 comments on commit d470158

Please sign in to comment.