INNER CODE UNIT · Ruby

fetch_resources

Shopify/krane · lib/krane/cluster_resource_discovery.rb: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

    private

    # During discovery, the api paths may not actually be at the root, so we must programatically find it.
    def base_api_path
      @base_api_path ||= begin
        raw_response, err, st = kubectl.run("config", "view", "--minify", "--output",
          "jsonpath={.clusters[*].cluster.server}", attempts: 5, use_namespace: false)
        raise FatalKubeAPIError, "Error retrieving cluster url: #{err}" unless st.success?

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…