Skip to content

Fix Kubernetes strategy crash on endpoint addresses without targetRef - #216

Open
dajiaohuang wants to merge 1 commit into
bitwalker:mainfrom
dajiaohuang:fix-kubernetes-endpoints-without-targetref
Open

dajiaohuang wants to merge 1 commit into
bitwalker:mainfrom
dajiaohuang:fix-kubernetes-endpoints-without-targetref

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary of changes

EndpointAddress.targetRef is optional in the Kubernetes API. Endpoints which are not backed by a pod — manually managed ones pointing at external addresses, for example — have no targetRef at all, and parsing such a response raised a FunctionClauseError in parse_response/2, which runs from init/1. The strategy then failed to start, so the node never joined the cluster.

Reproducing it needs no real cluster: the added VCR cassette returns one address with a targetRef and one without. Before the change the strategy fails to start with:

** (FunctionClauseError) no function clause matching in anonymous fn/1 in Cluster.Strategy.Kubernetes.parse_response/2
    (libcluster 3.5.0) lib/strategy/kubernetes.ex:473: ...
    (libcluster 3.5.0) lib/strategy/kubernetes.ex:250: Cluster.Strategy.Kubernetes.init/1

The fix keeps using targetRef.namespace when it is present, and otherwise falls back to the namespace the endpoints were queried from. Every address in an endpoints response belongs to that namespace, because the API request is namespace-scoped, so names built for :hostname and :dns modes stay correct.

Checklist

  • New functions have typespecs, changed functions were updated (only private functions changed, so no typespec or public API is affected)
  • Same for documentation, including moduledocs (no documented behaviour changed)
  • Tests were added or updated to cover changes (test/kubernetes_test.exs, plus the cassette test/fixtures/vcr_cassettes/kubernetes_no_target_ref.json)
  • Commits were squashed into a single coherent commit
  • Notes added to CHANGELOG file which describe changes at a high-level

mix test (40 tests, 0 failures) and mix format --check-formatted both pass.

`EndpointAddress.targetRef` is optional in the Kubernetes API, so addresses
which are not backed by a pod (manually managed endpoints, for example) do
not carry one. Parsing those raised a FunctionClauseError inside the
strategy's init, so the strategy could not start at all and the node never
joined the cluster.

Fall back to the namespace the endpoints were queried from, which is the
namespace every address in the response belongs to. Addresses which do have
a targetRef keep using its namespace, so existing behaviour is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant