Skip to content

Commit

Permalink
Track in and out
Browse files Browse the repository at this point in the history
  • Loading branch information
dturn committed Dec 16, 2020
1 parent b71565a commit c8ec5f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
14 changes: 9 additions & 5 deletions lib/krane/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DeployTask
)

def predeploy_sequence
default_group = { skip_groups: [] }
default_group = { groups: [], skip_groups: [] }
before_crs = %w(
ResourceQuota
NetworkPolicy
Expand All @@ -71,10 +71,14 @@ def predeploy_sequence

after_crs = %w(
Pod
).map { |r| [r, default_group] }
)

predeploy_hash = Hash[before_crs]
cluster_resource_discoverer.crds.select(&:predeployed?).each do |cr|
predeploy_hash[cr.kind] ||= { groups: [cr.group], skip_groups: [] }
end

crs = cluster_resource_discoverer.crds.select(&:predeployed?).map { |cr| [cr.kind, default_group] }
predeploy_hash = Hash[before_crs + crs + after_crs]
after_crs.each { |cr| predeploy_hash[cr] = default_group }

cluster_resource_discoverer.crds.reject(&:predeployed?).each do |cr|
predeploy_hash[cr.kind][:skip_groups] << cr.group if predeploy_hash[cr.kind]
Expand Down Expand Up @@ -222,7 +226,7 @@ def ejson_provisioners
def deploy_has_priority_resources?(resources)
resources.any? do |r|
next unless (pr = predeploy_sequence[r.type])
!pr[:skip_groups].include?(r.group)
(pr[:groups].empty? || pr[:groups].include?(r.group)) && !pr[:skip_groups].include?(r.group)
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/krane/resource_deployer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def predeploy_priority_resources(resource_list, predeploy_sequence)

predeploy_sequence.each do |resource_type, attributes|
matching_resources = resource_list.select do |r|
r.type == resource_type && !attributes[:skip_groups].include?(r.group)
r.type == resource_type &&
((attributes[:groups].empty? || attributes[:groups].include?(r.group)) &&
!attributes[:skip_groups].include?(r.group))
end
StatsD.client.gauge('priority_resources.count', matching_resources.size, tags: statsd_tags)

Expand Down
2 changes: 1 addition & 1 deletion test/unit/krane/resource_deployer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_predeploy_priority_resources_respects_pre_deploy_list
# are deployed. See test_predeploy_priority_resources_respects_empty_pre_deploy_list
# for counter example
Krane::ResourceWatcher.expects(:new).returns(watcher)
priority_list = { kind => { group: "core" } }
priority_list = { kind => { groups: ["core"], skip_groups: [] } }
resource_deployer.predeploy_priority_resources([resource], priority_list)
end

Expand Down

0 comments on commit c8ec5f4

Please sign in to comment.