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 01/20] 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 02/20] 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 64531ce55d5b3277b6b837fc3574e53b2e198c03 Mon Sep 17 00:00:00 2001 From: Anumita Shenoy Date: Wed, 29 Sep 2021 15:27:47 +0530 Subject: [PATCH 03/20] added custom cert --- src/connectedk8s/azext_connectedk8s/_params.py | 2 +- src/connectedk8s/azext_connectedk8s/_utils.py | 1 + src/connectedk8s/azext_connectedk8s/custom.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/connectedk8s/azext_connectedk8s/_params.py b/src/connectedk8s/azext_connectedk8s/_params.py index 77223211f31..2621410e70e 100644 --- a/src/connectedk8s/azext_connectedk8s/_params.py +++ b/src/connectedk8s/azext_connectedk8s/_params.py @@ -44,7 +44,7 @@ def load_arguments(self, _): c.argument('https_proxy', options_list=['--proxy-https'], arg_group='Proxy', help='Https proxy URL to be used.') c.argument('http_proxy', options_list=['--proxy-http'], arg_group='Proxy', help='Http proxy URL to be used.') c.argument('no_proxy', options_list=['--proxy-skip-range'], arg_group='Proxy', help='List of URLs/CIDRs for which proxy should not to be used.') - c.argument('proxy_cert', options_list=['--proxy-cert'], arg_group='Proxy', type=file_type, completer=FilesCompleter(), help='Path to the certificate file for proxy') + c.argument('proxy_cert', options_list=['--proxy-cert'], arg_group='Proxy', type=file_type, completer=FilesCompleter(), help='Path to the any additional certificate file (for proxy as well)') c.argument('disable_proxy', options_list=['--disable-proxy'], arg_group='Proxy', action='store_true', help='Disables proxy settings for agents') c.argument('auto_upgrade', options_list=['--auto-upgrade'], help='Flag to enable/disable auto upgrade of arc agents. By default, auto upgrade of agents is enabled.', arg_type=get_enum_type(["true", "false"])) diff --git a/src/connectedk8s/azext_connectedk8s/_utils.py b/src/connectedk8s/azext_connectedk8s/_utils.py index 3ec025c2d76..4c87a356f03 100644 --- a/src/connectedk8s/azext_connectedk8s/_utils.py +++ b/src/connectedk8s/azext_connectedk8s/_utils.py @@ -322,6 +322,7 @@ def helm_install_release(chart_path, subscription_id, kubernetes_distro, kuberne cmd_helm_install.extend(["--set", "global.noProxy={}".format(no_proxy)]) if proxy_cert: cmd_helm_install.extend(["--set-file", "global.proxyCert={}".format(proxy_cert)]) + cmd_helm_install.extend(["--set", "global.isCustomCert={}".format(True)]) if https_proxy or http_proxy or no_proxy: cmd_helm_install.extend(["--set", "global.isProxyEnabled={}".format(True)]) if kube_config: diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index f66114fc499..ed40885a8a9 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -898,6 +898,7 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" cmd_helm_upgrade.extend(["--set", "global.isProxyEnabled={}".format(False)]) if proxy_cert: cmd_helm_upgrade.extend(["--set-file", "global.proxyCert={}".format(proxy_cert)]) + cmd_helm_upgrade.extend(["--set", "global.isCustomCert={}".format(True)]) if kube_config: cmd_helm_upgrade.extend(["--kubeconfig", kube_config]) if kube_context: From 75101fd4ab714eed1db06f7065aa5af7e24c6f18 Mon Sep 17 00:00:00 2001 From: Anumita Shenoy Date: Thu, 11 Nov 2021 13:56:19 +0530 Subject: [PATCH 04/20] change setup.py --- 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 ed40885a8a9..69e83ec887e 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -801,7 +801,7 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" if https_proxy == "" and http_proxy == "" and no_proxy == "" and proxy_cert == "" and not disable_proxy and not auto_upgrade: raise RequiredArgumentMissingError(consts.No_Param_Error) - if (https_proxy or http_proxy or no_proxy or proxy_cert) and disable_proxy: + if (https_proxy or http_proxy or no_proxy) and disable_proxy: raise MutuallyExclusiveArgumentError(consts.EnableProxy_Conflict_Error) # Checking whether optional extra values file has been provided. From df27b204715d44959215a112b47089045c167877 Mon Sep 17 00:00:00 2001 From: Anumita Shenoy Date: Tue, 15 Feb 2022 14:12:08 +0530 Subject: [PATCH 05/20] Helmupdatefix (#4) * Use userValues.txt instead of --resuse-values in update command * fix error msg Co-authored-by: Siri Teja Reddy Kasireddy --- 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 69e83ec887e..368a617c2aa 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.Update_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 02014ea28f4333018730dc2bb3d1abe5d3ef61ac Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Tue, 15 Feb 2022 17:41:15 +0530 Subject: [PATCH 06/20] 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 33669c1ef301722fefaeaf3e68d6081f16c4e4d5 Mon Sep 17 00:00:00 2001 From: siriteja <32883500+sirireddy12@users.noreply.github.com> Date: Tue, 15 Feb 2022 21:48:43 +0530 Subject: [PATCH 07/20] Helmupdatefix (#5) * Use userValues.txt instead of --resuse-values in update command * fix error msg * fix output file Co-authored-by: Siri Teja Reddy Kasireddy --- 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 368a617c2aa..71882ffa7af 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"] @@ -926,8 +926,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 08/20] 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 09/20] 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 From 58a545a92ad9c685cb6b0ff086f1bdee531b6d9a Mon Sep 17 00:00:00 2001 From: siriteja <32883500+sirireddy12@users.noreply.github.com> Date: Wed, 16 Feb 2022 15:49:42 +0530 Subject: [PATCH 10/20] Helmupdatefix (#6) * Use userValues.txt instead of --resuse-values in update command * fix error msg * fix output file * place values file in .azure folder * place values file in .azure folder Co-authored-by: Siri Teja Reddy Kasireddy --- src/connectedk8s/azext_connectedk8s/custom.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 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) From 84c1148231061f1383a9105efde0cb941c32739a Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Wed, 16 Feb 2022 15:57:56 +0530 Subject: [PATCH 11/20] place values file in .azure folder --- src/connectedk8s/azext_connectedk8s/custom.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index b63b6528ae6..85bafd489bb 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -886,16 +886,16 @@ 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]) - + if(operating_system == 'Windows'): - user_values_filepath_string = f'.azure\\userValues.txt' + user_values_filepath_string = r'.azure\\userValues.txt' elif(operating_system == 'Linux' or operating_system == 'Darwin'): - user_values_filepath_string = f'.azure/userValues.txt' + user_values_filepath_string = r'.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) @@ -939,9 +939,9 @@ 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(user_values_location) + os.remove(user_values_location) except OSError: - pass + pass raise CLIInternalError(str.format(consts.Update_Agent_Failure, error_helm_upgrade.decode("ascii"))) try: os.remove(user_values_location) From ddf86c817c4c7ebceaf3311a68a37fe4daee7029 Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Wed, 16 Feb 2022 16:52:55 +0530 Subject: [PATCH 12/20] nit --- src/connectedk8s/azext_connectedk8s/custom.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index 248b6d41bb3..c70b64c61ac 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -903,9 +903,9 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" 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.Update_Agent_Failure, error_helm_get_values.decode("ascii"))) + 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", From e0d6b3184fd6ec94bcbd12bd6483ac372c883608 Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Wed, 16 Feb 2022 17:03:35 +0530 Subject: [PATCH 13/20] nit --- src/connectedk8s/azext_connectedk8s/custom.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index 87020f036e9..5e84151289e 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -905,7 +905,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"] @@ -938,7 +938,7 @@ 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(user_values_location) + os.remove(user_values_location) except OSError: pass raise CLIInternalError(str.format(consts.Update_Agent_Failure, error_helm_upgrade.decode("ascii"))) From dc6cabfe0e334984db13624b6eed51eb40954bd9 Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Wed, 16 Feb 2022 17:11:05 +0530 Subject: [PATCH 14/20] nit --- 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 5e84151289e..21eef97d137 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -905,7 +905,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"] From 670ace0aa6777ee0b631ee329d9d1448b32e7206 Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Wed, 16 Feb 2022 17:32:59 +0530 Subject: [PATCH 15/20] setp.py and history.rst updates --- src/connectedk8s/HISTORY.rst | 5 +++++ src/connectedk8s/setup.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/connectedk8s/HISTORY.rst b/src/connectedk8s/HISTORY.rst index 8cf543ef9f0..3022bc53de6 100644 --- a/src/connectedk8s/HISTORY.rst +++ b/src/connectedk8s/HISTORY.rst @@ -2,6 +2,11 @@ Release History =============== +1.2.4 +++++++ + +* Custom cert changes, using "userValues.txt" for existing values in update command instead of --reuse-values + 1.2.3 ++++++ 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 86783a9f163546cf67794cff85fd020f638f2626 Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Mon, 21 Feb 2022 13:34:54 +0530 Subject: [PATCH 16/20] modify the way of fetching userValues.txt path --- src/connectedk8s/azext_connectedk8s/custom.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index 21eef97d137..af14ec7e24d 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -777,8 +777,6 @@ 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) @@ -887,14 +885,7 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" if kube_context: cmd_helm_values.extend(["--kube-context", kube_context]) - if(operating_system == 'Windows'): - user_values_filepath_string = r'.azure\\userValues.txt' - elif(operating_system == 'Linux' or operating_system == 'Darwin'): - user_values_filepath_string = r'.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_filepath_string = os.path.join(os.path.expanduser('~'), '.azure', 'userValues.txt') 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) From d3500d2af60965950bceb5d29970c41f67dceb14 Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Mon, 21 Feb 2022 14:08:24 +0530 Subject: [PATCH 17/20] Waiting for LRO to complete before moving ahead with agent installation/deletion --- src/connectedk8s/azext_connectedk8s/custom.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index af14ec7e24d..4c17f1be20b 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -181,7 +181,8 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, https_pr except Exception as e: # pylint: disable=broad-except utils.arm_exception_handler(e, consts.Get_ConnectedCluster_Fault_Type, 'Failed to check if connected cluster resource already exists.') cc = generate_request_payload(configuration, location, public_key, tags, kubernetes_distro, kubernetes_infra) - create_cc_resource(client, resource_group_name, cluster_name, cc, no_wait) + cc_response = create_cc_resource(client, resource_group_name, cluster_name, cc, no_wait).result() + return cc_response else: telemetry.set_exception(exception='The kubernetes cluster is already onboarded', fault_type=consts.Cluster_Already_Onboarded_Fault_Type, summary='Kubernetes cluster already onboarded') @@ -281,7 +282,7 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, https_pr cc = generate_request_payload(configuration, location, public_key, tags, kubernetes_distro, kubernetes_infra) # Create connected cluster resource - put_cc_response = create_cc_resource(client, resource_group_name, cluster_name, cc, no_wait) + put_cc_response = create_cc_resource(client, resource_group_name, cluster_name, cc, no_wait).result() # Checking if custom locations rp is registered and fetching oid if it is registered enable_custom_locations, custom_locations_oid = check_cl_registration_and_get_oid(cmd, cl_oid) @@ -679,7 +680,7 @@ def delete_connectedk8s(cmd, client, resource_group_name, cluster_name, release_namespace = get_release_namespace(kube_config, kube_context, helm_client_location) if not release_namespace: - delete_cc_resource(client, resource_group_name, cluster_name, no_wait) + delete_cc_resource(client, resource_group_name, cluster_name, no_wait).result() return # Loading config map @@ -704,7 +705,7 @@ def delete_connectedk8s(cmd, client, resource_group_name, cluster_name, summary='The resource cannot be deleted as user is using proxy kubeconfig.') raise ClientRequestError("az connectedk8s delete is not supported when using the Cluster Connect kubeconfig.", recommendation="Run the az connectedk8s delete command with your kubeconfig file pointing to the actual Kubernetes cluster to ensure that the agents are cleaned up successfully as part of the delete command.") - delete_cc_resource(client, resource_group_name, cluster_name, no_wait) + delete_cc_resource(client, resource_group_name, cluster_name, no_wait).result() else: telemetry.set_exception(exception='Unable to delete connected cluster', fault_type=consts.Bad_DeleteRequest_Fault_Type, summary='The resource cannot be deleted as kubernetes cluster is onboarded with some other resource id') From 225238080a2515c23d5540b2709260a450a10fd3 Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Mon, 21 Feb 2022 14:18:35 +0530 Subject: [PATCH 18/20] update history.rst --- src/connectedk8s/HISTORY.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connectedk8s/HISTORY.rst b/src/connectedk8s/HISTORY.rst index 3022bc53de6..69a6c7c3e6b 100644 --- a/src/connectedk8s/HISTORY.rst +++ b/src/connectedk8s/HISTORY.rst @@ -5,7 +5,7 @@ Release History 1.2.4 ++++++ -* Custom cert changes, using "userValues.txt" for existing values in update command instead of --reuse-values +* Custom cert changes, using "userValues.txt" for existing values in update command instead of --reuse-values, fix to wait for LRO to complete before starting agent installation/deletion 1.2.3 ++++++ From 82989ab17fea6caeaa0b965a357ddfba8a166f6f Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Mon, 21 Feb 2022 14:45:15 +0530 Subject: [PATCH 19/20] fix --- src/connectedk8s/azext_connectedk8s/custom.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index 4c17f1be20b..3c1d7242942 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -753,9 +753,9 @@ def create_cc_resource(client, resource_group_name, cluster_name, cc, no_wait): def delete_cc_resource(client, resource_group_name, cluster_name, no_wait): try: - sdk_no_wait(no_wait, client.begin_delete, - resource_group_name=resource_group_name, - cluster_name=cluster_name) + return sdk_no_wait(no_wait, client.begin_delete, + resource_group_name=resource_group_name, + cluster_name=cluster_name) except Exception as e: utils.arm_exception_handler(e, consts.Delete_ConnectedCluster_Fault_Type, 'Unable to delete connected cluster resource') From a1f6a967f7dac6d288b46321ac7d1b5a713a49cc Mon Sep 17 00:00:00 2001 From: Siri Teja Reddy Kasireddy Date: Mon, 21 Feb 2022 16:22:59 +0530 Subject: [PATCH 20/20] fix location variable --- src/connectedk8s/azext_connectedk8s/custom.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index 3c1d7242942..4fde18967f2 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -886,8 +886,7 @@ def update_agents(cmd, client, resource_group_name, cluster_name, https_proxy="" if kube_context: cmd_helm_values.extend(["--kube-context", kube_context]) - user_values_filepath_string = os.path.join(os.path.expanduser('~'), '.azure', 'userValues.txt') - user_values_location = os.path.expanduser(os.path.join('~', user_values_filepath_string)) + user_values_location = os.path.join(os.path.expanduser('~'), '.azure', 'userValues.txt') 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()