Class: KubernetesDeploy::SyncMediator
- Inherits:
-
Object
- Object
- KubernetesDeploy::SyncMediator
- Defined in:
- lib/kubernetes-deploy/sync_mediator.rb
Instance Method Summary collapse
- #get_all(kind, selector = nil) ⇒ Object
- #get_instance(kind, resource_name) ⇒ Object
-
#initialize(namespace:, context:, logger:) ⇒ SyncMediator
constructor
A new instance of SyncMediator.
- #kubectl ⇒ Object
- #sync(resources) ⇒ Object
Constructor Details
#initialize(namespace:, context:, logger:) ⇒ SyncMediator
Returns a new instance of SyncMediator.
4 5 6 7 8 9 |
# File 'lib/kubernetes-deploy/sync_mediator.rb', line 4 def initialize(namespace:, context:, logger:) @namespace = namespace @context = context @logger = logger clear_cache end |
Instance Method Details
#get_all(kind, selector = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kubernetes-deploy/sync_mediator.rb', line 19 def get_all(kind, selector = nil) fetch_by_kind(kind) unless @cache.key?(kind) instances = @cache.fetch(kind, {}).values return instances unless selector instances.select do |r| labels = r.dig("metadata", "labels") || {} labels >= selector end end |
#get_instance(kind, resource_name) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/kubernetes-deploy/sync_mediator.rb', line 11 def get_instance(kind, resource_name) if @cache.key?(kind) @cache.dig(kind, resource_name) || {} else request_instance(kind, resource_name) end end |
#kubectl ⇒ Object
43 44 45 |
# File 'lib/kubernetes-deploy/sync_mediator.rb', line 43 def kubectl @kubectl ||= Kubectl.new(namespace: @namespace, context: @context, logger: @logger, log_failure_by_default: false) end |
#sync(resources) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kubernetes-deploy/sync_mediator.rb', line 30 def sync(resources) clear_cache dependencies = resources.map(&:class).uniq.flat_map do |c| c::SYNC_DEPENDENCIES if c.const_defined?('SYNC_DEPENDENCIES') end kinds = (resources.map(&:type) + dependencies).compact.uniq kinds.each { |kind| fetch_by_kind(kind) } KubernetesDeploy::Concurrency.split_across_threads(resources) do |r| r.sync(dup) end end |