Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle cases where the kubeconfig contains multiple paths #288

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

hcavarsan
Copy link
Owner

fix: handle cases where the kubeconfig contains multiple paths

@hcavarsan hcavarsan added the bug Something isn't working label Aug 20, 2024
@hcavarsan hcavarsan self-assigned this Aug 20, 2024
Copy link
Contributor

coderabbitai bot commented Aug 20, 2024

Walkthrough

The recent changes primarily enhance the kubeconfig management in the system, allowing retrieval of multiple kubeconfig paths and improving error handling across various functions. New functionalities, such as listing Kubernetes contexts, have been introduced along with significant updates to client creation processes. Overall, the modifications aim to increase flexibility, maintainability, and robustness of the codebase relating to Kubernetes configuration and management.

Changes

Files Change Summary
crates/kftray-commons/src/utils/config_dir.rs, crates/kftray-portforward/src/client.rs The kubeconfig path retrieval is updated to support multiple paths. The get_default_kubeconfig_path function is replaced with get_kubeconfig_paths, which returns a vector of valid paths. The client creation function is modified for better error handling and support for multiple contexts.
crates/kftray-portforward/src/core.rs, crates/kftray-portforward/src/port_forward.rs The client initialization logic is refined to improve error handling, ensuring that invalid clients are properly reported. The handling of context names is adjusted for clarity and robustness.
crates/kftray-server/src/udp_over_tcp_proxy.rs, crates/kftray-portforward/src/models/kube.rs, crates/kftray-portforward/src/pod_finder.rs Minor changes include comment removals for clarity without impacting functionality.
crates/kftray-tauri/src/commands/kubecontext.rs A new command function list_kube_contexts is added, and existing functions are updated to improve error handling during client creation, enhancing robustness and maintainability.
frontend/src/components/AddConfigModal/index.tsx, frontend/src/components/AddConfigModal/utils.ts Comments removed for simplification and clarity, with no impact on code functionality or logic.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hcavarsan hcavarsan merged commit 542b20d into main Aug 20, 2024
7 checks passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6c057a7 and 0da436d.

Files ignored due to path filters (4)
  • Cargo.lock is excluded by !**/*.lock, !**/*.lock
  • crates/kftray-commons/Cargo.toml is excluded by !**/*.toml
  • crates/kftray-portforward/Cargo.toml is excluded by !**/*.toml
  • crates/kftui/Cargo.toml is excluded by !**/*.toml
Files selected for processing (10)
  • crates/kftray-commons/src/utils/config_dir.rs (4 hunks)
  • crates/kftray-portforward/src/client.rs (2 hunks)
  • crates/kftray-portforward/src/core.rs (1 hunks)
  • crates/kftray-portforward/src/models/kube.rs (1 hunks)
  • crates/kftray-portforward/src/pod_finder.rs (1 hunks)
  • crates/kftray-portforward/src/port_forward.rs (2 hunks)
  • crates/kftray-server/src/udp_over_tcp_proxy.rs (1 hunks)
  • crates/kftray-tauri/src/commands/kubecontext.rs (13 hunks)
  • frontend/src/components/AddConfigModal/index.tsx (1 hunks)
  • frontend/src/components/AddConfigModal/utils.ts (3 hunks)
Files skipped from review due to trivial changes (5)
  • crates/kftray-portforward/src/models/kube.rs
  • crates/kftray-portforward/src/pod_finder.rs
  • crates/kftray-server/src/udp_over_tcp_proxy.rs
  • frontend/src/components/AddConfigModal/index.tsx
  • frontend/src/components/AddConfigModal/utils.ts
Additional comments not posted (16)
crates/kftray-portforward/src/client.rs (7)

22-23: Update function signature and return type.

The function create_client_with_specific_context now takes context_name as Option<&str> and returns Result<(Option<Client>, Option<Kubeconfig>, Vec<String>)>. This change allows handling cases where no specific context is provided and returns additional context information.


24-28: Handle multiple kubeconfig paths.

The logic now retrieves multiple kubeconfig paths using get_kubeconfig_paths(). This enhances the function's ability to handle multiple configurations.


30-31: Initialize error and context collection.

The initialization of errors and all_contexts vectors is appropriate for collecting error messages and available contexts from multiple kubeconfig files.


33-43: Iterate over kubeconfig paths and handle success/failure.

The loop iterates over each kubeconfig path, attempting to read and log the result. This structure effectively manages multiple paths and collects contexts.


45-97: Conditional context configuration and error handling.

The logic attempts to create a configuration for a specified context and handles errors by collecting them. This improves robustness by providing detailed error messages.


108-115: Return contexts if no specific context is provided.

If context_name is None, the function returns all contexts found. This is a logical fallback to provide available context information.


118-123: Add helper function list_contexts.

The list_contexts function extracts context names from a kubeconfig, streamlining context retrieval. This is a useful addition for modularity.

crates/kftray-commons/src/utils/config_dir.rs (2)

58-82: Support multiple kubeconfig paths.

The get_kubeconfig_paths function now handles multiple paths by checking the KUBECONFIG environment variable and defaulting to ~/.kube/config. This increases flexibility in configuration handling.


214-234: Update tests for multiple kubeconfig paths.

The test test_get_kubeconfig_paths verifies the new functionality by checking both custom and default paths. This ensures robustness in handling multiple configurations.

crates/kftray-tauri/src/commands/kubecontext.rs (5)

28-55: Introduce list_kube_contexts function.

The new function retrieves Kubernetes contexts from a kubeconfig and handles errors effectively. This addition enhances the ability to manage contexts.


Line range hint 57-92: Improve error handling in list_pods.

The function now checks if the client was successfully created, preventing null reference errors. This improves robustness.


Line range hint 108-126: Enhance client creation in list_namespaces.

Similar improvements in error handling ensure the client is valid before proceeding. This increases reliability.


Line range hint 142-160: Refine client creation in list_services.

The updated logic ensures the client is valid, enhancing error management and robustness.


Line range hint 172-261: Streamline port listing in list_ports.

The function uses functional programming constructs for better readability and efficiency in collecting port information.

crates/kftray-portforward/src/port_forward.rs (1)

60-72: Enhance client creation logic in PortForward::new.

The updated logic checks if the client was successfully created and provides descriptive error messages if not. This improves robustness and error reporting.

crates/kftray-portforward/src/core.rs (1)

558-573: Improve client creation and error handling in deploy_and_forward_pod.

The function now explicitly checks if the client is created and raises an error if not. This adds robustness and clarity to the client configuration process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant