Azure / azure-cli-extensions

Public Repository for Extensions of Azure CLI.
https://docs.microsoft.com/en-us/cli/azure
MIT License
384 stars 1.25k forks source link

`az connectedk8s connect` fails ungracefully with `http.client.IncompleteRead` error when installing helm client #6033

Open andrew-lee-1089 opened 1 year ago

andrew-lee-1089 commented 1 year ago

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..
yonzhan commented 1 year ago

route to CXP team

navba-MSFT commented 1 year ago

@andrew-lee-metaswitch Thanks for reaching out to us and reporting this issue. Could you please update your extension connectedk8s and check if that helps.

az extension update -n connectedk8s

On a side note, also please update the Azure CLI. Hope this helps.

ghost commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @akashkeshari.

Issue Details
### 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.. ```
Author: andrew-lee-metaswitch
Assignees: navba-MSFT
Labels: `question`, `Service Attention`, `needs-author-feedback`, `Connected Kubernetes`, `Auto-Assign`
Milestone: -
navba-MSFT commented 1 year ago

@andrew-lee-metaswitch As discussed internally, I am adding Service team to look into this issue.

@akashkeshari Could you please look into this once you get a chance ? Thanks in advance.