From 7fa0766df6a396860a3e0911398e1f55fa6bfdec Mon Sep 17 00:00:00 2001 From: Daniel Turner Date: Tue, 19 Jan 2021 16:12:15 -0800 Subject: [PATCH] More fixup --- lib/krane/kubernetes_resource/daemon_set.rb | 2 +- lib/krane/kubernetes_resource/deployment.rb | 2 +- lib/krane/kubernetes_resource/replica_set.rb | 2 +- lib/krane/kubernetes_resource/service.rb | 2 +- lib/krane/kubernetes_resource/stateful_set.rb | 2 +- lib/krane/resource_cache.rb | 10 ++++++---- lib/krane/task_config.rb | 8 ++++++-- 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/krane/kubernetes_resource/daemon_set.rb b/lib/krane/kubernetes_resource/daemon_set.rb index b296f633e..5cfe53665 100644 --- a/lib/krane/kubernetes_resource/daemon_set.rb +++ b/lib/krane/kubernetes_resource/daemon_set.rb @@ -3,7 +3,7 @@ module Krane class DaemonSet < PodSetBase TIMEOUT = 5.minutes - SYNC_DEPENDENCIES = %w(Pod) + SYNC_DEPENDENCIES = %w(Pod.apps) attr_reader :pods def sync(cache) diff --git a/lib/krane/kubernetes_resource/deployment.rb b/lib/krane/kubernetes_resource/deployment.rb index b7ed43b9f..0dfcf50fb 100644 --- a/lib/krane/kubernetes_resource/deployment.rb +++ b/lib/krane/kubernetes_resource/deployment.rb @@ -4,7 +4,7 @@ module Krane class Deployment < KubernetesResource TIMEOUT = 7.minutes - SYNC_DEPENDENCIES = %w(Pod ReplicaSet) + SYNC_DEPENDENCIES = %w(Pod.apps ReplicaSet.apps) REQUIRED_ROLLOUT_ANNOTATION = "required-rollout" REQUIRED_ROLLOUT_TYPES = %w(maxUnavailable full none).freeze DEFAULT_REQUIRED_ROLLOUT = 'full' diff --git a/lib/krane/kubernetes_resource/replica_set.rb b/lib/krane/kubernetes_resource/replica_set.rb index bb585bcef..204ac6dbe 100644 --- a/lib/krane/kubernetes_resource/replica_set.rb +++ b/lib/krane/kubernetes_resource/replica_set.rb @@ -4,7 +4,7 @@ module Krane class ReplicaSet < PodSetBase TIMEOUT = 5.minutes - SYNC_DEPENDENCIES = %w(Pod) + SYNC_DEPENDENCIES = %w(Pod.apps) attr_reader :pods def initialize(namespace:, context:, definition:, logger:, statsd_tags: nil, diff --git a/lib/krane/kubernetes_resource/service.rb b/lib/krane/kubernetes_resource/service.rb index 78a7f35c3..dbe84f82a 100644 --- a/lib/krane/kubernetes_resource/service.rb +++ b/lib/krane/kubernetes_resource/service.rb @@ -4,7 +4,7 @@ module Krane class Service < KubernetesResource TIMEOUT = 7.minutes - SYNC_DEPENDENCIES = %w(Pod Deployment StatefulSet) + SYNC_DEPENDENCIES = %w(Pod.apps Deployment.apps StatefulSet.apps) def sync(cache) super diff --git a/lib/krane/kubernetes_resource/stateful_set.rb b/lib/krane/kubernetes_resource/stateful_set.rb index e500a7271..ad8f2b3e6 100644 --- a/lib/krane/kubernetes_resource/stateful_set.rb +++ b/lib/krane/kubernetes_resource/stateful_set.rb @@ -4,7 +4,7 @@ module Krane class StatefulSet < PodSetBase TIMEOUT = 10.minutes ONDELETE = 'OnDelete' - SYNC_DEPENDENCIES = %w(Pod) + SYNC_DEPENDENCIES = %w(Pod.apps) attr_reader :pods def sync(cache) diff --git a/lib/krane/resource_cache.rb b/lib/krane/resource_cache.rb index 2c556c209..b030d51ad 100644 --- a/lib/krane/resource_cache.rb +++ b/lib/krane/resource_cache.rb @@ -36,10 +36,9 @@ def get_all(kind, selector = nil) [] end - # TODO: I've broken sync_dependencies def prewarm(resources) sync_dependencies = resources.flat_map { |r| r.class.const_get(:SYNC_DEPENDENCIES) } - kinds = resources.map(&:sync_group_kind).uniq # sync_dependencies).uniq + kinds = (resources.map(&:sync_group_kind + sync_dependencies).uniq Krane::Concurrency.split_across_threads(kinds, max_threads: kinds.count) { |kind| get_all(kind) } end @@ -57,9 +56,12 @@ def use_or_populate_cache(kind) end def fetch_by_kind(kind) - kind_only = kind.split(".").first.downcase # Busted for non unique kinds... + kind_only, group = kind.downcase.split(".", 2) + global_kind = @task_config.global_resources.any? do |resource| + resource['kind'].downcase == kind_only && resource['apigroup'].downcase == group + end + resource_class = KubernetesResource.class_for_kind(kind_only) - global_kind = @task_config.global_kinds.map(&:downcase).include?(kind_only) output_is_sensitive = resource_class.nil? ? false : resource_class::SENSITIVE_TEMPLATE_CONTENT raw_json, _, st = @kubectl.run("get", kind, "--chunk-size=0", attempts: 5, output: "json", output_is_sensitive: output_is_sensitive, use_namespace: !global_kind) diff --git a/lib/krane/task_config.rb b/lib/krane/task_config.rb index 113304914..415bfa2d6 100644 --- a/lib/krane/task_config.rb +++ b/lib/krane/task_config.rb @@ -14,9 +14,13 @@ def initialize(context, namespace, logger = nil, kubeconfig = nil) end def global_kinds - @global_kinds ||= begin + global_resources.map { |g| g["kind"] } + end + + def global_resources + @global_resources ||= begin cluster_resource_discoverer = ClusterResourceDiscovery.new(task_config: self) - cluster_resource_discoverer.fetch_resources(namespaced: false).map { |g| g["kind"] } + cluster_resource_discoverer.fetch_resources(namespaced: false) end end