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

az aks get-credentials throws exception if ~/.kube/config does not contain the expected sections #10812

Closed
FooBarWidget opened this issue Oct 11, 2019 · 15 comments
Assignees
Labels
AKS az aks/acs/openshift customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-author-feedback More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. Service Attention This issue is responsible by Azure service team.

Comments

@FooBarWidget
Copy link

Describe the bug
az aks get-credentials expects ~/.kube/config to contain a clusters, users and contexts section. If even one of them is missing, then the command will bail out with a Python KeyError exception.

To Reproduce
Create ~/.kube/config with the following contents:

apiVersion: v1
clusters: []
kind: Config

Then run:

az aks get-credentials --resource-group SOMETHING --name SOMETHING --overwrite-existing

Actual behavior

The command failed with an unexpected error. Here is the traceback:

'users'
Traceback (most recent call last):
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/knack/cli.py", line 206, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 603, in execute
    raise ex
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 661, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 654, in _run_job
    six.reraise(*sys.exc_info())
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/six.py", line 693, in reraise
    raise value
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 631, in _run_job
    result = cmd_copy(params)
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 306, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/azure/cli/core/__init__.py", line 485, in default_command_handler
    return op(**command_args)
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/azure/cli/command_modules/acs/custom.py", line 1887, in aks_get_credentials
    _print_or_merge_credentials(path, kubeconfig, overwrite_existing, context_name)
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/azure/cli/command_modules/acs/custom.py", line 2775, in _print_or_merge_credentials
    merge_kubernetes_configurations(path, temp_path, overwrite_existing, context_name)
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/azure/cli/command_modules/acs/custom.py", line 1178, in merge_kubernetes_configurations
    _handle_merge(existing, addition, 'users', replace)
  File "/usr/local/Cellar/azure-cli/2.0.74/libexec/lib/python3.7/site-packages/azure/cli/command_modules/acs/custom.py", line 1112, in _handle_merge
    if existing[key] is None:
KeyError: 'users'

To open an issue, please run: 'az feedback'

Expected behavior
I expect the command to succeed, like this:

Merged "SOMETHING" as current context in ~/.kube/config

Environment summary
I was able to reproduce this problem on two different environments.

Environment 1:

  • Install method: Homebrew
  • CLI version: 2.0.74
  • OS: macOS Mojave
  • Shell: bash

Environment 2:

  • Install method: APT (via packages.microsoft.com)
  • CLI version: 2.0.74
  • OS: Ubuntu 16.04 (running inside a Docker container)

Additional context
The problematic line is here:

The code there attempts to check whether the config section exists, but does so in a wrong way. In Python, foo[key] raises an exception if the key doesn't exist, so foo[key] is None makes no sense here. You want foo.get(key) is None which does not raise but returns None if the key does not exist.

@FooBarWidget FooBarWidget changed the title az aks get-credentials errors if ~/.kube/config does not contain the expected sections az aks get-credentials throws exception if ~/.kube/config does not contain the expected sections Oct 11, 2019
@maggiepint maggiepint added AKS az aks/acs/openshift customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Oct 12, 2019
@maggiepint
Copy link

Thanks for the feedback. I have routed to the appropriate team for follow up.

@haroldrandom haroldrandom added AKS az aks/acs/openshift customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Oct 25, 2019
@yonzhan yonzhan added the Service Attention This issue is responsible by Azure service team. label Dec 4, 2019
@ghost
Copy link

ghost commented Dec 4, 2019

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/aks-pm

@jluk
Copy link
Contributor

jluk commented Dec 5, 2019

We're looking into this issue - @palma21 fyi

@deepakk11
Copy link

Any update on this issue?

@yankeexe
Copy link

@maggiepint Any update on the issue?

@maperr
Copy link

maperr commented Aug 25, 2020

Also need update one this.

@chriskuech
Copy link

Is there anything we can do to mitigate?

@fgbaezp
Copy link

fgbaezp commented Aug 10, 2021

Its gonna be 2 years now, no updates?

@yonzhan
Copy link
Collaborator

yonzhan commented Aug 10, 2021

ask service team should take a look

@navba-MSFT
Copy link
Contributor

@phealy Could you please let us know if you have any update on this issue ?

@navba-MSFT
Copy link
Contributor

@FooBarWidget Apologies for the late reply. We will get back to you once we have an update.

@phealy Please let us know if you had a chance to look into this issue and provide the details on this github thread

@amul047
Copy link

amul047 commented Mar 26, 2022

I don't know how to get this prioritized, it looks like people have already been complaining for ages...

@navba-MSFT
Copy link
Contributor

@amul047 Until a solution is provided, Could you please follow the workaround mentioned here and here and check if that helps ?

In the meantime, I am tagging the AKS Service PM here to check if they can prioritize this.

@Azure/aks-pm and @phealy Could you please look into this on priority and provide an update on this ? Awaiting your reply.

@navba-MSFT
Copy link
Contributor

@amul047 Could you please let me know if you have tried to workaround mentioned here and here ? Awaiting your reply.

@navba-MSFT navba-MSFT added the needs-author-feedback More information is needed from author to address the issue. label May 5, 2022
@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label May 12, 2022
@ghost
Copy link

ghost commented May 12, 2022

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

@ghost ghost closed this as completed May 27, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AKS az aks/acs/openshift customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-author-feedback More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests