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

mruoss / kompost / d3d3b53dc1f761432ab8cd958b74b2b23b4427ad-PR-27

pending completion
d3d3b53dc1f761432ab8cd958b74b2b23b4427ad-PR-27

Pull #27

github

mruoss
fix ssl connection and add ca
Pull Request #27: SSL support

22 of 22 new or added lines in 3 files covered. (100.0%)

74 of 532 relevant lines covered (13.91%)

4.56 hits per line

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

0.0
/lib/kompost/kompo/temporal/controller/namespace_controller.ex
1
defmodule Kompost.Kompo.Temporal.Controller.NamespaceController do
2
  use Bonny.ControllerV2
3

4
  require Logger
5

6
  alias Kompost.Kompo.Temporal.APIClient
7
  alias Kompost.Kompo.Temporal.Conn
8

9
  step Bonny.Pluggable.SkipObservedGenerations
10

11
  step Kompost.Pluggable.InitConditions, conditions: ["Connected", "Created"]
12

13
  step Bonny.Pluggable.Finalizer,
14
    id: "kompost.chuge.li/delete-resources",
15
    impl: &__MODULE__.delete_resources/1,
16
    add_to_resource: &__MODULE__.add_finalizer?/1,
17
    log_level: :debug
18

19
  step :handle_event
20

21
  @spec handle_event(Bonny.Axn.t(), Keyword.t()) :: Bonny.Axn.t()
22
  def handle_event(%Bonny.Axn{action: action} = axn, _opts)
23
      when action in [:add, :modify, :reconcile] do
24
    {api_server_ref, namespace_spec} = Map.pop!(axn.resource["spec"], "apiServerRef")
×
25
    id = Conn.get_id(api_server_ref)
×
26
    namespace = axn.resource["metadata"]["namespace"] <> "-" <> axn.resource["metadata"]["name"]
×
27

28
    with {:channel, %GRPC.Channel{} = channel} <- {:channel, Conn.lookup(id)},
×
29
         axn <-
×
30
           set_condition(
31
             axn,
32
             "Connected",
33
             true,
34
             "Connected to the referenced Temporal API Server."
35
           ),
36
         {:namespace, axn, {:ok, _namespace}} <-
×
37
           {:namespace, axn, APIClient.apply_namespace(channel, namespace, namespace_spec)} do
38
      axn
39
      |> success_event(message: "The namespace was created successfully.")
40
      |> set_condition(
×
41
        "Created",
42
        true,
43
        "The namespace was created successfully."
44
      )
45
    else
46
      {:channel, nil} ->
47
        message = "Could not connect to Temporal cluster: No active connection was found"
×
48
        Logger.warning("#{axn.action} failed. #{message}")
×
49

50
        axn
51
        |> failure_event(message: message)
52
        |> set_condition("Connected", false, message)
×
53

54
      {:namespace, axn, {:error, exception}} when is_exception(exception) ->
55
        message = Exception.message(exception)
×
56
        Logger.warning("#{axn.action} failed. #{message}")
×
57

58
        axn
59
        |> failure_event(message: message)
60
        |> set_condition("Created", false, message)
×
61
    end
62
  end
63

64
  def handle_event(%Bonny.Axn{action: :delete} = axn, _opts) do
65
    success_event(axn)
×
66
  end
67

68
  @doc """
69
  Finalizer preventing the deletion of the database resource until underlying
70
  resources on the postgres instance are cleaned up.
71
  """
72
  @spec delete_resources(Bonny.Axn.t()) :: {:ok, Bonny.Axn.t()} | {:error, Bonny.Axn.t()}
73
  def delete_resources(axn) do
74
    resource = axn.resource
×
75
    namespace = resource["metadata"]["namespace"] <> "-" <> resource["metadata"]["name"]
×
76
    id = Conn.get_id(resource["spec"]["apiServerRef"])
×
77

78
    with {:channel, %GRPC.Channel{} = channel} <- {:channel, Conn.lookup(id)},
×
79
         {:namespace, axn, {:ok, _namespace}} <-
×
80
           {:namespace, axn, APIClient.delete_namespace(channel, namespace)} do
81
      {:ok, axn}
82
    else
83
      {:channel, nil} ->
84
        message =
×
85
          "The referenced Temporal API Server was not found. We consider the resource gone."
86

87
        Logger.warning("Failed to finalize. #{message}")
×
88

89
        {:ok, axn}
90

91
      {:namespace, axn, {:error, exception}} when is_exception(exception) ->
92
        message = Exception.message(exception)
×
93
        Logger.warning("#{axn.action} failed. #{message}")
×
94

95
        axn
96
        |> failure_event(message: message)
97
        |> set_condition("Deleted", false, message)
×
98

99
        {:error, axn}
100
    end
101
  end
102

103
  @spec add_finalizer?(Bonny.Axn.t()) :: boolean()
104
  def add_finalizer?(%Bonny.Axn{resource: resource}) do
105
    conditions =
×
106
      resource
107
      |> get_in([Access.key("status", %{}), Access.key("conditions", [])])
108
      |> Map.new(&{&1["type"], &1})
×
109

110
    resource["metadata"]["annotations"]["kompost.chuge.li/deletion-policy"] != "abandon" and
×
111
      conditions["Connected"]["status"] == "True"
×
112
  end
113
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

© 2026 Coveralls, Inc