From ee8b99c035f54f1c8ec79c259815860525344ee8 Mon Sep 17 00:00:00 2001 From: rohan-dassani <107916192+rohan-dassani@users.noreply.github.com> Date: Thu, 25 May 2023 11:55:35 +0530 Subject: [PATCH] Adding Cluster Connect endpoint network check (OBO endpoint) (#6308) --- src/connectedk8s/HISTORY.rst | 5 +++ .../azext_connectedk8s/_constants.py | 10 +++-- .../azext_connectedk8s/_precheckutils.py | 9 +++- src/connectedk8s/azext_connectedk8s/_utils.py | 43 ++++++++++++++----- src/connectedk8s/setup.py | 2 +- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/connectedk8s/HISTORY.rst b/src/connectedk8s/HISTORY.rst index 2dfcfd8e00f..69a5d8cea37 100644 --- a/src/connectedk8s/HISTORY.rst +++ b/src/connectedk8s/HISTORY.rst @@ -2,6 +2,11 @@ Release History +1.3.19 +++++++ + +* Adding outbound network connectivity check for Cluster Connect (OBO endpoint) + 1.3.18 ++++++ diff --git a/src/connectedk8s/azext_connectedk8s/_constants.py b/src/connectedk8s/azext_connectedk8s/_constants.py index b632614b141..4fd253dc389 100644 --- a/src/connectedk8s/azext_connectedk8s/_constants.py +++ b/src/connectedk8s/azext_connectedk8s/_constants.py @@ -195,24 +195,26 @@ Connected_Cluster_Resource = "connected_cluster_resource_snapshot.txt" DNS_Check = "dns_check.txt" K8s_Cluster_Info = "k8s_cluster_info.txt" -Outbound_Network_Connectivity_Check = "outbound_network_connectivity_check.txt" +Outbound_Network_Connectivity_Check_for_onboarding = "outbound_network_connectivity_check_for_onboarding.txt" +Outbound_Network_Connectivity_Check_for_cluster_connect = "outbound_network_connectivity_check_for_cluster_connect.txt" Events_of_Incomplete_Diagnoser_Job = "diagnoser_failure_events.txt" # Connect Precheck Diagnoser constants -Cluster_Diagnostic_Checks_Job_Registry_Path = "mcr.microsoft.com/azurearck8s/helmchart/stable/clusterdiagnosticchecks:0.1.1" +Cluster_Diagnostic_Checks_Job_Registry_Path = "mcr.microsoft.com/azurearck8s/helmchart/stable/clusterdiagnosticchecks:0.1.2" Cluster_Diagnostic_Checks_Helm_Install_Failed_Fault_Type = "Error while installing cluster diagnostic checks helm release" Cluster_Diagnostic_Checks_Execution_Failed_Fault_Type = "Error occured while executing cluster diagnostic checks" Cluster_Diagnostic_Checks_Release_Cleanup_Failed = "Error occured while cleaning up the cluster diagnostic checks helm release" Cluster_Diagnostic_Checks_Job_Not_Scheduled = 'Unable to schedule cluster-diagnostic-checks job' Cluster_Diagnostic_Checks_Job_Not_Complete = 'Unable to complete cluster-diagnostic-checks job after scheduling' Pre_Onboarding_Diagnostic_Checks_Execution_Failed = 'Exception occured while trying to execute pre-onboarding diagnostic checks' -Outbound_Connectivity_Check_Failed = "Outbound network connectivity check failed" +Outbound_Connectivity_Check_Failed_For_Onboarding = "Outbound network connectivity check failed for onboarding" DNS_Check_Failed = "DNS Resolution failed" Cluster_Diagnostic_Prechecks_Failed = "Cluster diagnostic prechecks failed" Cluster_Diagnostic_Prechecks_Incomplete = "Cluster diagnostic prechecks failed to complete" Cluster_Diagnostic_Checks_Pod_Description_Save_Failed = 'Failed to save cluster diagnostic checks pod description' Cluster_Diagnostic_Checks_Job_Log_Save_Failed = 'Failed to save cluster diagnostic checks job log' # Diagnostic Results Name -Outbound_Connectivity_Check_Result_String = "Outbound Network Connectivity Result:" +Outbound_Connectivity_Check_Check_String = "Outbound Network Connectivity Check" +Outbound_Connectivity_Check_Failed_For_Cluster_Connect = "Outbound network connectivity check failed for Cluster Connect" DNS_Check_Result_String = "DNS Result:" AZ_CLI_ADAL_TO_MSAL_MIGRATE_VERSION = '2.30.0' CLIENT_PROXY_VERSION = '1.3.022011' diff --git a/src/connectedk8s/azext_connectedk8s/_precheckutils.py b/src/connectedk8s/azext_connectedk8s/_precheckutils.py index 80b145beea6..5344b8bfb0c 100644 --- a/src/connectedk8s/azext_connectedk8s/_precheckutils.py +++ b/src/connectedk8s/azext_connectedk8s/_precheckutils.py @@ -59,18 +59,23 @@ def fetch_diagnostic_checks_results(corev1_api_instance, batchv1_api_instance, h cluster_diagnostic_checks_container_log_list = cluster_diagnostic_checks_container_log.split("\n") cluster_diagnostic_checks_container_log_list.pop(-1) dns_check_log = "" + outbound_connectivity_check_log = "" counter_container_logs = 1 # For retrieving only cluster_diagnostic_checks logs from the output for outputs in cluster_diagnostic_checks_container_log_list: - if consts.Outbound_Connectivity_Check_Result_String in outputs: + if consts.Outbound_Connectivity_Check_Check_String in outputs: counter_container_logs = 1 + if outbound_connectivity_check_log == "": + outbound_connectivity_check_log += outputs + else: + outbound_connectivity_check_log += " " + outputs elif consts.DNS_Check_Result_String in outputs: dns_check_log += outputs counter_container_logs = 0 elif counter_container_logs == 0: dns_check_log += " " + outputs dns_check, storage_space_available = azext_utils.check_cluster_DNS(dns_check_log, filepath_with_timestamp, storage_space_available, diagnoser_output) - outbound_connectivity_check, storage_space_available = azext_utils.check_cluster_outbound_connectivity(cluster_diagnostic_checks_container_log_list[-1], filepath_with_timestamp, storage_space_available, diagnoser_output) + outbound_connectivity_check, storage_space_available = azext_utils.check_cluster_outbound_connectivity(outbound_connectivity_check_log, filepath_with_timestamp, storage_space_available, diagnoser_output) else: return consts.Diagnostic_Check_Incomplete, storage_space_available diff --git a/src/connectedk8s/azext_connectedk8s/_utils.py b/src/connectedk8s/azext_connectedk8s/_utils.py index a9d03b116d5..5946af80a0b 100644 --- a/src/connectedk8s/azext_connectedk8s/_utils.py +++ b/src/connectedk8s/azext_connectedk8s/_utils.py @@ -234,25 +234,46 @@ def check_cluster_DNS(dns_check_log, filepath_with_timestamp, storage_space_avai def check_cluster_outbound_connectivity(outbound_connectivity_check_log, filepath_with_timestamp, storage_space_available, diagnoser_output): try: - outbound_connectivity_response = outbound_connectivity_check_log[-1:-4:-1] - outbound_connectivity_response = outbound_connectivity_response[::-1] - if consts.Outbound_Connectivity_Check_Result_String not in outbound_connectivity_check_log: + if consts.Outbound_Connectivity_Check_Check_String not in outbound_connectivity_check_log: return consts.Diagnostic_Check_Incomplete, storage_space_available + + Outbound_Connectivity_Log_For_Cluster_Connect = outbound_connectivity_check_log.split(' ')[0] + # extracting the endpoints for cluster connect feature + Cluster_Connect_Precheck_Endpoint_Url = Outbound_Connectivity_Log_For_Cluster_Connect.split(" : ")[1] + # extracting the obo endpoint response code from outbound connectivity check + Cluster_Connect_Precheck_Endpoint_response_code = Outbound_Connectivity_Log_For_Cluster_Connect.split(" : ")[2] + + if(Cluster_Connect_Precheck_Endpoint_response_code != "000"): + if storage_space_available: + cluster_connect_outbound_connectivity_check_path = os.path.join(filepath_with_timestamp, consts.Outbound_Network_Connectivity_Check_for_cluster_connect) + with open(cluster_connect_outbound_connectivity_check_path, 'w+') as outbound: + outbound.write("Response code " + Cluster_Connect_Precheck_Endpoint_response_code + "\nOutbound network connectivity check to cluster connect precheck endpoints passed successfully.") + else: + logger.warning("The outbound network connectivity check has failed for the endpoint - " + Cluster_Connect_Precheck_Endpoint_Url + "\nThis will affect the \"cluster-connect\" feature. If you are planning to use \"cluster-connect\" functionality , please ensure outbound connectivity to the above endpoint.\n") + telemetry.set_exception(exception='Outbound network connectivity check failed for the Cluster Connect endpoint', fault_type=consts.Outbound_Connectivity_Check_Failed_For_Cluster_Connect, summary="Outbound network connectivity check failed for the Cluster Connect precheck endpoint") + if storage_space_available: + cluster_connect_outbound_connectivity_check_path = os.path.join(filepath_with_timestamp, consts.Outbound_Network_Connectivity_Check_for_cluster_connect) + with open(cluster_connect_outbound_connectivity_check_path, 'w+') as outbound: + outbound.write("Response code " + Cluster_Connect_Precheck_Endpoint_response_code + "\nOutbound connectivity failed for the endpoint:" + Cluster_Connect_Precheck_Endpoint_Url + " ,this is an optional endpoint needed for cluster-connect feature.") + + Onboarding_Precheck_Endpoint_outbound_connectivity_response = outbound_connectivity_check_log[-1:-4:-1] + Onboarding_Precheck_Endpoint_outbound_connectivity_response = Onboarding_Precheck_Endpoint_outbound_connectivity_response[::-1] + # Validating if outbound connectiivty is working or not and displaying proper result - if(outbound_connectivity_response != "000"): + if(Onboarding_Precheck_Endpoint_outbound_connectivity_response != "000"): if storage_space_available: - outbound_connectivity_check_path = os.path.join(filepath_with_timestamp, consts.Outbound_Network_Connectivity_Check) + outbound_connectivity_check_path = os.path.join(filepath_with_timestamp, consts.Outbound_Network_Connectivity_Check_for_onboarding) with open(outbound_connectivity_check_path, 'w+') as outbound: - outbound.write("Response code " + outbound_connectivity_response + "\nOutbound network connectivity check passed successfully.") + outbound.write("Response code " + Onboarding_Precheck_Endpoint_outbound_connectivity_response + "\nOutbound network connectivity check to the onboarding precheck endpoint passed successfully.") return consts.Diagnostic_Check_Passed, storage_space_available else: - logger.warning("Error: We found an issue with outbound network connectivity from the cluster.\nPlease ensure to meet the following network requirements 'https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli#meet-network-requirements' \nIf your cluster is behind an outbound proxy server, please ensure that you have passed proxy parameters during the onboarding of your cluster.\nFor more details visit 'https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli#connect-using-an-outbound-proxy-server' \n") - diagnoser_output.append("Error: We found an issue with outbound network connectivity from the cluster.\nPlease ensure to meet the following network requirements 'https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli#meet-network-requirements' \nIf your cluster is behind an outbound proxy server, please ensure that you have passed proxy parameters during the onboarding of your cluster.\nFor more details visit 'https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli#connect-using-an-outbound-proxy-server' \n") + logger.warning("Error: We found an issue with outbound network connectivity from the cluster to the endpoints required for onboarding.\nPlease ensure to meet the following network requirements 'https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli#meet-network-requirements' \nIf your cluster is behind an outbound proxy server, please ensure that you have passed proxy parameters during the onboarding of your cluster.\nFor more details visit 'https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli#connect-using-an-outbound-proxy-server' \n") + diagnoser_output.append("Error: We found an issue with outbound network connectivity from the cluster to the endpoints required for onboarding.\nPlease ensure to meet the following network requirements 'https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli#meet-network-requirements' \nIf your cluster is behind an outbound proxy server, please ensure that you have passed proxy parameters during the onboarding of your cluster.\nFor more details visit 'https://docs.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli#connect-using-an-outbound-proxy-server' \n") if storage_space_available: - outbound_connectivity_check_path = os.path.join(filepath_with_timestamp, consts.Outbound_Network_Connectivity_Check) + outbound_connectivity_check_path = os.path.join(filepath_with_timestamp, consts.Outbound_Network_Connectivity_Check_for_onboarding) with open(outbound_connectivity_check_path, 'w+') as outbound: - outbound.write("Response code " + outbound_connectivity_response + "\nWe found an issue with Outbound network connectivity from the cluster.") - telemetry.set_exception(exception='Outbound network connectivity check failed', fault_type=consts.Outbound_Connectivity_Check_Failed, summary="Outbound network connectivity check failed in the cluster") + outbound.write("Response code " + Onboarding_Precheck_Endpoint_outbound_connectivity_response + "\nWe found an issue with Outbound network connectivity from the cluster required for onboarding.") + telemetry.set_exception(exception='Outbound network connectivity check failed for onboarding', fault_type=consts.Outbound_Connectivity_Check_Failed_For_Onboarding, summary="Outbound network connectivity check for onboarding failed in the cluster") return consts.Diagnostic_Check_Failed, storage_space_available # For handling storage or OS exception that may occur during the execution diff --git a/src/connectedk8s/setup.py b/src/connectedk8s/setup.py index a744f792388..aa850a26c19 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.3.18' +VERSION = '1.3.19' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers