Class: Krane::ClusterResourceDiscovery
- Inherits:
-
Object
- Object
- Krane::ClusterResourceDiscovery
- Defined in:
- lib/krane/cluster_resource_discovery.rb
Instance Method Summary collapse
- #crds ⇒ Object
- #fetch_resources(namespaced: false) ⇒ Object
-
#initialize(task_config:, namespace_tags: []) ⇒ ClusterResourceDiscovery
constructor
A new instance of ClusterResourceDiscovery.
- #prunable_resources(namespaced:) ⇒ Object
Constructor Details
#initialize(task_config:, namespace_tags: []) ⇒ ClusterResourceDiscovery
Returns a new instance of ClusterResourceDiscovery.
8 9 10 11 12 |
# File 'lib/krane/cluster_resource_discovery.rb', line 8 def initialize(task_config:, namespace_tags: []) @task_config = task_config @namespace_tags = @api_path_cache = {} end |
Instance Method Details
#crds ⇒ Object
14 15 16 17 18 19 |
# File 'lib/krane/cluster_resource_discovery.rb', line 14 def crds @crds ||= fetch_crds.map do |cr_def| CustomResourceDefinition.new(namespace: namespace, context: context, logger: logger, definition: cr_def, statsd_tags: @namespace_tags) end end |
#fetch_resources(namespaced: false) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/krane/cluster_resource_discovery.rb', line 30 def fetch_resources(namespaced: false) responses = Concurrent::Hash.new Krane::Concurrency.split_across_threads(api_paths) do |path| responses[path] = fetch_api_path(path)["resources"] || [] end responses.flat_map do |path, resources| resources.map { |r| resource_hash(path, namespaced, r) } end.compact.uniq { |r| "#{r['apigroup']}/#{r['kind']}" } end |
#prunable_resources(namespaced:) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/krane/cluster_resource_discovery.rb', line 21 def prunable_resources(namespaced:) black_list = %w(Namespace Node ControllerRevision Event) fetch_resources(namespaced: namespaced).map do |resource| next unless resource["verbs"].one? { |v| v == "delete" } next if black_list.include?(resource["kind"]) [resource["apigroup"], resource["version"], resource["kind"]].compact.join("/") end.compact end |