• 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

50.0
/lib/k8s/client/runner/stream.ex
1
defmodule K8s.Client.Runner.Stream do
2
  @moduledoc """
3
  Takes a `K8s.Client.list/3` operation and returns an Elixir [`Stream`](https://hexdocs.pm/elixir/Stream.html) of resources.
4
  """
5
  alias K8s.Client.Runner.Base
6
  alias K8s.Client.Runner.Stream.ListRequest
7
  alias K8s.Client.Runner.Stream.Watch
8
  alias K8s.Conn
9
  alias K8s.Operation
10
  alias K8s.Operation.Error
11

12
  @supported_operations [:list, :list_all_namespaces, :watch, :watch_all_namespaces, :connect]
13

14
  @doc """
15
  Validates operation type before calling `stream/3`. Only supports verbs: `list_all_namespaces` and `list`.
16
  """
17
  @spec run(Operation.t()) :: {:ok, Enumerable.t()} | {:error, Error.t()}
18
  def run(%Operation{conn: %Conn{} = conn} = op), do: run(conn, op, [])
3✔
19

20
  @spec run(Operation.t(), keyword()) :: {:ok, Enumerable.t()} | {:error, Error.t()}
21
  def run(%Operation{conn: %Conn{} = conn} = op, http_opts), do: run(conn, op, http_opts)
×
22

23
  @spec run(Conn.t(), Operation.t()) :: {:ok, Enumerable.t()} | {:error, Error.t()}
24
  def run(%Conn{} = conn, %Operation{} = op), do: run(conn, op, [])
×
25

26
  @spec run(Conn.t(), Operation.t(), keyword()) :: {:ok, Enumerable.t()} | {:error, Error.t()}
27
  def run(%Conn{} = conn, %Operation{verb: verb} = op, http_opts)
28
      when verb in [:list, :list_all_namespaces] do
29
    op = name_as_field_selector(op)
1✔
30
    {:ok, ListRequest.stream(conn, op, http_opts)}
31
  end
32

33
  def run(%Conn{} = conn, %Operation{verb: verb} = op, http_opts)
34
      when verb in [:watch, :watch_all_namespaces] do
35
    op = name_as_field_selector(op)
×
36
    Watch.stream(conn, op, http_opts)
×
37
  end
38

39
  def run(%Conn{} = conn, %Operation{verb: :connect} = op, http_opts) do
40
    Base.stream(conn, op, http_opts)
2✔
41
  end
42

43
  def run(op, _, _) do
44
    msg = "Only #{inspect(@supported_operations)} operations can be streamed. #{inspect(op)}"
×
45

46
    {:error, %Error{message: msg}}
47
  end
48

49
  @spec name_as_field_selector(Operation.t()) :: Operation.t()
50
  defp name_as_field_selector(operation) do
51
    {name, operation} = pop_in(operation, [Access.key(:path_params), :name])
1✔
52

53
    if is_nil(name), do: operation, else: K8s.Selector.field(operation, {"metadata.name", name})
1✔
54
  end
55
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