Fall back to leader address when joining controllers (#1103) - #1106
Draft
kke wants to merge 1 commit into
Draft
Conversation
When spec.api.externalAddress is an externally managed VIP the join token's embedded server URL points at the VIP. During bootstrap the VIP may be assigned to a controller that is not yet running, so both k0sctl'spreflight API check and the actual join fail non-deterministically depending on which node currently holds the VIP. If the token-embedded URL is unreachable, rewrite the token's server host to the freshly initialized leader's address (which is guaranteed to be up) and retry. The token itself is rewritten, so the real join targets the leader too, not just the preflight validation. Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses non-deterministic controller joins when spec.api.externalAddress is an externally managed VIP that may not be assigned to the freshly bootstrapped leader yet. It adds logic to retry join/preflight API connectivity using the leader’s address by rewriting the token-embedded kubeconfig server host.
Changes:
- Added
TokenData.WithJoinHost()(plusencodeToken()) to rewrite the token’s embedded kubeconfig server host while preserving scheme/port and re-encoding the token. - Updated the controller install phase to retry API validation via the leader’s address when the token URL is unreachable, and to use the rewritten token for the actual join.
- Added unit tests covering token parsing and host-rewrite behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/k0s.go | Adds token kubeconfig host-rewrite + token re-encoding helper to support join retries via leader address. |
| pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/k0s_test.go | Adds tests for token host rewriting and reduces reliance on a single hardcoded token fixture. |
| phase/install_controllers.go | Implements “try token URL, then fallback to leader address” logic and rewrites the join token to ensure the join itself uses the fallback target. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+155
to
158
| rewritten, rerr := h.Metadata.K0sTokenData.WithJoinHost(leaderJoinHost) | ||
| if rerr != nil { | ||
| return fmt.Errorf("failed to connect from controller to kubernetes api - check networking: %w", err) | ||
| } |
Comment on lines
+160
to
+162
| if rerr := retry.WithDefaultTimeout(ctx, node.HTTPStatusFunc(h, rewritten.URL, 200, 401, 404)); rerr != nil { | ||
| return fmt.Errorf("failed to connect from controller to kubernetes api - check networking: %w", err) | ||
| } |
Member
|
Would this fallback also mean that kubelet would also fallback to this address? So in the VIP use case in #1103 , kubelet would only connect to the first node direct IP? |
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.
Fixes #1103 (or tries to)
When spec.api.externalAddress is an externally managed VIP the join token's embedded server URL points at the VIP. During bootstrap the VIP may be assigned to a controller that is not yet running, so both k0sctl'spreflight API check and the actual join fail non-deterministically depending on which node currently holds the VIP.
If the token-embedded URL is unreachable, rewrite the token's server host to the freshly initialized leader's address (which should be up at this point) and retry.