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

coryodaniel / k8s / 3ad638d4ead66a6b92e146babfaa4886000cf7e7

18 Mar 2024 07:31AM UTC coverage: 84.249%. Remained the same
3ad638d4ead66a6b92e146babfaa4886000cf7e7

push

github

web-flow
Merge pull request #309 from coryodaniel/dependabot/github_actions/actions/checkout-4.1.2

Bump actions/checkout from 4.1.1 to 4.1.2

920 of 1092 relevant lines covered (84.25%)

335.14 hits per line

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

90.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, [])
6✔
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, [])
11✔
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)
7✔
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)
3✔
36
    Watch.stream(conn, op, http_opts)
3✔
37
  end
38

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

43
  def run(op, _, _) do
44
    msg = "Only #{inspect(@supported_operations)} operations can be streamed. #{inspect(op)}"
2✔
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])
10✔
52

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