Skip to content

Commit

Permalink
Consider Kubernetes API [] and null equivalent (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
net authored and bitwalker committed Jan 21, 2018
1 parent 654c226 commit 6d89805
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions lib/strategy/kubernetes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,16 @@ defmodule Cluster.Strategy.Kubernetes do

defp parse_response(:ip, app_name, resp) do
case resp do
%{"items" => []} ->
[]
%{"items" => items} ->
%{"items" => items} when is_list(items) ->
Enum.reduce(items, [], fn
%{"subsets" => []}, acc ->
acc
%{"subsets" => subsets}, acc ->
addrs = Enum.flat_map(subsets, fn
%{"addresses" => addresses} ->
Enum.map(addresses, fn %{"ip" => ip} -> :"#{app_name}@#{ip}" end)
_ ->
[]
end)
%{"subsets" => subsets}, acc when is_list(subsets) ->
addrs =
Enum.flat_map(subsets, fn
%{"addresses" => addresses} when is_list(addresses) ->
Enum.map(addresses, fn %{"ip" => ip} -> :"#{app_name}@#{ip}" end)
_ ->
[]
end)
acc ++ addrs
_, acc ->
acc
Expand All @@ -193,20 +190,17 @@ defmodule Cluster.Strategy.Kubernetes do

defp parse_response(:dns, app_name, resp) do
case resp do
%{"items" => []} ->
[]
%{"items" => items} ->
%{"items" => items} when is_list(items) ->
Enum.reduce(items, [], fn
%{"subsets" => []}, acc ->
acc
%{"subsets" => subsets}, acc ->
addrs = Enum.flat_map(subsets, fn
%{"addresses" => addresses} ->
Enum.map(addresses, fn %{"ip" => ip, "targetRef" => %{"namespace" => namespace}} -> format_dns_record(app_name, ip, namespace) end)
_ ->
[]
end)
acc ++ addrs
%{"subsets" => subsets}, acc when is_list(subsets) ->
addrs =
Enum.flat_map(subsets, fn
%{"addresses" => addresses} when is_list(addresses) ->
Enum.map(addresses, fn %{"ip" => ip, "targetRef" => %{"namespace" => namespace}} -> format_dns_record(app_name, ip, namespace) end)
_ ->
[]
end)
acc ++ addrs
_, acc ->
acc
end)
Expand Down

0 comments on commit 6d89805

Please sign in to comment.