Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider Kubernetes API [] and null to be equivalent #38

Merged
merged 1 commit into from
Jan 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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