`az aks get-credentials` throws exception if ~/.kube/config does not contain the expected sections
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: https://github.com/Azure/azure-cli/blob/0d4a040f56d481afa6b3d8cd1319b51bde9dd69a/src/azure-cli/azure/cli/command_modules/acs/custom.py#L1112
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.
Thanks for the feedback. I have routed to the appropriate team for follow up.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/aks-pm
We're looking into this issue - @palma21 fyi
Any update on this issue?
@maggiepint Any update on the issue?
Also need update one this.
Is there anything we can do to mitigate?
Its gonna be 2 years now, no updates?
ask service team should take a look
@phealy Could you please let us know if you have any update on this issue ?
@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
I don't know how to get this prioritized, it looks like people have already been complaining for ages...
@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.
@amul047 Could you please let me know if you have tried to workaround mentioned here and here ? Awaiting your reply.
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!