Skip to content

Commit b7a34ab

Browse files
committed
adjusting arm64 support
1 parent b6c9815 commit b7a34ab

3 files changed

Lines changed: 139 additions & 52 deletions

File tree

src/connectedk8s/azext_connectedk8s/custom.py

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,15 +1302,14 @@ def install_helm_client(cmd: CLICommand) -> str:
13021302
)
13031303

13041304
download_location = os.path.expanduser(os.path.join("~", download_location_string))
1305-
download_dir = os.path.dirname(download_location)
13061305
install_location = os.path.expanduser(os.path.join("~", install_location_string))
13071306

13081307
# Download compressed Helm binary if not already present
13091308
if not os.path.isfile(install_location):
13101309
# Creating the helm folder if it doesnt exist
1311-
if not os.path.exists(download_dir):
1310+
if not os.path.exists(download_location):
13121311
try:
1313-
os.makedirs(download_dir)
1312+
os.makedirs(download_location)
13141313
except Exception as e:
13151314
telemetry.set_exception(
13161315
exception=e,
@@ -1324,32 +1323,56 @@ def install_helm_client(cmd: CLICommand) -> str:
13241323
"Downloading helm client for first time. This can take few minutes..."
13251324
)
13261325

1327-
mcr_url = utils.get_mcr_path(cmd.cli_ctx.cloud.endpoints.active_directory)
1328-
1329-
client = oras.client.OrasClient(hostname=mcr_url)
13301326
retry_count = 3
13311327
retry_delay = 5
1332-
for i in range(retry_count):
1333-
try:
1334-
client.pull(
1335-
target=f"{mcr_url}/{consts.HELM_MCR_URL}:{artifactTag}",
1336-
outdir=download_location,
1337-
)
1338-
break
1339-
except Exception as e:
1340-
if i == retry_count - 1:
1341-
if "Connection reset by peer" in str(e):
1342-
telemetry.set_user_fault()
1343-
telemetry.set_exception(
1344-
exception=e,
1345-
fault_type=consts.Download_Helm_Fault_Type,
1346-
summary="Unable to download helm client.",
1347-
)
1348-
raise CLIInternalError(
1349-
f"Failed to download helm client: {e}",
1350-
recommendation="Please check your internet connection.",
1328+
if arch == "arm64":
1329+
official_helm_url = f"https://get.helm.sh/{download_file_name}"
1330+
download_location_file = os.path.expanduser(
1331+
os.path.join(download_location, download_file_name)
1332+
)
1333+
for i in range(retry_count):
1334+
try:
1335+
from urllib.request import urlretrieve
1336+
1337+
urlretrieve(official_helm_url, download_location_file)
1338+
break
1339+
except Exception as e:
1340+
if i == retry_count - 1:
1341+
telemetry.set_exception(
1342+
exception=e,
1343+
fault_type=consts.Download_Helm_Fault_Type,
1344+
summary="Unable to download helm client.",
1345+
)
1346+
raise CLIInternalError(
1347+
f"Failed to download helm client: {e}",
1348+
recommendation="Please check your internet connection.",
1349+
)
1350+
time.sleep(retry_delay)
1351+
else:
1352+
mcr_url = utils.get_mcr_path(cmd.cli_ctx.cloud.endpoints.active_directory)
1353+
1354+
client = oras.client.OrasClient(hostname=mcr_url)
1355+
for i in range(retry_count):
1356+
try:
1357+
client.pull(
1358+
target=f"{mcr_url}/{consts.HELM_MCR_URL}:{artifactTag}",
1359+
outdir=download_location,
13511360
)
1352-
time.sleep(retry_delay)
1361+
break
1362+
except Exception as e:
1363+
if i == retry_count - 1:
1364+
if "Connection reset by peer" in str(e):
1365+
telemetry.set_user_fault()
1366+
telemetry.set_exception(
1367+
exception=e,
1368+
fault_type=consts.Download_Helm_Fault_Type,
1369+
summary="Unable to download helm client.",
1370+
)
1371+
raise CLIInternalError(
1372+
f"Failed to download helm client: {e}",
1373+
recommendation="Please check your internet connection.",
1374+
)
1375+
time.sleep(retry_delay)
13531376

13541377
# Extract the archive.
13551378
try:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import unittest
7+
from unittest.mock import MagicMock, patch
8+
9+
from azext_connectedk8s.custom import install_kubectl_client
10+
11+
12+
class TestInstallKubectlClient(unittest.TestCase):
13+
@patch("azext_connectedk8s.custom.platform.system", return_value="linux")
14+
@patch("azext_connectedk8s.custom.os.path.isfile", return_value=False)
15+
@patch("azext_connectedk8s.custom.os.makedirs")
16+
@patch("azext_connectedk8s.custom.os.path.expanduser", return_value="/tmp/home")
17+
@patch("azext_connectedk8s.custom.get_default_cli")
18+
def test_install_kubectl_invokes_install_cli(
19+
self,
20+
mock_get_default_cli,
21+
_mock_expanduser,
22+
_mock_makedirs,
23+
_mock_isfile,
24+
_mock_system,
25+
):
26+
mock_cli = MagicMock()
27+
mock_cli.invoke.return_value = 0
28+
mock_get_default_cli.return_value = mock_cli
29+
30+
result = install_kubectl_client()
31+
32+
expected_kubectl_path = "/tmp/home/.azure/kubectl-client/kubectl"
33+
self.assertEqual(result, expected_kubectl_path)
34+
mock_cli.invoke.assert_called_once_with(
35+
[
36+
"aks",
37+
"install-cli",
38+
"--install-location",
39+
expected_kubectl_path,
40+
]
41+
)

src/k8s-extension/azext_k8s_extension/custom.py

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -747,15 +747,14 @@ def install_helm_client(cmd: CLICommand) -> str:
747747
)
748748

