• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

coryodaniel / k8s / 807e93631268e5fd52ca29e3e4755088cf11bf27-PR-262

pending completion
807e93631268e5fd52ca29e3e4755088cf11bf27-PR-262

Pull #262

github

mruoss
add possibility to wait for delete
Pull Request #262: add possibility to wait for delete

6 of 6 new or added lines in 1 file covered. (100.0%)

732 of 1009 relevant lines covered (72.55%)

44.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/lib/k8s/discovery/resource_finder.ex
1
defmodule K8s.Discovery.ResourceFinder do
2
  @moduledoc """
3
  Kubernetes API Groups
4
  """
5

6
  alias K8s.Discovery.ResourceNaming
7

8
  @type error_t :: {:error, K8s.Discovery.Error.t()}
9

10
  @doc """
11
  Get the REST resource name for a kubernetes `Kind`.
12

13
  Since `K8s.Operation` is abstracted away from a specific cluster, when working with kubernetes resource `Map`s and specifying `"kind"` the `K8s.Operation.Path` module isn't
14
  able to determine the correct path. (It will generate things like /api/v1/Pod instead of api/v1/pods).
15

16
  Also accepts REST resource name in the event they are provided, as it may be known in the event of subresources.
17
  """
18
  @spec resource_name_for_kind(K8s.Conn.t(), binary(), binary()) ::
19
          {:ok, binary()}
20
          | error_t
21
  def resource_name_for_kind(conn, api_version, name_or_kind) do
22
    case find_resource(conn, api_version, name_or_kind) do
97✔
23
      {:ok, %{"name" => name}} ->
97✔
24
        {:ok, name}
25

26
      error ->
27
        error
×
28
    end
29
  end
30

31
  @doc """
32
  Finds a resource definition by api version and (name or kind).
33
  """
34
  @spec find_resource(K8s.Conn.t(), binary(), atom() | binary()) ::
35
          {:ok, map}
36
          | error_t
37
  def find_resource(conn, api_version, name_or_kind) do
38
    with {:ok, resources} <- conn.discovery_driver.resources(api_version, conn) do
97✔
39
      find_resource_by_name(resources, name_or_kind)
97✔
40
    end
41
  end
42

43
  @doc false
44
  @spec find_resource_by_name(list(map), atom() | binary()) ::
45
          {:ok, map} | error_t
46
  def find_resource_by_name(resources, name_or_kind) do
47
    resource = Enum.find(resources, &ResourceNaming.matches?(&1, name_or_kind))
102✔
48

49
    case resource do
102✔
50
      nil ->
1✔
51
        {:error,
52
         %K8s.Discovery.Error{
53
           message: "Unsupported Kubernetes resource: #{inspect(name_or_kind)}"
54
         }}
55

56
      resource ->
101✔
57
        {:ok, resource}
58
    end
59
  end
60
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc