1212import stat
1313import subprocess
1414import time
15- import urllib .request
1615from subprocess import PIPE
1716
17+ import oras .client # type: ignore[import-untyped]
1818import psutil
1919import requests
2020from azure .cli .core import get_default_cli
@@ -71,23 +71,21 @@ def install_helm_client():
7171
7272 # Set helm binary download & install locations
7373 if operating_system == "windows" :
74- download_location_string = (
75- f".azure\\ helm\\ { consts .HELM_VERSION } \\ helm-{ consts .HELM_VERSION } -\
76- { operating_system } -amd64.zip"
77- )
74+ download_location_string = f".azure\\ helm\\ { consts .HELM_VERSION } "
75+ download_file_name = f"helm-{ consts .HELM_VERSION } -{ operating_system } -amd64.zip"
7876 install_location_string = (
7977 f".azure\\ helm\\ { consts .HELM_VERSION } \\ { operating_system } -amd64\\ helm.exe"
8078 )
81- requestUri = f"{ consts . HELM_STORAGE_URL } / helm/helm -{ consts .HELM_VERSION } -{ operating_system } -amd64.zip "
79+ artifactTag = f"helm-{ consts .HELM_VERSION } -{ operating_system } -amd64"
8280 elif operating_system == "linux" or operating_system == "darwin" :
83- download_location_string = (
84- f".azure/helm/ { consts . HELM_VERSION } /helm- { consts . HELM_VERSION } - \
85- { operating_system } -amd64.tar.gz"
81+ download_location_string = f".azure/helm/ { consts . HELM_VERSION } "
82+ download_file_name = (
83+ f"helm- { consts . HELM_VERSION } - { operating_system } -amd64.tar.gz"
8684 )
8785 install_location_string = (
8886 f".azure/helm/{ consts .HELM_VERSION } /{ operating_system } -amd64/helm"
8987 )
90- requestUri = f"{ consts . HELM_STORAGE_URL } / helm/helm -{ consts .HELM_VERSION } -{ operating_system } -amd64.tar.gz "
88+ artifactTag = f"helm-{ consts .HELM_VERSION } -{ operating_system } -amd64"
9189 else :
9290 logger .warning (
9391 f"The { operating_system } platform is not currently supported for installing helm client."
@@ -98,8 +96,8 @@ def install_helm_client():
9896 download_dir = os .path .dirname (download_location )
9997 install_location = os .path .expanduser (os .path .join ("~" , install_location_string ))
10098
101- # Download compressed helm binary if not already present
102- if not os .path .isfile (download_location ):
99+ # Download compressed Helm binary if not already present
100+ if not os .path .isfile (install_location ):
103101 # Creating the helm folder if it doesnt exist
104102 if not os .path .exists (download_dir ):
105103 try :
@@ -109,27 +107,25 @@ def install_helm_client():
109107 return
110108
111109 # Downloading compressed helm client executable
110+ logger .warning (
111+ "Downloading helm client for first time. This can take few minutes..."
112+ )
113+ client = oras .client .OrasClient ()
112114 try :
113- response = urllib .request .urlopen (requestUri )
115+ client .pull (
116+ target = f"{ consts .HELM_MCR_URL } :{ artifactTag } " , outdir = download_location
117+ )
114118 except Exception as e :
115119 logger .warning ("Failed to download helm client." + str (e ))
116120 return
117121
118- responseContent = response .read ()
119- response .close ()
120-
121- # Creating the compressed helm binaries
122+ # Extract the archive.
122123 try :
123- with open (download_location , "wb" ) as f :
124- f .write (responseContent )
125- except Exception as e :
126- logger .warning ("Failed to extract helm executable" + str (e ))
127- return
128-
129- # Extract compressed helm binary
130- if not os .path .isfile (install_location ):
131- try :
132- shutil .unpack_archive (download_location , download_dir )
124+ extract_dir = download_location
125+ download_location = os .path .expanduser (
126+ os .path .join (download_location , download_file_name )
127+ )
128+ shutil .unpack_archive (download_location , extract_dir )
133129 os .chmod (install_location , os .stat (install_location ).st_mode | stat .S_IXUSR )
134130 except Exception as e :
135131 logger .warning ("Failed to extract helm executable" + str (e ))
@@ -220,52 +216,6 @@ def test_connect(self, resource_group):
220216 # delete the kube config
221217 os .remove (_get_test_data_file (managed_cluster_name + "-config.yaml" ))
222218
223- @live_only ()
224- @ResourceGroupPreparer (
225- name_prefix = "conk8stest" , location = CONFIG ["location" ], random_name_length = 16
226- )
227- def test_connect_withoidcandworkloadidentity (self , resource_group ):
228- managed_cluster_name = self .create_random_name (prefix = "test-connect" , length = 24 )
229- kubeconfig = _get_test_data_file (managed_cluster_name + "-config.yaml" )
230- self .kwargs .update (
231- {
232- "rg" : resource_group ,
233- "name" : self .create_random_name (prefix = "cc-" , length = 12 ),
234- "kubeconfig" : kubeconfig ,
235- "managed_cluster_name" : managed_cluster_name ,
236- "location" : CONFIG ["location" ],
237- }
238- )
239-
240- # scenario - oidc issuer and workload identity enabled
241- self .cmd ("aks create -g {rg} -n {managed_cluster_name} --generate-ssh-keys" )
242- self .cmd (
243- "aks get-credentials -g {rg} -n {managed_cluster_name} -f {kubeconfig} --admin"
244- )
245- self .cmd (
246- "connectedk8s connect -n {name} -g {rg} -l {location} --tags foo=doo --enable-oidc-issuer \
247- --enable-workload-identity --kube-config {kubeconfig} --kube-context {managed_cluster_name}-admin"
248- )
249- self .cmd (
250- "connectedk8s show -g {rg} -n {name}" ,
251- checks = [
252- self .check ("tags.foo" , "doo" ),
253- self .check ("name" , "{name}" ),
254- self .check ("resourceGroup" , "{rg}" ),
255- self .check ("oidcIssuerProfile.enabled" , True ),
256- self .check ("securityProfile.workloadIndentity.enabled" , True ),
257- ],
258- )
259-
260- self .cmd (
261- "connectedk8s delete -g {rg} -n {name} --kube-config {kubeconfig} --kube-context \
262- {managed_cluster_name}-admin -y"
263- )
264- self .cmd ("aks delete -g {rg} -n {managed_cluster_name} -y" )
265-
266- # delete the kube config
267- os .remove (_get_test_data_file (managed_cluster_name + "-config.yaml" ))
268-
269219 @live_only ()
270220 @ResourceGroupPreparer (
271221 name_prefix = "conk8stest" , location = CONFIG ["location" ], random_name_length = 16
@@ -470,7 +420,7 @@ def test_enable_disable_features(self, resource_group):
470420 with self .assertRaisesRegex (
471421 CLIError ,
472422 "Disabling 'cluster-connect' feature is not allowed when \
473- 'custom-locations' feature is enabled. " ,
423+ 'custom-locations' feature is enabled" ,
474424 ):
475425 self .cmd (
476426 "connectedk8s disable-features -n {name} -g {rg} --features cluster-connect --kube-config \
@@ -847,22 +797,6 @@ def test_update(self, resource_group):
847797 ],
848798 )
849799
850- # scenario - oidc issuer and workload identity enabled
851- self .cmd (
852- "connectedk8s update -n {name} -g {rg} --enable-oidc-issuer \
853- --enable-workload-identity --kube-config {kubeconfig} \
854- --kube-context {managed_cluster_name}-admin"
855- )
856- self .cmd (
857- "connectedk8s show -g {rg} -n {name}" ,
858- checks = [
859- self .check ("name" , "{name}" ),
860- self .check ("resourceGroup" , "{rg}" ),
861- self .check ("oidcIssuerProfile.enabled" , True ),
862- self .check ("securityProfile.workloadIndentity.enabled" , True ),
863- ],
864- )
865-
866800 # scenario - oidc issuer enabled and self hosted issuer url set
867801 self .cmd (
868802 'connectedk8s update -n {name} -g {rg} --enable-oidc-issuer \
0 commit comments