Skip to content

Conversation

@daezaa
Copy link

@daezaa daezaa commented Sep 30, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:

Currently, self.no_proxy is explicitly reset to None after being populated from environment variables (NO_PROXY or no_proxy). This effectively discards the loaded values and prevents no_proxy from being respected when configuring the client.

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.

Which issue(s) this PR fixes:

No issue has been opened yet. Let me know if needed.
Fixes #

Special notes for your reviewer:

  • The change is small but corrects behavior that currently nullifies no_proxy support.
  • Please confirm whether a regression test should be added for this.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

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.
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. labels Sep 30, 2025
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 30, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @daezaa!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Sep 30, 2025
@afshin-paydar
Copy link

lgtm 👍

if os.getenv("no_proxy"): self.no_proxy = os.getenv("no_proxy")
"""Proxy URL
"""
self.no_proxy = None
Copy link
Member

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

Copy link
Author

@daezaa daezaa Oct 9, 2025

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,

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

Copy link

@roccotigger roccotigger Nov 5, 2025

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

Copy link
Author

Choose a reason for hiding this comment

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

@roccotigger

 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:

  1. 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
  1. 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
  1. Run script and validate configuration.py (Make sure no redundant self.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
  1. 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

cc : @roycaihw @yliaog

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?

Copy link
Author

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.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 9, 2025
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 9, 2025
@daniram94
Copy link

LGTM

@daezaa
Copy link
Author

daezaa commented Oct 28, 2025

@yliaog @roycaihw Can you please review this PR?

@yliaog
Copy link
Contributor

yliaog commented Oct 28, 2025

i think you want to change the script, rather than the generated file, otherwise, the generated file will be overridden during next release.

@daezaa
Copy link
Author

daezaa commented Oct 28, 2025

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.

@daezaa
Copy link
Author

daezaa commented Nov 4, 2025

Can we get this reviewed please?

Problem with v33.1.0 is, it doesn't honour HTTP_PROXY/HTTPS_PROXY env var from the client.
v33.1.0...v34.1.0#diff-977bedbaf9339b25749bc96a24266c1fa3e99ab521a835562fe84b2ab87b7001L160

Problem with v34.1.0 is, configuration.proxy from below could now be turned on by above change but configuration.no_proxy is ALWAYS ''. Therefore should_by_pass NO_PROXY wouldn't work as expected.

if configuration.proxy and not should_bypass_proxies(configuration.host, no_proxy=configuration.no_proxy or ''):

@yliaog
Copy link
Contributor

yliaog commented Nov 6, 2025

@daezaa please check #2459 (comment)

@daezaa
Copy link
Author

daezaa commented Nov 10, 2025

#2459 (comment) Comment updated.. thanks

@daezaa daezaa requested a review from roccotigger November 10, 2025 18:17
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: daezaa, roccotigger
Once this PR has been reviewed and has the lgtm label, please assign roycaihw for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants