Skip to content

k8sclient: use ServerVersion instead of pod list for kubeconfig validation#1478

Open
pliurh wants to merge 2 commits intok8snetworkplumbingwg:masterfrom
pliurh:kubeconfig
Open

k8sclient: use ServerVersion instead of pod list for kubeconfig validation#1478
pliurh wants to merge 2 commits intok8snetworkplumbingwg:masterfrom
pliurh:kubeconfig

Conversation

@pliurh
Copy link
Collaborator

@pliurh pliurh commented Mar 4, 2026

Listing all pods across all namespaces during bootstrap is expensive in large clusters and unnecessary since the result is discarded. Use the lightweight /version endpoint to validate connectivity instead.

@pliurh pliurh requested a review from bpickard22 March 4, 2026 03:43
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request optimizes the kubeconfig validation process during the bootstrap phase. Instead of performing a resource-intensive operation like listing all pods, which can be slow and unnecessary in large Kubernetes clusters, the system now uses a more efficient method of querying the API server's lightweight /version endpoint. This change enhances the overall efficiency and responsiveness of the client's connection validation.

Highlights

  • Performance Optimization: Replaced the expensive operation of listing all pods across all namespaces with a lightweight query to the /version endpoint for kubeconfig validation during bootstrap, significantly improving performance in large clusters.
  • New Helper Function: Introduced a new helper function validateKubeconfigConn to encapsulate the logic for checking kubeconfig connectivity using the /version endpoint.
  • Dependency Reduction: Removed the metav1 import as it is no longer required after switching from ListOptions to the /version endpoint check.
Changelog
  • pkg/k8sclient/kubeconfig.go
    • Removed unused metav1 import.
    • Added validateKubeconfigConn function to check kubeconfig connectivity using the /version endpoint.
    • Updated PerNodeK8sClient to utilize the new validateKubeconfigConn function for kubeconfig validation.
    • Adjusted error logging messages to reflect the new validation method.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 improves performance by replacing an expensive pod listing operation with a lightweight server version check for kubeconfig validation. This is a beneficial change, especially for large clusters. I have identified one critical issue where an unhandled error could lead to a panic.

if current != nil {
cfg = config
}
if current != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this jumps where we set the config outside of where we were previously validating, so previously if we had some error other than unknown authority we would keep the bootstrap kubeconfig instead of the cert based kubeconfig, now we just override the bootstrap either way.

I think this is okay / maybe even an improvement (if we can use the cert based kubeconfig we should), just wanted to make sure this was your intention @pliurh

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The old implementation is buggy. I did some refactory, PTAL.

…ation

Listing all pods across all namespaces during bootstrap is expensive
in large clusters and unnecessary since the result is discarded.
Use the lightweight /version endpoint to validate connectivity instead.

Signed-off-by: Peng Liu <pliu@redhat.com>
Validate the per-node kubeconfig when a current certificate is
available and fall back to the bootstrap kubeconfig only when the
per-node config is no longer trusted.

Also rebuild the derived per-node rest.Config from the reloaded
bootstrap config so TLS settings are preserved and refreshed
consistently.

Signed-off-by: Peng Liu <pliu@redhat.com>
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.

2 participants