Fix Kubernetes strategy crash on endpoint addresses without targetRef - #216
Open
dajiaohuang wants to merge 1 commit into
Open
dajiaohuang wants to merge 1 commit into
dajiaohuang wants to merge 1 commit into
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of changes
EndpointAddress.targetRefis optional in the Kubernetes API. Endpoints which are not backed by a pod — manually managed ones pointing at external addresses, for example — have notargetRefat all, and parsing such a response raised aFunctionClauseErrorinparse_response/2, which runs frominit/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
targetRefand one without. Before the change the strategy fails to start with:The fix keeps using
targetRef.namespacewhen 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:hostnameand:dnsmodes stay correct.Checklist
test/kubernetes_test.exs, plus the cassettetest/fixtures/vcr_cassettes/kubernetes_no_target_ref.json)mix test(40 tests, 0 failures) andmix format --check-formattedboth pass.