-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Connectedk8s] Non-existing namespace deploy check + Error experience Improvement #3736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e0cfa4f
3db2c51
d6abcc1
1751c56
97f7792
432eda3
9e41a7a
5509d9a
d131e5a
dfffd8b
d8a5a76
7fd701e
73acc48
f73c556
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,9 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, https_pr | |
| graph_client = _graph_client_factory(cmd.cli_ctx) | ||
| onboarding_tenant_id = graph_client.config.tenant_id | ||
|
|
||
| # Checking provider registration status | ||
| utils.check_provider_registrations(cmd.cli_ctx) | ||
|
|
||
| # Setting kubeconfig | ||
| kube_config = set_kube_config(kube_config) | ||
|
|
||
|
|
@@ -119,6 +122,12 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, https_pr | |
| summary="Couldn't find any node on the kubernetes cluster with the architecture type 'amd64' and OS 'linux'") | ||
| logger.warning("Please ensure that this Kubernetes cluster have any nodes with OS 'linux' and architecture 'amd64', for scheduling the Arc-Agents onto and connecting to Azure. Learn more at {}".format("https://aka.ms/ArcK8sSupportedOSArchitecture")) | ||
|
|
||
| crb_permission = utils.can_create_clusterrolebindings(configuration) | ||
| if not crb_permission: | ||
| telemetry.set_exception(exception="Your credentials doesn't have permission to create clusterrolebindings on this kubernetes cluster.", fault_type=consts.Cannot_Create_ClusterRoleBindings_Fault_Type, | ||
| summary="Your credentials doesn't have permission to create clusterrolebindings on this kubernetes cluster.") | ||
| raise ValidationError("Your credentials doesn't have permission to create clusterrolebindings on this kubernetes cluster. Please check your permissions.") | ||
|
|
||
| # Get kubernetes cluster info | ||
| kubernetes_version = get_server_version(configuration) | ||
|
|
||
|
|
@@ -200,6 +209,36 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, https_pr | |
| "and corresponds to a different Kubernetes cluster.", recommendation="To onboard this Kubernetes cluster " + | ||
| "to Azure, specify different resource name or resource group name.") | ||
|
|
||
| try: | ||
| k8s_contexts = config.list_kube_config_contexts() # returns tuple of (all_contexts, current_context) | ||
| if kube_context: # if custom kube-context is specified | ||
| if k8s_contexts[1].get('name') == kube_context: | ||
| current_k8s_context = k8s_contexts[1] | ||
| else: | ||
| for context in k8s_contexts[0]: | ||
| if context.get('name') == kube_context: | ||
| current_k8s_context = context | ||
| break | ||
| else: | ||
| current_k8s_context = k8s_contexts[1] | ||
|
|
||
| current_k8s_namespace = current_k8s_context.get('context').get('namespace', "default") # Take "default" namespace, if not specified in the kube-config | ||
| namespace_exists = False | ||
| k8s_v1 = kube_client.CoreV1Api() | ||
| k8s_ns = k8s_v1.list_namespace() | ||
| for ns in k8s_ns.items: | ||
| if ns.metadata.name == current_k8s_namespace: | ||
| namespace_exists = True | ||
| break | ||
| if namespace_exists is False: | ||
| telemetry.set_exception(exception="Namespace doesn't exist", fault_type=consts.Default_Namespace_Does_Not_Exist_Fault_Type, | ||
| summary="The default namespace defined in the kubeconfig doesn't exist on the kubernetes cluster.") | ||
| raise ValidationError("The default namespace '{}' defined in the kubeconfig doesn't exist on the kubernetes cluster.".format(current_k8s_namespace)) | ||
| except ValidationError as e: | ||
| raise e | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we give a warning here instead of an error? What kind of scenarios come under the scope of this exception?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ValidationError raised in line 236, will be caught by that except block in 237, and thus an error. |
||
| except Exception as e: | ||
| logger.warning("Failed to validate if the active namespace exists on the kubernetes cluster. Exception: {}".format(str(e))) | ||
|
|
||
| # Resource group Creation | ||
| if resource_group_exists(cmd.cli_ctx, resource_group_name, subscription_id) is False: | ||
| from azure.cli.core.profiles import ResourceType | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.