-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Conversation
WalkthroughThe 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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this 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
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 takescontext_name
asOption<&str>
and returnsResult<(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
andall_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
isNone
, the function returns all contexts found. This is a logical fallback to provide available context information.
118-123
: Add helper functionlist_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 theKUBECONFIG
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
: Introducelist_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 inlist_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 inlist_namespaces
.Similar improvements in error handling ensure the client is valid before proceeding. This increases reliability.
Line range hint
142-160
: Refine client creation inlist_services
.The updated logic ensures the client is valid, enhancing error management and robustness.
Line range hint
172-261
: Streamline port listing inlist_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 inPortForward::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 indeploy_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.
fix: handle cases where the kubeconfig contains multiple paths