Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions kubernetes/client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,17 @@ def __init__(self, host="http://localhost",
"""

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")
self.no_proxy = None
# 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")
"""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.

"""bypass proxy for host in the no_proxy list.
"""
self.proxy_headers = None
Expand Down