From 48d93bf0bf9504f022ac6cedccc89d30155608c5 Mon Sep 17 00:00:00 2001 From: tal66 <77445020+tal66@users.noreply.github.com> Date: Thu, 23 Jun 2022 18:38:56 +0300 Subject: [PATCH 1/3] After `delete` show how to delete management cluster --- src/capi/azext_capi/custom.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/capi/azext_capi/custom.py b/src/capi/azext_capi/custom.py index 11a72c5..8e5ee33 100644 --- a/src/capi/azext_capi/custom.py +++ b/src/capi/azext_capi/custom.py @@ -720,7 +720,8 @@ def delete_workload_cluster(cmd, capi_name, resource_group_name=None, yes=False) if not yes and not prompt_y_n(msg, default="n"): return begin_msg = "Deleting workload cluster" - end_msg = "✓ Deleted workload cluster" + end_msg = "✓ Deleted workload cluster" \ + + f'\nNote: To also delete the management cluster, run "az capi management delete -n {capi_name}"' err_msg = "Couldn't delete workload cluster" try_command_with_spinner(cmd, command, begin_msg, end_msg, err_msg) if is_self_managed: From b209750a460c797ff39c55f9bfdd1f8b16efb028 Mon Sep 17 00:00:00 2001 From: tal66 <77445020+tal66@users.noreply.github.com> Date: Thu, 23 Jun 2022 18:40:13 +0300 Subject: [PATCH 2/3] typo --- src/capi/azext_capi/custom.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/capi/azext_capi/custom.py b/src/capi/azext_capi/custom.py index 8e5ee33..85fe5c3 100644 --- a/src/capi/azext_capi/custom.py +++ b/src/capi/azext_capi/custom.py @@ -61,7 +61,7 @@ def init_environment(cmd, prompt=True, management_cluster_name=None, error_msg = err.error_msg if management_cluster_components_missing_matching_expressions(error_msg): choices = ["Create a new management cluster", - "Use default kuberenetes cluster found and install CAPI required components", + "Use default kubernetes cluster found and install CAPI required components", "Exit"] msg = "The default kubernetes cluster found is missing required components for a management cluster.\ \nDo you want to:" @@ -305,10 +305,10 @@ def update_management_cluster(cmd, yes=False): def set_azure_identity_secret_env_vars(): identity_secret_name = "AZURE_CLUSTER_IDENTITY_SECRET_NAME" - indentity_secret_namespace = "AZURE_CLUSTER_IDENTITY_SECRET_NAMESPACE" + identity_secret_namespace = "AZURE_CLUSTER_IDENTITY_SECRET_NAMESPACE" cluster_identity_name = "CLUSTER_IDENTITY_NAME" os.environ[identity_secret_name] = os.environ.get(identity_secret_name, "cluster-identity-secret") - os.environ[indentity_secret_namespace] = os.environ.get(indentity_secret_namespace, "default") + os.environ[identity_secret_namespace] = os.environ.get(identity_secret_namespace, "default") os.environ[cluster_identity_name] = os.environ.get(cluster_identity_name, "cluster-identity") @@ -598,7 +598,7 @@ def create_workload_cluster( # pylint: disable=too-many-arguments,too-many-loca if windows: calico_manifest = "https://raw.githubusercontent.com/kubernetes-sigs/cluster-api-provider-azure/main/templates/addons/windows/calico/calico.yaml" # pylint: disable=line-too-long spinner_enter_message = "Deploying Windows Calico support" - spinner_exit_message = "✓ Deployed Windows Calico support to worload cluster" + spinner_exit_message = "✓ Deployed Windows Calico support to workload cluster" error_message = "Couldn't install Windows Calico support after waiting 5 minutes." apply_kubernetes_manifest(cmd, calico_manifest, workload_cfg, spinner_enter_message, spinner_exit_message, error_message) @@ -609,7 +609,7 @@ def create_workload_cluster( # pylint: disable=too-many-arguments,too-many-loca write_to_file(kubeproxy_manifest_file, manifest) spinner_enter_message = "Deploying Windows kube-proxy support" - spinner_exit_message = "✓ Deployed Windows kube-proxy support to worload cluster" + spinner_exit_message = "✓ Deployed Windows kube-proxy support to workload cluster" error_message = "Couldn't install Windows kube-proxy support after waiting 5 minutes." apply_kubernetes_manifest(cmd, kubeproxy_manifest_file, workload_cfg, spinner_enter_message, spinner_exit_message, error_message) @@ -793,10 +793,10 @@ def check_prereqs(cmd, install=False): # Check for required environment variables # TODO: remove this when AAD Pod Identity becomes the default - check_enviroment_variables() + check_environment_variables() -def check_enviroment_variables(): +def check_environment_variables(): required_env_vars = ["AZURE_CLIENT_ID", "AZURE_CLIENT_SECRET", "AZURE_SUBSCRIPTION_ID", "AZURE_TENANT_ID"] missing_env_vars = [v for v in required_env_vars if not check_environment_var(v)] missing_vars_len = len(missing_env_vars) From feaeaa3c7db60839e9de9894300418ccadf17901 Mon Sep 17 00:00:00 2001 From: tal66 <77445020+tal66@users.noreply.github.com> Date: Thu, 23 Jun 2022 21:33:32 +0300 Subject: [PATCH 3/3] show msg only if cluster name is the same --- src/capi/azext_capi/custom.py | 5 +++-- src/capi/azext_capi/tests/latest/test_capi_scenario.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/capi/azext_capi/custom.py b/src/capi/azext_capi/custom.py index 85fe5c3..830dbe1 100644 --- a/src/capi/azext_capi/custom.py +++ b/src/capi/azext_capi/custom.py @@ -720,8 +720,9 @@ def delete_workload_cluster(cmd, capi_name, resource_group_name=None, yes=False) if not yes and not prompt_y_n(msg, default="n"): return begin_msg = "Deleting workload cluster" - end_msg = "✓ Deleted workload cluster" \ - + f'\nNote: To also delete the management cluster, run "az capi management delete -n {capi_name}"' + end_msg = "✓ Deleted workload cluster" + if capi_name == kubectl_helpers.find_cluster_in_current_context(): + end_msg += f'\nNote: To also delete the management cluster, run "az capi management delete -n {capi_name}"' err_msg = "Couldn't delete workload cluster" try_command_with_spinner(cmd, command, begin_msg, end_msg, err_msg) if is_self_managed: diff --git a/src/capi/azext_capi/tests/latest/test_capi_scenario.py b/src/capi/azext_capi/tests/latest/test_capi_scenario.py index 2e2a345..63691f0 100644 --- a/src/capi/azext_capi/tests/latest/test_capi_scenario.py +++ b/src/capi/azext_capi/tests/latest/test_capi_scenario.py @@ -98,9 +98,10 @@ def test_capi_show(self, mock_def): self.assertEqual(mock.call_count, 3) + @patch('azext_capi.custom.kubectl_helpers.find_cluster_in_current_context', return_value="testcluster1") @patch('azext_capi.custom.is_self_managed_cluster', return_value=False) @patch('azext_capi.custom.exit_if_no_management_cluster') - def test_capi_delete(self, mock_def, mock_is_self_managed): + def test_capi_delete(self, mock_def, mock_is_self_managed, find_cluster_mock): # Test (indirectly) that user is prompted for confirmation by default with self.assertRaises(NoTTYException): self.cmd('capi delete --name testcluster1')