From 0a46d4b531f88facd7b7ff520908a0dc8456bd7a Mon Sep 17 00:00:00 2001 From: Daniel Turner Date: Wed, 16 Dec 2020 11:57:37 -0800 Subject: [PATCH] Don't predeploy all CRs --- lib/krane/deploy_task.rb | 44 +++++++++++++++++++--------------- lib/krane/resource_deployer.rb | 3 +-- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/krane/deploy_task.rb b/lib/krane/deploy_task.rb index 4796bd0c8..86fa15afd 100644 --- a/lib/krane/deploy_task.rb +++ b/lib/krane/deploy_task.rb @@ -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 @@ -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 diff --git a/lib/krane/resource_deployer.rb b/lib/krane/resource_deployer.rb index 3990fb0af..b0cbc7782 100644 --- a/lib/krane/resource_deployer.rb +++ b/lib/krane/resource_deployer.rb @@ -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)