749749
download_location = os.path.expanduser(os.path.join("~", download_location_string))
750-
download_dir = os.path.dirname(download_location)
751750
install_location = os.path.expanduser(os.path.join("~", install_location_string))
752751

753752
# Download compressed Helm binary if not already present
754753
if not os.path.isfile(install_location):
755754
# Creating the helm folder if it doesnt exist
756-
if not os.path.exists(download_dir):
755+
if not os.path.exists(download_location):
757756
try:
758-
os.makedirs(download_dir)
757+
os.makedirs(download_location)
759758
except Exception as e:
760759
telemetry.set_exception(
761760
exception=e,
@@ -769,32 +768,56 @@ def install_helm_client(cmd: CLICommand) -> str:
769768
"Downloading helm client for first time. This can take few minutes..."
770769
)
771770

772-
mcr_url = utils.get_mcr_path(cmd.cli_ctx.cloud.endpoints.active_directory)
773-
774-
client = oras.client.OrasClient(hostname=mcr_url)
775771
retry_count = 3
776772
retry_delay = 5
777-
for i in range(retry_count):
778-
try:
779-
client.pull(
780-
target=f"{mcr_url}/{consts.HELM_MCR_URL}:{artifactTag}",
781-
outdir=download_location,
782-
)
783-
break
784-
except Exception as e:
785-
if i == retry_count - 1:
786-
if "Connection reset by peer" in str(e):
787-
telemetry.set_user_fault()
788-
telemetry.set_exception(
789-
exception=e,
790-
fault_type=consts.Download_Helm_Fault_Type,
791-
summary="Unable to download helm client.",
792-
)
793-
raise CLIInternalError(
794-
f"Failed to download helm client: {e}",
795-
recommendation="Please check your internet connection.",
773+
if arch == "arm64":
774+
official_helm_url = f"https://get.helm.sh/{download_file_name}"
775+
download_location_file = os.path.expanduser(
776+
os.path.join(download_location, download_file_name)
777+
)
778+
for i in range(retry_count):
779+
try:
780+
from urllib.request import urlretrieve
781+
782+
urlretrieve(official_helm_url, download_location_file)
783+
break
784+
except Exception as e:
785+
if i == retry_count - 1:
786+
telemetry.set_exception(
787+
exception=e,
788+
fault_type=consts.Download_Helm_Fault_Type,
789+
summary="Unable to download helm client.",
790+
)
791+
raise CLIInternalError(
792+
f"Failed to download helm client: {e}",
793+
recommendation="Please check your internet connection.",
794+
)
795+
time.sleep(retry_delay)
796+
else:
797+
mcr_url = utils.get_mcr_path(cmd.cli_ctx.cloud.endpoints.active_directory)
798+
799+
client = oras.client.OrasClient(hostname=mcr_url)
800+
for i in range(retry_count):
801+
try:
802+
client.pull(
803+
target=f"{mcr_url}/{consts.HELM_MCR_URL}:{artifactTag}",
804+
outdir=download_location,
796805
)
797-
time.sleep(retry_delay)
806+
break
807+
except Exception as e:
808+
if i == retry_count - 1:
809+
if "Connection reset by peer" in str(e):
810+
telemetry.set_user_fault()
811+
telemetry.set_exception(
812+
exception=e,
813+
fault_type=consts.Download_Helm_Fault_Type,
814+
summary="Unable to download helm client.",
815+
)
816+
raise CLIInternalError(
817+
f"Failed to download helm client: {e}",
818+
recommendation="Please check your internet connection.",
819+
)
820+
time.sleep(retry_delay)
798821

799822
# Extract the archive.
800823
try:

0 commit comments

Comments
 (0)