Skip to content

fix: Use HTTP_PROXY and HTTPS_PROXY environment variables for proxy #2397

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

Merged
merged 8 commits into from
May 11, 2025

Conversation

myakove
Copy link
Collaborator

@myakove myakove commented May 8, 2025

Use the same proxy configuration as the http and https protocols.

Summary by CodeRabbit

  • Documentation

    • Updated proxy configuration instructions to simplify the process; users now only need to set the HTTPS_PROXY or HTTP_PROXY environment variable.
  • Bug Fixes

    • Simplified and unified proxy handling so that proxy settings are automatically applied from environment variables if present.
  • Tests

    • Removed tests related to deprecated proxy environment variable checks.
    • Added tests to verify client proxy configuration and precedence behavior.
    • Refactored test fixtures for improved clarity and scope.

Use the same proxy configuration as the `http` and `https` protocols.
Copy link

coderabbitai bot commented May 8, 2025

"""

Walkthrough

The proxy configuration logic was simplified across documentation, implementation, and tests. Proxy enablement now relies solely on the presence of HTTPS_PROXY or HTTP_PROXY environment variables, removing the need for a dedicated flag. Related error checks and tests were removed, and the client initialization logic was streamlined accordingly.

Changes

Files / Groups Change Summary
README.md Updated documentation to remove the need for OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY and clarify proxy setup using only HTTPS_PROXY or HTTP_PROXY.
ocp_resources/resource.py Refactored get_client to always set proxy from environment variables if present, removed explicit proxy enablement flag and related error checks, and unified client creation logic. Added new parameters to get_client and improved fallback handling. Updated function signatures to allow None for config_file and context.
tests/test_resources.py Split and refactored fixtures, removed tests for proxy enablement flag and conflict, and added new tests verifying proxy configuration using only environment variables and proxy precedence.

Possibly related PRs

Suggested labels

size/M, verified, can-be-merged, approved-myakove

Suggested reviewers

  • rnetser
  • dbasunag
    """

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06faf24 and 2272482.

