Skip to content

fix(commands): honor --endpoints in talosconfig regenerate flow#202

Merged
lexfrei merged 1 commit into
mainfrom
fix/talosconfig-honor-endpoints
May 13, 2026
Merged

fix(commands): honor --endpoints in talosconfig regenerate flow#202
lexfrei merged 1 commit into
mainfrom
fix/talosconfig-honor-endpoints

Conversation

@lexfrei
Copy link
Copy Markdown
Contributor

@lexfrei lexfrei commented May 13, 2026

What

Apply the same --endpoints fix from PR #201 (init flow) to the parallel assignment site in regenerateTalosconfig.

Why

Thorough audit of similar bug patterns across the project surfaced one more silent-flag-discard at pkg/commands/talosconfig.go:192. The regenerateTalosconfig flow, when called on a project with no existing talosconfig (e.g. operator runs talm talosconfig to regenerate certs but the original file is gone), hardcoded defaultLocalEndpoint and silently discarded --endpoints. Same bug class as #9341 (init flow); same fix.

Other audited sites:

  • charts/talm/templates/_helpers.tpl::talm.discovered.bond_config (v1.11 nested bond form): identical empty-slaves shape as the multidoc bug, but not reachable today because the Talos auto-bond-stub behaviour is a 1.13 link-controller addition while the v1.11 nested form is gated on talosVersion < v1.12. Out of scope.
  • BridgeConfig empty-ports rendering: Talos schema validates only name for bridges, so empty links: does not produce an apply-reject (unlike bond which requires ≥1 link). Operator noise only, not a bug. Out of scope.
  • pkg/commands/kubeconfig_handler.go:134: correctly checks len(GlobalArgs.Endpoints) > 0 before consuming. Not affected.
  • pkg/commands/apply.go PreRunE: seeds defaultLocalEndpoint only when GlobalArgs.Endpoints is empty, with a defensive reset between files. Not affected (the pattern is correct).

Approach

Reuse the existing resolveTalosconfigEndpoints helper from init.go so the two talosconfig-seeding sites stay in sync. The old-config path (preserving existing context endpoints) is unchanged.

Tests

The helper-level contract is already pinned by:

  • TestResolveTalosconfigEndpoints_GlobalNonEmpty_UsesGlobal
  • TestResolveTalosconfigEndpoints_GlobalEmpty_UsesLoopbackFallback
  • TestResolveTalosconfigEndpoints_ReturnsCopy
  • TestResolveTalosconfigEndpoints_MultipleEndpoints

The visible call site keeps both seeding paths under one helper so a future regression where someone re-introduces a hardcoded loopback at either site surfaces against the same test surface.

Local CI: go test ./... clean, golangci-lint run ./... 0 issues.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed talosconfig regeneration to use configured cluster endpoints instead of defaulting to local endpoint, ensuring context endpoints correctly reference your specified configuration.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Warning

Rate limit exceeded

@lexfrei has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 7 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d1cd6896-cb16-4b80-8980-e7b8c26179d9

📥 Commits

Reviewing files that changed from the base of the PR and between 0fb60a6 and 1191b22.

📒 Files selected for processing (2)
  • pkg/commands/contract_talosconfig_test.go
  • pkg/commands/talosconfig.go
📝 Walkthrough

Walkthrough

When regenerating a talosconfig without an existing config file, the endpoint initialization now resolves from GlobalArgs.Endpoints via resolveTalosconfigEndpoints() instead of hardcoding a local endpoint. Added comments clarify the fallback behavior and explain why operator-supplied --endpoints should not be silently discarded.

Changes

Talosconfig Endpoint Initialization

Layer / File(s) Summary
Endpoint initialization in config regeneration
pkg/commands/talosconfig.go
When no existing talosconfig is present, the clusterName context endpoints are initialized from GlobalArgs.Endpoints via resolveTalosconfigEndpoints() instead of using a hardcoded defaultLocalEndpoint. Comments explain the fallback behavior and why user-supplied endpoints must be preserved.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A config reborn from empty air,
Now honors endpoints with proper care,
No defaults hide what users share,
Comments bloom with wisdom rare! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing the regenerate flow to honor the --endpoints flag. It is specific, directly related to the changeset, and highlights the primary issue being addressed.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/talosconfig-honor-endpoints

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates pkg/commands/talosconfig.go to utilize resolveTalosconfigEndpoints when generating a new configuration, ensuring that the --endpoints flag is correctly respected and fixing a bug where it was previously ignored. The reviewer suggests refactoring resolveTalosconfigEndpoints into a more central location to improve modularity and reduce coupling between command files.

// here, `talm talosconfig --endpoints X` on a project with
// no prior talosconfig would silently discard the operator's
// flag — the same bug class init had at the assignment site.
newConfig.Contexts[clusterName].Endpoints = resolveTalosconfigEndpoints(GlobalArgs.Endpoints)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While reusing resolveTalosconfigEndpoints is a great way to fix this bug and maintain consistency, the function itself seems generally useful for handling talosconfig endpoints. Currently, it resides in init.go, which creates a dependency from talosconfig.go to init.go.

To improve modularity and make it clear that this is a shared helper, consider moving resolveTalosconfigEndpoints to a more central location within the commands package, such as root.go or a new helpers.go file. This would make the code organization cleaner and prevent tight coupling between command-specific files.

regenerateTalosconfig at pkg/commands/talosconfig.go:192 hit the
same silent-discard pattern as init flow: when no old talosconfig
existed, the assignment site hardcoded defaultLocalEndpoint and
discarded the operator's --endpoints flag. Reuse the
resolveTalosconfigEndpoints helper from init.go so the two
talosconfig-seeding sites stay in sync. The old-config path
(preserving existing context endpoints) is unchanged.

The helper-level contract is already pinned by
TestResolveTalosconfigEndpoints_{GlobalNonEmpty_UsesGlobal,
GlobalEmpty_UsesLoopbackFallback, ReturnsCopy, MultipleEndpoints};
the visible call site keeps both seeding paths under one helper
so a future regression where someone re-introduces a hardcoded
loopback at either site surfaces against the same test surface.

Signed-off-by: Aleksei Sviridkin <f@lex.la>
@lexfrei lexfrei force-pushed the fix/talosconfig-honor-endpoints branch from 0fb60a6 to 1191b22 Compare May 13, 2026 10:42
@lexfrei lexfrei merged commit 92ffd52 into main May 13, 2026
8 checks passed
@lexfrei lexfrei deleted the fix/talosconfig-honor-endpoints branch May 13, 2026 10:45
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