-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add proxy support to Kubernetes client configuration in get_client #2291
base: main
Are you sure you want to change the base?
Add proxy support to Kubernetes client configuration in get_client #2291
Conversation
WalkthroughThe changes involve modifying the Changes
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (4)
✨ Finishing Touches
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
Report bugs in Issues The following are automatically added:
Available user actions:
Supported /retest check runs
Supported labels
|
/verified |
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
🧹 Nitpick comments (1)
ocp_resources/resource.py (1)
124-129
: LGTM! Proxy configuration implementation is robust.The implementation correctly handles proxy configuration through environment variables, following standard practices. Consider adding a debug log when no proxy is found to improve observability.
client_configuration = client_configuration or client.Configuration() proxy = os.environ.get("HTTPS_PROXY") or os.environ.get("HTTP_PROXY") +if not proxy: + LOGGER.debug("No proxy configuration found in environment variables") if proxy: LOGGER.info(f"Trying to get client using proxy {proxy}") client_configuration.proxy = proxy
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ocp_resources/resource.py
(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: tox
- GitHub Check: python-module-install
🔇 Additional comments (2)
ocp_resources/resource.py (2)
83-87
: LGTM! Function signature changes are well-structured.The new
client_configuration
parameter is properly typed and documented, allowing for flexible client configuration injection.Also applies to: 103-103
132-134
: LGTM! Client creation properly utilizes the configuration.The updated client creation correctly passes the configuration object to
new_client_from_config
.
043a0f7
to
e6d27e6
Compare
/verified |
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: 1
🧹 Nitpick comments (1)
ocp_resources/resource.py (1)
102-102
: Enhance the docstring for better clarity.The documentation for
client_configuration
should be more descriptive to help users understand its purpose and usage.- client_configuration (kubernetes.client.Configuration): The kubernetes.client.Configuration to set configs to. + client_configuration (kubernetes.client.Configuration): Optional custom Kubernetes client configuration. + Use this to provide pre-configured settings such as proxy configuration, SSL certificates, + API keys, etc. If not provided, a new configuration will be created. + Example: + config = kubernetes.client.Configuration() + config.proxy = "http://proxy.example.com:8080" + client = get_client(client_configuration=config)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ocp_resources/resource.py
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: python-module-install
- GitHub Check: tox
🔇 Additional comments (2)
ocp_resources/resource.py (2)
82-86
: LGTM! Function signature changes are well-structured.The new
client_configuration
parameter is properly typed and maintains backward compatibility.
131-133
: LGTM! Client configuration is properly utilized.The
client_configuration
is correctly passed tonew_client_from_config
, ensuring consistent configuration throughout the client creation process.
e6d27e6
to
791e1b5
Compare
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
🧹 Nitpick comments (2)
README.md (2)
100-101
: Improve formatting consistency of environment variables.For better readability and consistency with markdown formatting:
-Set the environment variable OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY=<any value> -This enables the proxy without requiring the use_proxy argument when creating the client. +Set the environment variable `OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY=<any value>` +This enables proxy support without requiring the `use_proxy` argument when creating the client.
103-104
: Enhance clarity of proxy URL configuration.For better clarity and consistency:
-Define the HTTPS_PROXY or HTTP_PROXY environment variable for the proxy URL. -If neither is set, a ValueError will be raised. +Define either `HTTPS_PROXY` or `HTTP_PROXY` environment variable with your proxy URL: +```bash +export HTTPS_PROXY="http://proxy.example.com:8080" +# or +export HTTP_PROXY="http://proxy.example.com:8080" +``` +If neither variable is set when proxy is enabled, a `ValueError` will be raised.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
README.md
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: python-module-install
- GitHub Check: tox
🔇 Additional comments (1)
README.md (1)
96-105
: LGTM! The proxy configuration section is well-structured.The section clearly explains how to enable and configure proxy support for the client.
/verified |
/verified |
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
🧹 Nitpick comments (3)
README.md (3)
96-110
: LGTM! Consider adding more details for better user experience.The proxy configuration documentation is clear and well-structured. Consider these enhancements:
- Add a Python code example showing the
use_proxy=True
argument usage- Specify the order of precedence between HTTPS_PROXY and HTTP_PROXY
- Include a troubleshooting section for common proxy issues
Example additions:
### Usage Example ```python from ocp_resources.resource import get_client # Enable proxy via argument client = get_client(use_proxy=True)Proxy Precedence
When both proxy variables are set, HTTPS_PROXY takes precedence over HTTP_PROXY.
Troubleshooting
- Ensure proxy URL is correctly formatted (e.g., includes protocol)
- Verify proxy server is accessible
- Check proxy authentication if required
--- `100-101`: **Improve environment variable documentation format.** The environment variable documentation could be clearer with consistent formatting and explicit value examples. ```diff -1. Set the `use_proxy` argument to `True` when creating the client or set the environment variable `OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY=<any value>` -This enables the proxy without requiring the `use_proxy` argument when creating the client. +1. Set the `use_proxy` argument to `True` when creating the client or set the environment variable: +```bash +export OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY="true" # Any non-empty value works +``` +This enables the proxy without requiring the `use_proxy` argument when creating the client.
103-109
: Add proxy authentication and HTTPS details.The proxy URL examples could benefit from additional details about authentication and HTTPS support.
2. Define either `HTTPS_PROXY` or `HTTP_PROXY` environment variable with your proxy URL: ```bash export HTTPS_PROXY="http://proxy.example.com:8080" # or export HTTP_PROXY="http://proxy.example.com:8080" +# With authentication: +export HTTPS_PROXY="http://username:[email protected]:8080" +# For HTTPS proxy: +export HTTPS_PROXY="https://proxy.example.com:8443"</blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 595cea710827aeb43f983fd17ffdf708e34edf0b and 84b9023cc47ce527bc9b29a785983924e22320eb. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `README.md` (1 hunks) </details> <details> <summary>⏰ Context from checks skipped due to timeout of 90000ms (2)</summary> * GitHub Check: python-module-install * GitHub Check: tox </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
/verified |
ocp_resources/resource.py
Outdated
@@ -115,8 +121,25 @@ def get_client( | |||
# If `KUBECONFIG` environment variable is set via code, the `KUBE_CONFIG_DEFAULT_LOCATION` will be None since | |||
# is populated during import which comes before setting the variable in code. | |||
config_file = config_file or os.environ.get("KUBECONFIG", "~/.kube/config") | |||
client_configuration = None |
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.
client_configuration
can be passed via kwargs
, this will overwrite what the user sends.
set only if not passed
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.
Thanks, done.
/verified |
for more information, see https://pre-commit.ci
/verified |
Short description:
Add proxy support to Kubernetes client configuration in get_client
More details:
This update modifies the get_client function to support setting a proxy for the Kubernetes client configuration. The client_configuration argument is introduced to allow passing a client.Configuration object directly, and if not provided, it defaults to creating a new configuration instance. Additionally, if the HTTPS_PROXY or HTTP_PROXY environment variables are set, the proxy is applied to the Kubernetes client configuration.
Introduced dynamic proxy enablement by reading the OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY environment variable.
If use_proxy is enabled, the client will fetch the proxy URL from HTTPS_PROXY or HTTP_PROXY environment variables.
A ValueError is raised if proxy variables are not set when use_proxy is enabled.
Updated README.md with instructions on using the new proxy enablement feature.
What this PR does / why we need it:
This solution is preferred over requiring the caller to set the client.Configuration for each client instance creation. Doing so would necessitate updating every instance where the client is created, which would be less efficient and error-prone.
Which issue(s) this PR fixes:
https://issues.redhat.com/browse/CNV-46351
Special notes for reviewer:
A similar solution was previously proposed in PR #2066 , but it was not accepted at the time. This PR aims to provide additional reasoning and demonstrate why this approach is the most effective.
This change is especially useful in environments where proxies are required, and it simplifies the client setup process while minimizing the chances of errors.
Note:
We can also promote this upstream PR in kubernetes-client, which is a good solution:
kubernetes-client/python#2182
Bug:
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Documentation