📒 Files selected for processing (1)
  • ocp_resources/resource.py (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ocp_resources/resource.py
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: conventional-title
  • GitHub Check: tox
  • GitHub Check: python-module-install
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@redhat-qe-bot1
Copy link

Report bugs in Issues

The following are automatically added:

  • Add reviewers from OWNER file (in the root of the repository) under reviewers section.
  • Set PR size label.
  • New issue is created for the PR. (Closed when PR is merged/closed)
  • Run pre-commit if .pre-commit-config.yaml exists in the repo.

Available user actions:

  • To mark PR as WIP comment /wip to the PR, To remove it from the PR comment /wip cancel to the PR.
  • To block merging of PR comment /hold, To un-block merging of PR comment /hold cancel.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To cherry pick a merged PR comment /cherry-pick <target branch to cherry-pick to> in the PR.
    • Multiple target branches can be cherry-picked, separated by spaces. (/cherry-pick branch1 branch2)
    • Cherry-pick will be started when PR is merged
  • To build and push container image command /build-and-push-container in the PR (tag will be the PR number).
    • You can add extra args to the Podman build command
      • Example: /build-and-push-container --build-arg OPENSHIFT_PYTHON_WRAPPER_COMMIT=<commit_hash>
  • To add a label by comment use /<label name>, to remove, use /<label name> cancel
  • To assign reviewers based on OWNERS file use /assign-reviewers
  • To check if PR can be merged use /check-can-merge
  • to assign reviewer to PR use /assign-reviewer @<reviewer>

PR will be approved when the following conditions are met:

  • /approve from one of the approvers.
  • Minimum number of required /lgtm (0) is met.
Approvers and Reviewers
  • Approvers:

    • myakove
    • rnetser
  • Reviewers:

    • dbasunag
    • myakove
    • rnetser
Supported /retest check runs
  • /retest tox: Retest tox
  • /retest python-module-install: Retest python-module-install
  • /retest conventional-title: Retest conventional-title
  • /retest all: Retest all
Supported labels
  • hold
  • verified
  • wip
  • lgtm
  • approve

Copy link

@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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8515dbb and 1b45ed2.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • ocp_resources/resource.py (2 hunks)
  • tests/test_resources.py (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
README.md (1)
Learnt from: EdDev
PR: RedHatQE/openshift-python-wrapper#2291
File: ocp_resources/resource.py:126-126
Timestamp: 2025-01-28T07:25:19.573Z
Learning: The environment variable `OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY` must be set and not empty to override the `use_proxy` parameter in the `get_client` function.
🧬 Code Graph Analysis (1)
ocp_resources/resource.py (1)
tests/test_resources.py (1)
  • client (32-33)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: tox
  • GitHub Check: python-module-install
  • GitHub Check: conventional-title
🔇 Additional comments (8)
ocp_resources/resource.py (3)

104-113: Simplified proxy configuration approach

The code now automatically detects and uses proxy settings from environment variables (HTTPS_PROXY or HTTP_PROXY) if they're available, instead of requiring an explicit proxy enablement flag. This is a cleaner approach as it follows standard environment variable conventions used by other tools.


114-132: Improved client initialization logic

The client initialization code was refactored to be more consistent and maintainable. Creating the client from either a config dictionary or a config file now follows a clear pattern where the configuration is first created, then used to initialize the client.


134-136: Consolidated error handling

The error handling was simplified by consolidating the client creation and wrapping in a DynamicClient within a single try block, which makes the code cleaner and easier to maintain.

tests/test_resources.py (4)

4-4: More specific import improved

Changed from importing the entire kubernetes module to importing only the specific exception needed, which is a good practice for reducing import overhead and improving code clarity.


22-28: Improved test fixture organization

Separated the container configuration retrieval from client creation into two distinct fixtures, improving the test structure by following single responsibility principle. The error message inclusion in the skip reason is also a good addition for better debugging information.


31-33: Simplified client fixture

Client fixture now uses the extracted container configuration from the previous fixture, maintaining a clean separation of concerns and making the test more maintainable.


118-123: Updated test to match new proxy behavior

Added a new test that verifies the proxy handling behavior when environment variables are set. The test correctly expects a ConfigException rather than a ValueError since the proxy configuration is now auto-detected from environment variables.

This test aligns with the new implementation in get_client which automatically sets proxy from environment variables.

README.md (1)

102-109: Documentation updated to match new implementation

The proxy configuration documentation was updated to reflect the simplified approach where users only need to set the HTTPS_PROXY or HTTP_PROXY environment variables without any additional flag.

@myakove
Copy link
Collaborator Author

myakove commented May 8, 2025

/retest tox

Copy link

@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

🧹 Nitpick comments (3)
tests/test_resources.py (3)

119-124: Consider testing HTTP_PROXY as well.

The test confirms that HTTPS_PROXY is correctly used, but according to the implementation in resource.py, HTTP_PROXY is also supported as a fallback. Consider adding another test case to verify HTTP_PROXY works when HTTPS_PROXY isn't set.

 def test_client_with_proxy(monkeypatch, k3scontainer_config):
     proxy = "http://env-proxy.com"
     monkeypatch.setenv(name="HTTPS_PROXY", value=proxy)

     client = get_client(config_dict=k3scontainer_config)
     assert client.configuration.proxy == proxy
+
+
+def test_client_with_http_proxy(monkeypatch, k3scontainer_config):
+    proxy = "http://env-http-proxy.com"
+    monkeypatch.setenv(name="HTTP_PROXY", value=proxy)
+
+    client = get_client(config_dict=k3scontainer_config)
+    assert client.configuration.proxy == proxy

119-124: Verify proxy precedence behavior.

The implementation in resource.py prioritizes HTTPS_PROXY over HTTP_PROXY. Consider adding a test to verify this precedence when both environment variables are set.

+def test_proxy_precedence(monkeypatch, k3scontainer_config):
+    https_proxy = "https://env-https-proxy.com"
+    http_proxy = "http://env-http-proxy.com"
+    monkeypatch.setenv(name="HTTPS_PROXY", value=https_proxy)
+    monkeypatch.setenv(name="HTTP_PROXY", value=http_proxy)
+
+    client = get_client(config_dict=k3scontainer_config)
+    # Verify HTTPS_PROXY takes precedence over HTTP_PROXY
+    assert client.configuration.proxy == https_proxy

119-124:

❓ Verification inconclusive

Test that existing proxy configuration is preserved.

According to the implementation in resource.py, the proxy is only set from environment variables if _client.configuration.proxy is not already set. Consider adding a test to verify this behavior.


🏁 Script executed:

#!/bin/bash
# Check if there's a way to set the proxy in the k3scontainer_config

# First check if k3scontainer_config is used to initialize the client configuration
rg -A 3 "new_client_from_config_dict" --glob "*.py"

# Then check how kubernetes client configuration handles proxy settings
rg -A 5 "Configuration.*proxy" --glob "*.py"

Length of output: 388


I’d like to inspect how the k3scontainer_config fixture and the proxy‐setting logic in get_client are implemented. Running a few focused searches:

#!/bin/bash
# Show how the fixture builds config_dict
rg -n -C3 "def k3scontainer_config" --glob "tests/test_resources.py"

# Locate get_client and its signature
rg -n -C3 "def get_client" --glob "ocp_resources/resource.py"

# Show full context around new_client_from_config_dict invocation
rg -n -C10 "new_client_from_config_dict" --glob "ocp_resources/resource.py"

# Look for any proxy‐related logic in resource.py
rg -n -C5 "HTTPS_PROXY" --glob "ocp_resources/resource.py"
rg -n -C5 ".proxy" --glob "ocp_resources/resource.py"

To confirm whether get_client preserves an existing configuration.proxy and that there isn’t already a test covering it, let’s inspect the implementation and the fixture:

#!/bin/bash
# Show get_client() definition
rg -n -C5 "def get_client" --glob "ocp_resources/resource.py"

# Show new_client_from_config_dict call and surrounding proxy logic
rg -n -C10 "new_client_from_config_dict" --glob "ocp_resources/resource.py"

# Look for any explicit proxy assignments in that file
rg -n -C5 "proxy" --glob "ocp_resources/resource.py"

# Inspect the test fixture to see if it ever injects proxy into config_dict
rg -n -C5 "def k3scontainer_config" --glob "tests/test_resources.py"

Ensure preconfigured proxy isn’t overridden

Based on the logic in ocp_resources/resource.py, get_client should only apply the HTTPS_PROXY environment variable when client.configuration.proxy is unset. Please add a test that confirms an existing proxy value in config_dict isn’t replaced by the environment, for example:

 def test_client_with_proxy(monkeypatch, k3scontainer_config):
     proxy = "http://env-proxy.com"
     monkeypatch.setenv(name="HTTPS_PROXY", value=proxy)
 
     client = get_client(config_dict=k3scontainer_config)
     assert client.configuration.proxy == proxy

+def test_client_preserves_existing_proxy(monkeypatch, k3scontainer_config):
+    existing = "http://custom-proxy.com"
+    # inject a preconfigured proxy into the config dict
+    k3scontainer_config["proxy"] = existing
+    # also set the environment proxy
+    monkeypatch.setenv(name="HTTPS_PROXY", value="http://env-proxy.com")
+
+    client = get_client(config_dict=k3scontainer_config)
+    # ensure the preconfigured proxy remains unchanged
+    assert client.configuration.proxy == existing
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1d56e5 and 5ff8731.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • tests/test_resources.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/test_resources.py (1)
ocp_resources/resource.py (1)
  • get_client (79-150)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: tox
  • GitHub Check: conventional-title
  • GitHub Check: python-module-install
🔇 Additional comments (3)
tests/test_resources.py (3)

1-2: Good practice using from __future__ import annotations.

This import enables postponed evaluation of annotations, avoiding potential circular import issues and allowing for more flexible type annotations. This is especially useful for self-referencing types or forward references.


23-30: Good refactoring of the K3S container fixture.

Splitting the original client fixture into separate k3scontainer_config and client fixtures improves modularity and test isolation. The improved error message in the DockerException catch block provides more context when tests are skipped.


32-34: Good separation of concerns in fixtures.

Using the k3scontainer_config fixture as a dependency for the client fixture creates a clear separation of concerns and improves test maintainability. Changing the scope to "class" is appropriate for the test structure.

@redhat-qe-bot redhat-qe-bot requested a review from rnetser May 8, 2025 13:07
@rabin-io
Copy link

/verified

@myakove
Copy link
Collaborator Author

myakove commented May 11, 2025

/approve

@myakove myakove enabled auto-merge (squash) May 11, 2025 11:35
@myakove myakove merged commit 96ba312 into main May 11, 2025
6 of 7 checks passed
@myakove myakove deleted the use-http-s-proxy branch May 11, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants