From a6e3af489beba9f61c9ed3dec7ac929a9be3eb09 Mon Sep 17 00:00:00 2001 From: Net Date: Fri, 19 Jan 2018 16:01:11 -0500 Subject: [PATCH] Consider Kubernetes API [] and null equivalent See https://github.com/kubernetes/kubernetes/pull/45294. --- lib/strategy/kubernetes.ex | 44 ++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/lib/strategy/kubernetes.ex b/lib/strategy/kubernetes.ex index 1de3fb9..b172708 100644 --- a/lib/strategy/kubernetes.ex +++ b/lib/strategy/kubernetes.ex @@ -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 @@ -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)