Skip to content
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

[AKS] az aks get-credentials: Fix the command error when KUBECONFIG is empty #23000

Merged
merged 2 commits into from
Jun 24, 2022
Merged
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: 6 additions & 1 deletion src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,12 @@ def aks_get_credentials(cmd, client, resource_group_name, name, admin=False,
# in which case we ignore the KUBECONFIG variable
# KUBECONFIG can be colon separated. If we find that condition, use the first entry
if "KUBECONFIG" in os.environ and path == os.path.join(os.path.expanduser('~'), '.kube', 'config'):
path = os.environ["KUBECONFIG"].split(":")[0]
kubeconfig_path = os.environ["KUBECONFIG"].split(":")[0]
if kubeconfig_path:
logger.info("The default path '%s' is replaced by '%s' defined in KUBECONFIG.", path, kubeconfig_path)
path = kubeconfig_path
else:
logger.warning("Invalid path '%s' defined in KUBECONFIG.", kubeconfig_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why just print the warning log instead of raising an exception?

Copy link
Member Author

Choose a reason for hiding this comment

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

Personally, I think there are some usage scenarios where the user has multiple kubeconfig files, then sets the environment variable KUBECONFIG to point to a specific kubeconfig file to perform some operatations, and sometimes leaves KUBECONFIG empty to operate with the kubeconfig located in the default path (~/.kube/config).

I hope this change is that when the user sets KUBECONFIG to be empty, the kubeconfig of the cluster can also be successfully downloaded to the default location.

More discussions are welcome:)

Copy link
Contributor

Choose a reason for hiding this comment

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

Make sense!


if not credentialResults:
raise CLIError("No Kubernetes credentials found.")
Expand Down