Skip to content

Commit

Permalink
Download helm client from connectedk8s CLI (#3906)
Browse files Browse the repository at this point in the history
* Added spn and resource group creation in connectedk8s create

* Vanilla CLI Code for Connected Cluster

* saved location data CLI changes after 0.1.2

* Added the 0.1.2 version CLI code in master

* Removed a print statement

* Fixed container status check

* Updated pod status check

* Added 2020 version models and operations

* Updated with key pair generation

* review of public private key pair

* updated models with latest changes in swagger

* Update CLI to support SPN less onboarding

* Removed location data changes

* Update src/connectedk8s/azext_connectedk8s/custom.py

Co-Authored-By: Shashank Barsin <shashankbarsin@users.noreply.github.com>

* Update src/connectedk8s/azext_connectedk8s/custom.py

Co-Authored-By: Shashank Barsin <shashankbarsin@users.noreply.github.com>

* Update src/connectedk8s/azext_connectedk8s/custom.py

Co-Authored-By: Shashank Barsin <shashankbarsin@users.noreply.github.com>

* Update src/connectedk8s/azext_connectedk8s/custom.py

Co-Authored-By: Shashank Barsin <shashankbarsin@users.noreply.github.com>

* Update src/connectedk8s/azext_connectedk8s/custom.py

Co-Authored-By: Shashank Barsin <shashankbarsin@users.noreply.github.com>

* Update src/connectedk8s/azext_connectedk8s/custom.py

Co-Authored-By: Shashank Barsin <shashankbarsin@users.noreply.github.com>

* Update src/connectedk8s/azext_connectedk8s/custom.py

Co-Authored-By: Shashank Barsin <shashankbarsin@users.noreply.github.com>

* Update src/connectedk8s/azext_connectedk8s/custom.py

Co-Authored-By: Shashank Barsin <shashankbarsin@users.noreply.github.com>

* Update src/connectedk8s/azext_connectedk8s/custom.py

Co-Authored-By: Shashank Barsin <shashankbarsin@users.noreply.github.com>

* Update src/connectedk8s/azext_connectedk8s/custom.py

Co-Authored-By: Shashank Barsin <shashankbarsin@users.noreply.github.com>

* Updated error messages

* updated wrt style checks

* Added a recorded test

* Updated imports

* removed python 2.x from setup.py

* Updated format.py

* Updated readme file

* Updated test file

* updated setup.py

* updated knack version in setup.py

* updated knack version to 0.7.0rc4 in setup.py

* Updated test file to pass kubeconfig

* Updated test file to pass kubeconfig

* Added async support for delete

* Added helm charts to test data folder

* Updated helm chart pull method

* corrected import order

* Ran connectedk8s test

* Updated some print statements

* ran test with helm upgrade --install

* Updated print to warning

* Updated error message

* Updated exceptions to be generic

* Added aks creation in tests

* updated warning statements

* updated test to create aks cluster with ssh keys

* added spn calls in recorded tests

* Updated api-version in recorded tests

* removed mc delete as CI test needs it to be persistant

* switched to livescenariotest

* updated params.py

* corrected databricks change

* updated pod monitoring

* updated identation

* updated print statement to warnings

* added telemetry code for connect cli

* Added exception telemetry for delete operation

* Updated setup.py

* Changed default kubernetes distro

* Distro detect.

* Updated history

* removed arm resourceid from telemetry

* Add kubernetes distro and identifying it.

* Remove additional line.

* correct indentation.

* correct indentation.

* correct version number.

* added code to install helm binary from cli

* fixed path for linux and mac

* removed helm warning message

* moved folder creation step up

* updated print message to warning message

Co-authored-by: Akash Keshari <akkeshar@microsoft.com>
Co-authored-by: Shashank Barsin <shashankbarsin@users.noreply.github.com>
Co-authored-by: Pavan Sankavaram <pasankav@microsoft.com>
Co-authored-by: Pavan Sankavaram <54311110+pasankav@users.noreply.github.com>
  • Loading branch information
5 people authored Sep 23, 2021
1 parent 378e1de commit e0c9d9d
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 156 deletions.
5 changes: 5 additions & 0 deletions src/connectedk8s/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Release History
===============

1.1.11
++++++

* Installing helm binary as part of CLI commands

1.1.10
++++++

Expand Down
6 changes: 6 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
Kubeconfig_Failed_To_Load_Fault_Type = "failed-to-load-kubeconfig-file"
Failed_To_Load_K8s_Configuration_Fault_Type = "failed-to-load-kubernetes-configuration"
Failed_To_Merge_Kubeconfig_File = "failed-to-merge-kubeconfig-file"
Download_Helm_Fault_Type = "helm-client-download-error"
Create_HelmExe_Fault_Type = "helm-client-create-error"
Extract_HelmExe_Fault_Type = "helm-client-extract-error"
Different_Object_With_Same_Name_Fault_Type = "Kubeconfig has an object with same name"
Download_Exe_Fault_Type = "Error while downloading client proxy executable from storage account"
Create_Directory_Fault_Type = "Error while creating directory for placing the executable"
Expand All @@ -77,6 +80,7 @@
Proxy_Closed_Externally_Fault_Type = "Proxy closed externally."
Client_Proxy_Port_Fault_Type = "Client proxy port was in use."
Unsupported_Fault_Type = "Error while checking operating system.Unsupported OS detected."
Helm_Unsupported_OS_Fault_Type = "helm-client-unsupported-os-error."
Port_Check_Fault_Type = "Error while checking if port is in use."
Kubeconfig_Failed_To_Load_Fault_Type = "failed-to-load-kubeconfig-file"
Proxy_Cert_Path_Does_Not_Exist_Fault_Type = 'proxy-cert-path-does-not-exist-error'
Expand Down Expand Up @@ -118,3 +122,5 @@
CSP_REFRESH_TIME = 300
# URL constants
CSP_Storage_Url = "https://k8sconnectcsp.blob.core.windows.net"
HELM_STORAGE_URL = "https://k8connecthelm.azureedge.net"
HELM_VERSION = 'v3.6.3'
27 changes: 14 additions & 13 deletions src/connectedk8s/azext_connectedk8s/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def validate_location(cmd, location):
break


def get_chart_path(registry_path, kube_config, kube_context):
def get_chart_path(registry_path, kube_config, kube_context, helm_client_location):
# Pulling helm chart from registry
os.environ['HELM_EXPERIMENTAL_OCI'] = '1'
pull_helm_chart(registry_path, kube_config, kube_context)
pull_helm_chart(registry_path, kube_config, kube_context, helm_client_location)

# Exporting helm chart after cleanup
chart_export_path = os.path.join(os.path.expanduser('~'), '.azure', 'AzureArcCharts')
Expand All @@ -80,16 +80,16 @@ def get_chart_path(registry_path, kube_config, kube_context):
shutil.rmtree(chart_export_path)
except:
logger.warning("Unable to cleanup the azure-arc helm charts already present on the machine. In case of failure, please cleanup the directory '%s' and try again.", chart_export_path)
export_helm_chart(registry_path, chart_export_path, kube_config, kube_context)
export_helm_chart(registry_path, chart_export_path, kube_config, kube_context, helm_client_location)

# Returning helm chart path
helm_chart_path = os.path.join(chart_export_path, 'azure-arc-k8sagents')
chart_path = os.getenv('HELMCHART') if os.getenv('HELMCHART') else helm_chart_path
return chart_path


def pull_helm_chart(registry_path, kube_config, kube_context):
cmd_helm_chart_pull = ["helm", "chart", "pull", registry_path]
def pull_helm_chart(registry_path, kube_config, kube_context, helm_client_location):
cmd_helm_chart_pull = [helm_client_location, "chart", "pull", registry_path]
if kube_config:
cmd_helm_chart_pull.extend(["--kubeconfig", kube_config])
if kube_context:
Expand All @@ -102,8 +102,8 @@ def pull_helm_chart(registry_path, kube_config, kube_context):
raise CLIInternalError("Unable to pull helm chart from the registry '{}': ".format(registry_path) + error_helm_chart_pull.decode("ascii"))


def export_helm_chart(registry_path, chart_export_path, kube_config, kube_context):
cmd_helm_chart_export = ["helm", "chart", "export", registry_path, "--destination", chart_export_path]
def export_helm_chart(registry_path, chart_export_path, kube_config, kube_context, helm_client_location):
cmd_helm_chart_export = [helm_client_location, "chart", "export", registry_path, "--destination", chart_export_path]
if kube_config:
cmd_helm_chart_export.extend(["--kubeconfig", kube_config])
if kube_context:
Expand All @@ -116,10 +116,10 @@ def export_helm_chart(registry_path, chart_export_path, kube_config, kube_contex
raise CLIInternalError("Unable to export helm chart from the registry '{}': ".format(registry_path) + error_helm_chart_export.decode("ascii"))


def add_helm_repo(kube_config, kube_context):
def add_helm_repo(kube_config, kube_context, helm_client_location):
repo_name = os.getenv('HELMREPONAME')
repo_url = os.getenv('HELMREPOURL')
cmd_helm_repo = ["helm", "repo", "add", repo_name, repo_url]
cmd_helm_repo = [helm_client_location, "repo", "add", repo_name, repo_url]
if kube_config:
cmd_helm_repo.extend(["--kubeconfig", kube_config])
if kube_context:
Expand Down Expand Up @@ -269,8 +269,8 @@ def ensure_namespace_cleanup(configuration):
raise_error=False)


def delete_arc_agents(release_namespace, kube_config, kube_context, configuration):
cmd_helm_delete = ["helm", "delete", "azure-arc", "--namespace", release_namespace]
def delete_arc_agents(release_namespace, kube_config, kube_context, configuration, helm_client_location):
cmd_helm_delete = [helm_client_location, "delete", "azure-arc", "--namespace", release_namespace]
if kube_config:
cmd_helm_delete.extend(["--kubeconfig", kube_config])
if kube_context:
Expand All @@ -290,8 +290,9 @@ def delete_arc_agents(release_namespace, kube_config, kube_context, configuratio

def helm_install_release(chart_path, subscription_id, kubernetes_distro, kubernetes_infra, resource_group_name, cluster_name,
location, onboarding_tenant_id, http_proxy, https_proxy, no_proxy, proxy_cert, private_key_pem,
kube_config, kube_context, no_wait, values_file_provided, values_file, cloud_name, disable_auto_upgrade, enable_custom_locations, custom_locations_oid, onboarding_timeout="600"):
cmd_helm_install = ["helm", "upgrade", "--install", "azure-arc", chart_path,
kube_config, kube_context, no_wait, values_file_provided, values_file, cloud_name, disable_auto_upgrade,
enable_custom_locations, custom_locations_oid, helm_client_location, onboarding_timeout="600"):
cmd_helm_install = [helm_client_location, "upgrade", "--install", "azure-arc", chart_path,
"--set", "global.subscriptionId={}".format(subscription_id),
"--set", "global.kubernetesDistro={}".format(kubernetes_distro),
"--set", "global.kubernetesInfra={}".format(kubernetes_infra),
Expand Down
Loading

0 comments on commit e0c9d9d

Please sign in to comment.