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

Actively monitor nodes status for DaemonSet deployments #881

Merged
merged 2 commits into from
Mar 31, 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
20 changes: 18 additions & 2 deletions lib/krane/kubernetes_resource/daemon_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class DaemonSet < PodSetBase
def sync(cache)
super
@pods = exists? ? find_pods(cache) : []
@nodes = find_nodes(cache) if @nodes.blank?

@nodes = refresh_nodes(cache)
end

def status
Expand Down Expand Up @@ -66,9 +67,24 @@ def relevant_pods_ready?
rollout_data["numberReady"].to_i >= considered_pods.length
end

def refresh_nodes(cache)
new_nodes = find_nodes(cache)
return new_nodes if @nodes.blank?

# Remove non-existent nodes
@nodes.select do |node|
new_nodes.find { |n| n.name == node.name } != nil
end
end

def find_nodes(cache)
all_nodes = cache.get_all(Node.kind)
all_nodes.map { |node_data| Node.new(definition: node_data) }
all_nodes.each_with_object([]) do |node_data, relevant_nodes|
next if node_data.dig('spec', 'unschedulable').to_s.downcase == 'true'
cond = node_data.dig('status', 'conditions').find { |c| c['type'].downcase == 'ready' }
next if (!cond.nil? && cond['status'].downcase != 'true')
relevant_nodes << Node.new(definition: node_data)
end
end

def rollout_data
Expand Down
46 changes: 46 additions & 0 deletions test/unit/krane/kubernetes_resource/daemon_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,51 @@ def test_deploy_passes_when_ready_pods_but_nodes_added

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_passes_when_nodes_unschedulable
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?)

# node 2 Pod Ready status is False, if the node is unschedulable it should not account as blocking
node_templates[2]['spec']['unschedulable'] = 'true'

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_passes_when_nodes_not_ready
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?)

# node 2 Pod Ready status is False, if the node is not ready it should not account as blocking
node_templates[2]['status']['conditions'].find { |c| c['type'].downcase == 'ready' }['status'] = 'False'

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
Expand Down Expand Up @@ -123,6 +168,7 @@ def test_deploy_waits_for_daemonset_status_to_converge_to_pod_states
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])
stub_kind_get("Node", items: node_templates, use_namespace: false)
ds.sync(build_resource_cache)
assert_predicate(ds, :deploy_succeeded?)
end
Expand Down