Class: KubernetesDeploy::ResourceCache
- Inherits:
-
Object
- Object
- KubernetesDeploy::ResourceCache
- Defined in:
- lib/kubernetes-deploy/resource_cache.rb
Instance Method Summary collapse
- #get_all(kind, selector = nil) ⇒ Object
- #get_instance(kind, resource_name, raise_if_not_found: false) ⇒ Object
-
#initialize(namespace, context, logger) ⇒ ResourceCache
constructor
A new instance of ResourceCache.
Constructor Details
#initialize(namespace, context, logger) ⇒ ResourceCache
Returns a new instance of ResourceCache.
7 8 9 10 11 12 13 14 15 |
# File 'lib/kubernetes-deploy/resource_cache.rb', line 7 def initialize(namespace, context, logger) @namespace = namespace @context = context @logger = logger @kind_fetcher_locks = Concurrent::Hash.new { |hash, key| hash[key] = Mutex.new } @data = Concurrent::Hash.new @kubectl = Kubectl.new(namespace: @namespace, context: @context, logger: @logger, log_failure_by_default: false) end |
Instance Method Details
#get_all(kind, selector = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kubernetes-deploy/resource_cache.rb', line 27 def get_all(kind, selector = nil) instances = use_or_populate_cache(kind).values return instances unless selector instances.select do |r| labels = r.dig("metadata", "labels") || {} labels >= selector end rescue KubectlError [] end |
#get_instance(kind, resource_name, raise_if_not_found: false) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/kubernetes-deploy/resource_cache.rb', line 17 def get_instance(kind, resource_name, raise_if_not_found: false) instance = use_or_populate_cache(kind).fetch(resource_name, {}) if instance.blank? && raise_if_not_found raise KubernetesDeploy::Kubectl::ResourceNotFoundError, "Resource does not exist (used cache for kind #{kind})" end instance rescue KubectlError {} end |