From 4b7aadfbdbe40b034a40b6fa80b394307e391d62 Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Fri, 11 Feb 2022 17:15:11 +0530 Subject: [PATCH 1/5] Use userValues.txt instead of --resuse-values in update command --- src/connectedk8s/azext_connectedk8s/custom.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index f66114fc499..18ab9950317 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -879,9 +879,25 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" # Get Helm chart path chart_path = utils.get_chart_path(registry_path, kube_config, kube_context, helm_client_location) + cmd_helm_values = [helm_client_location, "get", "values", "azure-arc", "--namespace", release_namespace] + if kube_config: + cmd_helm_values.extend(["--kubeconfig", kube_config]) + if kube_context: + cmd_helm_values.extend(["--kube-context", kube_context]) + cmd_helm_values.extend([">", "userValues.txt"]) + + response_helm_values_get = Popen(cmd_helm_values, stdout=PIPE, stderr=PIPE) + _, error_helm_get_values = response_helm_values_get.communicate() + if response_helm_values_get.returncode != 0: + if ('forbidden' in error_helm_get_values.decode("ascii") or 'timed out waiting for the condition' in error_helm_get_values.decode("ascii")): + telemetry.set_user_fault() + telemetry.set_exception(exception=error_helm_get_values.decode("ascii"), fault_type=consts.Get_Helm_Values_Failed, + summary='Error while doing helm get values azure-arc') + raise CLIInternalError(str.format(consts.Upgrade_Agent_Failure, error_helm_get_values.decode("ascii"))) + cmd_helm_upgrade = [helm_client_location, "upgrade", "azure-arc", chart_path, "--namespace", release_namespace, - "--reuse-values", - "--wait", "--output", "json"] + "-f", + "userValues.txt", "--wait", "--output", "json"] if values_file_provided: cmd_helm_upgrade.extend(["-f", values_file]) if auto_upgrade is not None: From e8297ad4daadef5be4209bbb7e26be756658f305 Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Fri, 11 Feb 2022 17:19:08 +0530 Subject: [PATCH 2/5] fix error msg --- src/connectedk8s/azext_connectedk8s/custom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index 18ab9950317..2ddc371703b 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -893,7 +893,7 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" telemetry.set_user_fault() telemetry.set_exception(exception=error_helm_get_values.decode("ascii"), fault_type=consts.Get_Helm_Values_Failed, summary='Error while doing helm get values azure-arc') - raise CLIInternalError(str.format(consts.Upgrade_Agent_Failure, error_helm_get_values.decode("ascii"))) + raise CLIInternalError(str.format(consts.Update_Agent_Failure, error_helm_get_values.decode("ascii"))) cmd_helm_upgrade = [helm_client_location, "upgrade", "azure-arc", chart_path, "--namespace", release_namespace, "-f", From 02014ea28f4333018730dc2bb3d1abe5d3ef61ac Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Tue, 15 Feb 2022 17:41:15 +0530 Subject: [PATCH 3/5] fix output file --- src/connectedk8s/azext_connectedk8s/custom.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index 2ddc371703b..1472ce8882e 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -884,9 +884,9 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" cmd_helm_values.extend(["--kubeconfig", kube_config]) if kube_context: cmd_helm_values.extend(["--kube-context", kube_context]) - cmd_helm_values.extend([">", "userValues.txt"]) - - response_helm_values_get = Popen(cmd_helm_values, stdout=PIPE, stderr=PIPE) + + existing_user_values = open('userValues.txt', 'w+') + response_helm_values_get = Popen(cmd_helm_values, stdout=existing_user_values, stderr=PIPE) _, error_helm_get_values = response_helm_values_get.communicate() if response_helm_values_get.returncode != 0: if ('forbidden' in error_helm_get_values.decode("ascii") or 'timed out waiting for the condition' in error_helm_get_values.decode("ascii")): @@ -894,7 +894,7 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" telemetry.set_exception(exception=error_helm_get_values.decode("ascii"), fault_type=consts.Get_Helm_Values_Failed, summary='Error while doing helm get values azure-arc') raise CLIInternalError(str.format(consts.Update_Agent_Failure, error_helm_get_values.decode("ascii"))) - + cmd_helm_upgrade = [helm_client_location, "upgrade", "azure-arc", chart_path, "--namespace", release_namespace, "-f", "userValues.txt", "--wait", "--output", "json"] @@ -925,8 +925,15 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" telemetry.set_user_fault() telemetry.set_exception(exception=error_helm_upgrade.decode("ascii"), fault_type=consts.Install_HelmRelease_Fault_Type, summary='Unable to install helm release') + try: + os.remove(existing_user_values.name) + except OSError: + pass raise CLIInternalError(str.format(consts.Update_Agent_Failure, error_helm_upgrade.decode("ascii"))) - + try: + os.remove(existing_user_values.name) + except OSError: + pass return str.format(consts.Update_Agent_Success, connected_cluster.name) From 159e3bbb9591c73775ac964be3fae152834c4e2d Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Wed, 16 Feb 2022 15:37:08 +0530 Subject: [PATCH 4/5] place values file in .azure folder --- src/connectedk8s/azext_connectedk8s/custom.py | 20 +++++++++++++++---- src/connectedk8s/setup.py | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index 71882ffa7af..b52ca111bde 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -777,6 +777,8 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" # Send cloud information to telemetry send_cloud_telemetry(cmd) + # Fetch OS details + operating_system = platform.system() # Setting kubeconfig kube_config = set_kube_config(kube_config) @@ -885,7 +887,17 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" if kube_context: cmd_helm_values.extend(["--kube-context", kube_context]) - existing_user_values = open('userValues.txt', 'w+') + if(operating_system == 'Windows'): + user_values_filepath_string = f'.azure\\userValues.txt' + elif(operating_system == 'Linux' or operating_system == 'Darwin'): + user_values_filepath_string = f'.azure/userValues.txt' + else: + telemetry.set_exception(exception='Unsupported OS', fault_type=consts.Unsupported_Fault_Type, + summary=f'{operating_system} is not supported yet') + raise ClientRequestError(f'The {operating_system} platform is not currently supported.') + + user_values_location = os.path.expanduser(os.path.join('~', user_values_filepath_string)) + existing_user_values = open(user_values_location, 'w+') response_helm_values_get = Popen(cmd_helm_values, stdout=existing_user_values, stderr=PIPE) _, error_helm_get_values = response_helm_values_get.communicate() if response_helm_values_get.returncode != 0: @@ -897,7 +909,7 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" cmd_helm_upgrade = [helm_client_location, "upgrade", "azure-arc", chart_path, "--namespace", release_namespace, "-f", - "userValues.txt", "--wait", "--output", "json"] + user_values_location, "--wait", "--output", "json"] if values_file_provided: cmd_helm_upgrade.extend(["-f", values_file]) if auto_upgrade is not None: @@ -927,12 +939,12 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" telemetry.set_exception(exception=error_helm_upgrade.decode("ascii"), fault_type=consts.Install_HelmRelease_Fault_Type, summary='Unable to install helm release') try: - os.remove(existing_user_values.name) + os.remove(user_values_location) except OSError: pass raise CLIInternalError(str.format(consts.Update_Agent_Failure, error_helm_upgrade.decode("ascii"))) try: - os.remove(existing_user_values.name) + os.remove(user_values_location) except OSError: pass return str.format(consts.Update_Agent_Success, connected_cluster.name) diff --git a/src/connectedk8s/setup.py b/src/connectedk8s/setup.py index 66dc7977baa..df92c4d6167 100644 --- a/src/connectedk8s/setup.py +++ b/src/connectedk8s/setup.py @@ -17,7 +17,7 @@ # TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. -VERSION = '1.2.3' +VERSION = '1.2.4' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers From c18d3dffe6ac0f09a05a2ddd2646205bdcf23185 Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Wed, 16 Feb 2022 15:40:29 +0530 Subject: [PATCH 5/5] place values file in .azure folder --- src/connectedk8s/azext_connectedk8s/custom.py | 2 +- src/connectedk8s/setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index b52ca111bde..b63b6528ae6 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -906,7 +906,7 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" telemetry.set_exception(exception=error_helm_get_values.decode("ascii"), fault_type=consts.Get_Helm_Values_Failed, summary='Error while doing helm get values azure-arc') raise CLIInternalError(str.format(consts.Update_Agent_Failure, error_helm_get_values.decode("ascii"))) - + cmd_helm_upgrade = [helm_client_location, "upgrade", "azure-arc", chart_path, "--namespace", release_namespace, "-f", user_values_location, "--wait", "--output", "json"] diff --git a/src/connectedk8s/setup.py b/src/connectedk8s/setup.py index df92c4d6167..66dc7977baa 100644 --- a/src/connectedk8s/setup.py +++ b/src/connectedk8s/setup.py @@ -17,7 +17,7 @@ # TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. -VERSION = '1.2.4' +VERSION = '1.2.3' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers