Skip to content

Changes made in configuration.py to accept environmental variables #2390

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 2 commits into from
Jun 24, 2025

Conversation

p172913
Copy link
Contributor

@p172913 p172913 commented Apr 29, 2025

What type of PR is this?
/kind bug

What this PR does / why we need it:
This PRs will read environment variables assigned for proxy and no_proxy.

Which issue(s) this PR fixes:
Fixes #2321

Special notes for your reviewer:
Unit test is added kubernetes\base\stream\ws_client_test.py

Does this PR introduce a user-facing change?

Allow configuration.py to read proxy and no_proxy environmental variables

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

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 29, 2025
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 29, 2025
@p172913
Copy link
Contributor Author

p172913 commented Apr 29, 2025

@roycaihw , @fabianvf Please approve my PR

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Apr 30, 2025
@p172913
Copy link
Contributor Author

p172913 commented May 1, 2025

@roycaihw , @fabianvf Please review my PR...

@p172913
Copy link
Contributor Author

p172913 commented May 5, 2025

@roycaihw , @fabianvf Please review my PR...

@roycaihw
Copy link
Member

roycaihw commented May 7, 2025

/assign

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")
Copy link
Member

Choose a reason for hiding this comment

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

This file is generated by the upstream openapi generator. Could you make the change upstream?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have checked https://github.com/OpenAPITools/openapi-generator. We need to change in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/python/configuration.mustache (as it is python code change.). But while I am at it. I observed that there is no no_proxy variable there.
image
I am not sure whether I can add no_proxy variable to it or not. It was removed for some reasons according to this issue OpenAPITools/openapi-generator#20226.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I observed that there is no no_proxy variable there.

This client is based on an old version of the upstream generator. The upstream generator probably had some change to the no_proxy variable since then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of upstreaming the changes can we downstream the changes to files that using configuration.py variables. i.e. python_kubernetes\kubernetes\base\stream\ws_client.py and python_kubernetes\kubernetes\client\rest.py. We can add this change in above files. But I have a doubt will it impact this changes if we use Open-api generator...
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm not sure. From the title "Merge branch 'kubernetes-client:master' into master" it sounds like it was trying to merge the upstream master into your master branch.

An alternative is to open a new PR with a fresh branch, if you cannot delete this commit

Even I cann't delete it. It is not my commit.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@roycaihw Can you check and approve my PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@roycaihw Can you check and approve my PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@roycaihw Can you check and approve my PR

Copy link
Member

Choose a reason for hiding this comment

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

Even though this client is using a old version of the generator, can we first get this change accepted by the upstream generator, and then we can patch this client?

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 20, 2025
@p172913 p172913 requested a review from roycaihw May 27, 2025 07:00
Copy link
Member

@roycaihw roycaihw left a comment

Choose a reason for hiding this comment

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

Please remove the "Merge branch 'kubernetes-client:master' into master" commit to make the commits clear. You may have to start from a new branch to do so.

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")
Copy link
Member

Choose a reason for hiding this comment

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

If both HTTPS_PROXY and HTTP_PROXY are set, does this mean HTTP_PROXY will override HTTPS_PROXY? Is this behavior matching the websocket client behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If both HTTPS_PROXY and HTTP_PROXY are set, HTTP_PROXY will override HTTPS_PROXY. But Web client has only one self.proxy variable. So, I think it will work fine unless user provide both HTTPS_PROXY and HTTP_PROXY. If user needed both variables we need to check that condition. Even then we can just give HTTPS_PROXY priority...

Copy link
Contributor Author

@p172913 p172913 May 30, 2025

Choose a reason for hiding this comment

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

If user need to declare both HTTPS_PROXY and HTTP_PROXY. He need to mention which proxy he is using.

If user declared both HTTPS_PROXY and HTTP_PROXY and he didn't mention then it will choose latest declared.

If we need to give HTTPS_PROXY priority over HTTP_PROXY. Then I need to change the code accordingly....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@roycaihw What is the exact requirement here...?

Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with having override behavior, just want to make sure we are aligned with what websocket client is doing

According to the original issue, websocket client makes use of these env variables, so I wanted to understand if the same override behavior exists there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the original issue (#2321), he gave only one variable HTTPS_PROXY. So, the changes will not override the self.proxy variable.

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

Choose a reason for hiding this comment

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

Similar question here. Does no_proxy override NO_PROXY if both of them are set?

Copy link
Contributor Author

@p172913 p172913 May 28, 2025

Choose a reason for hiding this comment

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

Yes no_proxy override NO_PROXY. But this is for case sensitive environments like macOS . Only if user declared both no_proxy and NO_PROXY. In windows it will treat both as same. So, I added both no_proxy and NO_PROXY. But they are same...

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")
Copy link
Member

Choose a reason for hiding this comment

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

Even though this client is using a old version of the generator, can we first get this change accepted by the upstream generator, and then we can patch this client?

@p172913
Copy link
Contributor Author

p172913 commented May 28, 2025

Please remove the "Merge branch 'kubernetes-client:master' into master" commit to make the commits clear. You may have to start from a new branch to do so.

This commit is reverted back.

@p172913
Copy link
Contributor Author

p172913 commented May 28, 2025

I added a bash script file. This will edit configuration.py file if we create it using new opneapi generator.

Copy link
Member

@roycaihw roycaihw left a comment

Choose a reason for hiding this comment

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

Please squash the commits.

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")
Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with having override behavior, just want to make sure we are aligned with what websocket client is doing

According to the original issue, websocket client makes use of these env variables, so I wanted to understand if the same override behavior exists there.

@@ -1,53 +0,0 @@
# Read the Docs configuration file for Sphinx projects
Copy link
Member

Choose a reason for hiding this comment

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

I think the file deletion is unexpected. Please fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it.

@bachorp
Copy link

bachorp commented Jun 8, 2025

@roycaihw I have been working get this upstream: OpenAPITools/openapi-generator#21394

Edit: I ceased working on it for the time being.

@p172913
Copy link
Contributor Author

p172913 commented Jun 8, 2025

@roycaihw I have been working get this upstream: OpenAPITools/openapi-generator#21394

Oh ok. Then @roycaihw I will remove statement to execute insert_proxy_config.sh from scripts/release.sh. So, that we can execute insert_proxy_config.sh only if needed instead of running always....

@p172913
Copy link
Contributor Author

p172913 commented Jun 9, 2025

@roycaihw I have been working get this upstream: OpenAPITools/openapi-generator#21394

Oh ok. Then @roycaihw I will remove statement to execute insert_proxy_config.sh from scripts/release.sh. So, that we can execute insert_proxy_config.sh only if needed instead of running always....

@roycaihw What do you think...

@roycaihw
Copy link
Member

roycaihw commented Jun 9, 2025

Could you squash the commits? Otherwise LGTM. https://www.kubernetes.dev/docs/guide/github-workflow/#squash-commits

What type of PR is this?
/kind bug

What this PR does / why we need it:
This PRs will read environment variables assigned for proxy and no_proxy.

Update ws_client_test.py

Update configuration.py
What type of PR is this?
/kind bug

What this PR does / why we need it:
This PRs will read environment variables assigned for proxy and no_proxy.

Update configuration.py

Add debug logging doc and example

add .readthedocs.yaml config file

Added

Added insert_proxy_config.sh to edit configuration.py in client

Revert "Added insert_proxy_config.sh to edit configuration.py in client"

This reverts commit b295c2d.

To avoid condition self.no_proxy is already present
@p172913
Copy link
Contributor Author

p172913 commented Jun 10, 2025

Could you squash the commits? Otherwise LGTM. https://www.kubernetes.dev/docs/guide/github-workflow/#squash-commits

@roycaihw squashed commits as per instructions.

@p172913
Copy link
Contributor Author

p172913 commented Jun 12, 2025

Could you squash the commits? Otherwise LGTM. https://www.kubernetes.dev/docs/guide/github-workflow/#squash-commits

@roycaihw squashed commits as per instructions.

@roycaihw please approve my commit.

@p172913
Copy link
Contributor Author

p172913 commented Jun 16, 2025

Could you squash the commits? Otherwise LGTM. https://www.kubernetes.dev/docs/guide/github-workflow/#squash-commits

@roycaihw squashed commits as per instructions.

@roycaihw please approve my commit.

@roycaihw Do i need to add anything to this...?

@p172913 p172913 requested a review from roycaihw June 19, 2025 20:12
@p172913
Copy link
Contributor Author

p172913 commented Jun 23, 2025

@roycaihw Can you please look into my PR. I squashed my commits as you mentioned. Please approve my Pull request....

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 24, 2025
@roycaihw roycaihw added kind/feature Categorizes issue or PR as related to a new feature. and removed kind/bug Categorizes issue or PR as related to a bug. labels Jun 24, 2025
@roycaihw
Copy link
Member

/lgtm
/approve

Thank you!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 24, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: p172913, roycaihw

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 24, 2025
@k8s-ci-robot k8s-ci-robot merged commit 51f4db5 into kubernetes-client:master Jun 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebSocket connections make use of environment vars for PROXY
4 participants