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

Ignore Evicted Pods in DaemonSet deployments #883

Merged
merged 1 commit into from
Apr 1, 2022
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
2 changes: 1 addition & 1 deletion lib/krane/kubernetes_resource/daemon_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def initialize(definition:)
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) }
considered_pods = @pods.select { |p| relevant_node_names.include?(p.node_name) && !p.evicted? }
@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? &&
Expand Down
4 changes: 4 additions & 0 deletions lib/krane/kubernetes_resource/pod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def node_name
@instance_data.dig('spec', 'nodeName')
end

def evicted?
phase == "Failed" && reason == "Evicted"
end

private

def failed_schedule_reason
Expand Down
26 changes: 26 additions & 0 deletions test/unit/krane/kubernetes_resource/daemon_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,32 @@ def test_deploy_passes_when_nodes_not_ready
assert_predicate(ds, :deploy_succeeded?)
end

def test_deploy_passes_when_pod_evicted
status = {
"desiredNumberScheduled": 3,
"updatedNumberScheduled": 3,
"numberReady": 2,
}
ds_template = build_ds_template(filename: 'daemon_set.yml', status: status)
pod_templates = load_fixtures(filenames: ['daemon_set_pods.yml'])
node_templates = load_fixtures(filenames: ['nodes.yml'])
ds = build_synced_ds(ds_template: ds_template, pod_templates: pod_templates, node_templates: node_templates)
refute_predicate(ds, :deploy_succeeded?)

pod_templates[2]["status"] = {
"message": "Pod The node had condition: [DiskPressure].",
"phase": "Failed",
"reason": "Evicted",
"startTime": "2022-03-31T20:14:06Z"
}

stub_kind_get("DaemonSet", items: [ds_template])
stub_kind_get("Pod", items: pod_templates)
stub_kind_get("Node", items: node_templates, use_namespace: false)
ds.sync(build_resource_cache)
assert_predicate(ds, :deploy_succeeded?)
end

def test_deploy_fails_when_not_all_pods_updated
status = {
"desiredNumberScheduled": 2,
Expand Down