Skip to content

Commit

Permalink
More fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
dturn committed Jan 20, 2021
1 parent 6c00d18 commit 7fa0766
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/krane/kubernetes_resource/daemon_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/kubernetes_resource/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/kubernetes_resource/replica_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/kubernetes_resource/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/kubernetes_resource/stateful_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions lib/krane/resource_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions lib/krane/task_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7fa0766

Please sign in to comment.