Skip to content

Commit

Permalink
Don't predeploy all CRs
Browse files Browse the repository at this point in the history
  • Loading branch information
dturn committed Dec 16, 2020
1 parent 2d9e34f commit 0a46d4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
44 changes: 25 additions & 19 deletions lib/krane/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,30 @@ class DeployTask
)

def predeploy_sequence
default_group = { groups: nil }
before_crs = {
'ResourceQuota' => default_group,
'NetworkPolicy' => { groups: %w(extensions networking.k8s.io) },
'ConfigMap' => default_group,
'PersistentVolumeClaim' => default_group,
'ServiceAccount' => default_group,
'Role' => default_group,
'RoleBinding' => default_group,
'Secret' => default_group,
}

after_crs = { 'Pod' => default_group }

crs = cluster_resource_discoverer.crds.select(&:predeployed?).map { |cr| [cr.kind, { groups: [cr.group] }] }.to_h
predeploy_hash = before_crs
predeploy_hash.merge!(crs) { |_k, old, new| { groups: old[:groups] + new[:groups] } }
predeploy_hash.merge(after_crs) { |_k, old, new| { groups: old[:groups] + new[:groups] } }
default_group = { skip_groups: [] }
before_crs = %w(
ResourceQuota
NetworkPolicy
ConfigMap
PersistentVolumeClaim
ServiceAccount
Role
RoleBinding
Secret
).map { |r| [r, default_group] }

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

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

cluster_resource_discoverer.crds.reject(&:predeployed?).each do |cr|
predeploy_hash[cr.kind][:skip_groups] << cr.group if predeploy_hash[cr.kind]
end

predeploy_hash
end

def prune_whitelist
Expand Down Expand Up @@ -216,7 +222,7 @@ def ejson_provisioners
def deploy_has_priority_resources?(resources)
resources.any? do |r|
next unless (pr = predeploy_sequence[r.type])
!pr[:groups] || pr[:groups].include?(r.group)
!pr[:skip_groups].include?(r.group)
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/krane/resource_deployer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ 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[:group] || r.group == attributes[:group])
r.type == resource_type && !attributes[:skip_groups].include?(r.group)
end
StatsD.client.gauge('priority_resources.count', matching_resources.size, tags: statsd_tags)

Expand Down

0 comments on commit 0a46d4b

Please sign in to comment.