Azure / Azure/azure-cli-extensions
`az connectedk8s connect` fails ungracefully with `http.client.IncompleteRead` error when installing helm client
- Dominant language
- Python
- Stars
- 454
- Forks
- 1.7k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 64
Description
### Related command
`az connectedk8s connect --name andrewlee-k8s --resource-group andrewlee-08mar --location eastus'`
### Extension name (the extension in question)
connectedk8s (Version 1.3.7)
azure-cli 2.38.0
### Description of issue (in as much detail as possible)
The issue here is that https://github.com/Azure/azure-cli-extensions/blob/main/src/connectedk8s/azext_connectedk8s/custom.py, the install_helm_client
```
Enabling Azure Arc for Kubernetes. This may take a while.
Command: 'connectedk8s connect --name andrewlee-k8s --resource-group andrewlee-08mar --location eastus' failed with exit code: 1
WARNING: This operation might take a while...
WARNING: Downloading helm client for first time. This can take few minutes...
ERROR: The command failed with an unexpected error. Here is the traceback:
ERROR: IncompleteRead(11699020 bytes read, 2003097 more expected)
Traceback (most recent call last):
File "/usr/lib64/az/lib/python3.6/site-packages/knack/cli.py", line 231, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/lib64/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
raise ex
File "/usr/lib64/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/usr/lib64/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
result = cmd_copy(params)
File "/usr/lib64/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
return self.handler(*args, **kwargs)
File "/usr/lib64/az/lib/python3.6/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
return op(**command_args)
File "/root/.azure/cliextensions/connectedk8s/azext_connectedk8s/custom.py", line 176, in create_connectedk8s
helm_client_location = install_helm_client()
File "/root/.azure/cliextensions/connectedk8s/azext_connectedk8s/custom.py", line 426, in install_helm_client
responseContent = response.read()
File "/usr/lib64/python3.6/http/client.py", line 472, in read
s = self._safe_read(self.length)
File "/usr/lib64/python3.6/http/client.py", line 624, in _safe_read
raise IncompleteRead(b''.join(s), amt)
http.client.IncompleteRead: IncompleteRead(11699020 bytes read, 2003097 more expected)
To open an issue, please run: 'az feedback'
````
The relevant code is:
````
try:
response = urllib.request.urlopen(requestUri)
except Exception as e:
telemetry.set_exception(exception=e, fault_type=consts.Download_Helm_Fault_Type,
summary='Unable to download helm client.')
raise CLIInternalError("Failed to download helm client.", recommendation="Please check your internet connection." + str(e))
responseContent = response.read()
response.close()
````
1) On the http.client.IncompleteRead issue - see e.g : https://stackoverflow.com/questions/14442222/how-to-handle-incompleteread-in-python for how to fix
2) it would be more pythonic and safer to use a contextmanager here and do:
```
with urllib.request.urlopen(requestUri) as response:
do some things..
```
Contributor guide
Assessment
This issue has not been assessed yet.