-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix no_proxy reset in configuration.py #2459
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
base: master
Are you sure you want to change the base?
Conversation
This commit removes the redundant assignment to `None`, ensuring that the `no_proxy` environment variable is preserved and proxy bypass settings are applied as expected.
|
Welcome @daezaa! |
|
lgtm 👍 |
| if os.getenv("no_proxy"): self.no_proxy = os.getenv("no_proxy") | ||
| """Proxy URL | ||
| """ | ||
| self.no_proxy = 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.
The change LGTM
This file is generated by openapi-generator. We also need to update the hotfix script to keep the patch: https://github.com/kubernetes-client/python/blob/master/scripts/insert_proxy_config.sh
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.
@roycaihw Thanks for the input. The script looks fine to me and no need changes but if it was executed on v33.1.0,
python/scripts/insert_proxy_config.sh
Lines 49 to 76 in 5f6cdb2
| if [ -z "$NO_PROXY_LINE" ]; then | |
| # self.no_proxy = None is not present → insert full block after self.proxy = None | |
| BLOCK+="${INDENT}# Load proxy from environment variables (if set)\n" | |
| BLOCK+="${INDENT}if os.getenv(\"HTTPS_PROXY\"): self.proxy = os.getenv(\"HTTPS_PROXY\")\n" | |
| BLOCK+="${INDENT}if os.getenv(\"https_proxy\"): self.proxy = os.getenv(\"https_proxy\")\n" | |
| BLOCK+="${INDENT}if os.getenv(\"HTTP_PROXY\"): self.proxy = os.getenv(\"HTTP_PROXY\")\n" | |
| BLOCK+="${INDENT}if os.getenv(\"http_proxy\"): self.proxy = os.getenv(\"http_proxy\")\n" | |
| BLOCK+="${INDENT}self.no_proxy = None\n" | |
| BLOCK+="${INDENT}# Load no_proxy from environment variables (if set)\n" | |
| BLOCK+="${INDENT}if os.getenv(\"NO_PROXY\"): self.no_proxy = os.getenv(\"NO_PROXY\")\n" | |
| BLOCK+="${INDENT}if os.getenv(\"no_proxy\"): self.no_proxy = os.getenv(\"no_proxy\")" | |
| sed -i "${PROXY_LINE}a $BLOCK" "$CONFIG_FILE" | |
| echo "Inserted full proxy + no_proxy block after 'self.proxy = None'." | |
| else | |
| # self.no_proxy = None exists → insert only env logic after that | |
| BLOCK+="${INDENT}# Load proxy from environment variables (if set)\n" | |
| BLOCK+="${INDENT}if os.getenv(\"HTTPS_PROXY\"): self.proxy = os.getenv(\"HTTPS_PROXY\")\n" | |
| BLOCK+="${INDENT}if os.getenv(\"https_proxy\"): self.proxy = os.getenv(\"https_proxy\")\n" | |
| BLOCK+="${INDENT}if os.getenv(\"HTTP_PROXY\"): self.proxy = os.getenv(\"HTTP_PROXY\")\n" | |
| BLOCK+="${INDENT}if os.getenv(\"http_proxy\"): self.proxy = os.getenv(\"http_proxy\")\n" | |
| BLOCK+="${INDENT}# Load no_proxy from environment variables (if set)\n" | |
| BLOCK+="${INDENT}if os.getenv(\"NO_PROXY\"): self.no_proxy = os.getenv(\"NO_PROXY\")\n" | |
| BLOCK+="${INDENT}if os.getenv(\"no_proxy\"): self.no_proxy = os.getenv(\"no_proxy\")" | |
| sed -i "${NO_PROXY_LINE}a $BLOCK" "$CONFIG_FILE" | |
| echo "Inserted environment block after 'self.no_proxy = None'." | |
| fi |
the
else block should've ran so that there would be no duplicates of self.no_proxy = None. However, somehow, if [ -z "$NO_PROXY_LINE" ]; then has ran even though there was self.no_proxy = None existed.
Nevertheless, I am revising the PR with the result of executing instert_proxy_config.sh script on v33.1.0 tag.
Please re-review
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.
the script is not handling deleting the self.no_proxy = None when it appends the block to self.proxy section
something like the following is needed
BLOCK=""
NOPROXY_BLOCK=""
if [ -z "$NO_PROXY_LINE" ]; then
# self.no_proxy = None is not present → insert full block after self.proxy = None
BLOCK+="${INDENT}# Load proxy from environment variables (if set)\n"
BLOCK+="${INDENT}if os.getenv(\"HTTPS_PROXY\"): self.proxy = os.getenv(\"HTTPS_PROXY\")\n"
BLOCK+="${INDENT}if os.getenv(\"https_proxy\"): self.proxy = os.getenv(\"https_proxy\")\n"
BLOCK+="${INDENT}if os.getenv(\"HTTP_PROXY\"): self.proxy = os.getenv(\"HTTP_PROXY\")\n"
BLOCK+="${INDENT}if os.getenv(\"http_proxy\"): self.proxy = os.getenv(\"http_proxy\")\n"
sed -i "${PROXY_LINE}a $BLOCK" "$CONFIG_FILE"
NOPROXY_BLOCK+="${INDENT}# Load no_proxy from environment variables (if set)\n"
NOPROXY_BLOCK+="${INDENT}if os.getenv(\"NO_PROXY\"): self.no_proxy = os.getenv(\"NO_PROXY\")\n"
NOPROXY_BLOCK+="${INDENT}if os.getenv(\"no_proxy\"): self.no_proxy = os.getenv(\"no_proxy\")"
sed -i "${NO_PROXY_LINE}a $NOPROXY_BLOCK" "$CONFIG_FILE"
echo "Inserted proxy block after 'self.proxy = None'. and no_proxy block after 'self.no_proxy = None'."
else
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.
NO_PROXY_LINE=$(grep -n "^[[:space:]]*self\.no_proxy[[:space:]]*=[[:space:]]*None" "$CONFIG_FILE" | cut -d: -f1)
# If self.no_proxy = None is not present
if [ -z "$NO_PROXY_LINE" ]; then
...
From your suggestion.. If NO_PROXY_LINE is empty, I don't think sed -i "${NO_PROXY_LINE}a $NOPROXY_BLOCK" "$CONFIG_FILE" is valid and you would need to put self.no_proxy = None
I honestly don't see a problem with existing script.. If you try this script on v33.1.0, it works fine and the result of it is the pull request I made...
Please let me know if I am mistaken.
TEST DONE
Procedure:
- Clone and check out to v33.1.0
$ git clone https://github.com/kubernetes-client/python.git
$ cd python
$ git checkout v33.1.0
$ git branch
* (HEAD detached at v33.1.0)
master
- Download insert_proxy_config.sh in master branch
$ cd scripts
$ curl -fsSL -o insert_proxy_config.sh https://raw.githubusercontent.com/kubernetes-client/python/master/scripts/insert_proxy_config.sh
$ chmod +x insert_proxy_config.sh
- Run script and validate
configuration.py(Make sure no redundantself.no_proxy = None)
$ ./insert_proxy_config.sh
Inserted 'import os' after existing imports in <my_directory>/python/scripts/../kubernetes/client/configuration.py.
Inserted environment block after 'self.no_proxy = None'.
$ cat ../kubernetes/client/configuration.py | grep -A 20 " self.proxy = None"
self.proxy = None
"""Proxy URL
"""
self.no_proxy = None
# Load proxy from environment variables (if set)
if os.getenv("HTTPS_PROXY"): self.proxy = os.getenv("HTTPS_PROXY")
if os.getenv("https_proxy"): self.proxy = os.getenv("https_proxy")
if os.getenv("HTTP_PROXY"): self.proxy = os.getenv("HTTP_PROXY")
if os.getenv("http_proxy"): self.proxy = os.getenv("http_proxy")
# Load no_proxy from environment variables (if set)
if os.getenv("NO_PROXY"): self.no_proxy = os.getenv("NO_PROXY")
if os.getenv("no_proxy"): self.no_proxy = os.getenv("no_proxy")
"""bypass proxy for host in the no_proxy list.
"""
self.proxy_headers = None
"""Proxy headers
"""
self.safe_chars_for_path_param = ''
"""Safe chars for path_param
"""
self.retries = None
$ cat ../kubernetes/client/configuration.py | grep "self.no_proxy = None"
self.no_proxy = None
- Re run script for the future release
$ ./insert_proxy_config.sh
'import os' already present; no changes made.
Proxy environment code already present; no changes made.
$ cat ../kubernetes/client/configuration.py | grep -A 20 " self.proxy = None"
self.proxy = None
"""Proxy URL
"""
self.no_proxy = None
# Load proxy from environment variables (if set)
if os.getenv("HTTPS_PROXY"): self.proxy = os.getenv("HTTPS_PROXY")
if os.getenv("https_proxy"): self.proxy = os.getenv("https_proxy")
if os.getenv("HTTP_PROXY"): self.proxy = os.getenv("HTTP_PROXY")
if os.getenv("http_proxy"): self.proxy = os.getenv("http_proxy")
# Load no_proxy from environment variables (if set)
if os.getenv("NO_PROXY"): self.no_proxy = os.getenv("NO_PROXY")
if os.getenv("no_proxy"): self.no_proxy = os.getenv("no_proxy")
"""bypass proxy for host in the no_proxy list.
"""
self.proxy_headers = None
"""Proxy headers
"""
self.safe_chars_for_path_param = ''
"""Safe chars for path_param
"""
self.retries = None
$ cat ../kubernetes/client/configuration.py | grep "self.no_proxy = None"
self.no_proxy = 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.
I was unable to run scripts/update-client.sh. The closest I could come was to use the v33.1.0 version.
@daezaa Your analysis is correct that the script will operate correctly without changes.
How did the wrong changes make it into v34.1.0?
How to ensure they are corrected in the next released version?
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.
How did the wrong changes make it into v34.1.0?
Well, that is my question too. :(
How to ensure they are corrected in the next released version?
Tried re-running the script and the file was conserved.
$ ./insert_proxy_config.sh
'import os' already present; no changes made.
Proxy environment code already present; no changes made.
|
LGTM |
|
i think you want to change the script, rather than the generated file, otherwise, the generated file will be overridden during next release. |
@yliaog #2459 (comment) Please check my comment here. The script itself is looking good. |
|
Can we get this reviewed please? Problem with Problem with python/kubernetes/client/rest.py Line 90 in fe1a331
|
|
@daezaa please check #2459 (comment) |
|
#2459 (comment) Comment updated.. thanks |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: daezaa, roccotigger The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
What this PR does / why we need it:
Currently,
self.no_proxyis explicitly reset toNoneafter being populated from environment variables (NO_PROXYorno_proxy). This effectively discards the loaded values and preventsno_proxyfrom being respected when configuring the client.This commit removes the redundant assignment to
None, ensuring that theno_proxyenvironment variable is preserved and proxy bypass settings are applied as expected.Which issue(s) this PR fixes:
No issue has been opened yet. Let me know if needed.
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: