-
Notifications
You must be signed in to change notification settings - Fork 1.6k
cli-heuristics-change #5607
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
Merged
Merged
cli-heuristics-change #5607
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
314c19d
modified: src/connectedk8s/azext_connectedk8s/_constants.py
rohan-dassani d34a3cb
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani 6842e24
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani 9aafd26
modified: src/connectedk8s/HISTORY.rst
rohan-dassani 69ce330
modified: src/connectedk8s/azext_connectedk8s/_constants.py
rohan-dassani 8b7f6d3
modified: src/connectedk8s/HISTORY.rst
rohan-dassani 60f1b98
modified: src/connectedk8s/HISTORY.rst
rohan-dassani bd81d60
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani 257478a
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani f862fc8
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani 2407073
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani 1b90a22
modified: src/connectedk8s/azext_connectedk8s/_constants.py
rohan-dassani 01b9cf2
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani 6e581ba
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani 67ceb35
modified: .github/CODEOWNERS
rohan-dassani 516eb42
modified: src/connectedk8s/azext_connectedk8s/_precheckutils.py
rohan-dassani f39dc33
Revert " modified: .github/CODEOWNERS"
rohan-dassani df18eb6
Merge branch 'cli_heuristics_change' of https://github.com/rohan-dass…
rohan-dassani 63e0c33
Merge https://github.com/Azure/azure-cli-extensions into cli_heuristi…
rohan-dassani 0d4ce97
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani 8288271
Merge branch 'cli_heuristics_change' of https://github.com/rohan-dass…
rohan-dassani 4bd6385
modified: src/connectedk8s/azext_connectedk8s/_precheckutils.py
rohan-dassani 1316c35
modified: src/connectedk8s/HISTORY.rst
rohan-dassani c67c88c
modified: src/connectedk8s/azext_connectedk8s/_precheckutils.py
rohan-dassani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,7 +65,7 @@ | |
|
|
||
|
|
||
| def create_connectedk8s(cmd, client, resource_group_name, cluster_name, correlation_id=None, https_proxy="", http_proxy="", no_proxy="", proxy_cert="", location=None, | ||
| kube_config=None, kube_context=None, no_wait=False, tags=None, distribution='auto', infrastructure='auto', | ||
| kube_config=None, kube_context=None, no_wait=False, tags=None, distribution='generic', infrastructure='generic', | ||
| disable_auto_upgrade=False, cl_oid=None, onboarding_timeout="600", enable_private_link=None, private_link_scope_resource_id=None, | ||
| distribution_version=None, azure_hybrid_benefit=None, yes=False, container_log_path=None): | ||
| logger.warning("This operation might take a while...\n") | ||
|
|
@@ -151,14 +151,8 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, correlat | |
| raise ValidationError("Your credentials doesn't have permission to create clusterrolebindings on this kubernetes cluster. Please check your permissions.") | ||
|
|
||
| # Get kubernetes cluster info | ||
| if distribution == 'auto': | ||
| kubernetes_distro = get_kubernetes_distro(node_api_response) # (cluster heuristics) | ||
| else: | ||
| kubernetes_distro = distribution | ||
| if infrastructure == 'auto': | ||
| kubernetes_infra = get_kubernetes_infra(node_api_response) # (cluster heuristics) | ||
| else: | ||
| kubernetes_infra = infrastructure | ||
| kubernetes_distro = distribution | ||
| kubernetes_infra = infrastructure | ||
|
|
||
| kubernetes_properties = { | ||
| 'Context.Default.AzureCLI.KubernetesVersion': kubernetes_version, | ||
|
|
@@ -523,64 +517,6 @@ def get_private_key(key_pair): | |
| return PEM.encode(privKey_DER, "RSA PRIVATE KEY") | ||
|
|
||
|
|
||
| def get_kubernetes_distro(api_response): # Heuristic | ||
| if api_response is None: | ||
| return "generic" | ||
| try: | ||
| for node in api_response.items: | ||
| labels = node.metadata.labels | ||
| provider_id = str(node.spec.provider_id) | ||
| annotations = node.metadata.annotations | ||
| if labels.get("node.openshift.io/os_id"): | ||
| return "openshift" | ||
| if labels.get("kubernetes.azure.com/node-image-version"): | ||
| return "aks" | ||
| if labels.get("cloud.google.com/gke-nodepool") or labels.get("cloud.google.com/gke-os-distribution"): | ||
| return "gke" | ||
| if labels.get("eks.amazonaws.com/nodegroup"): | ||
| return "eks" | ||
| if labels.get("minikube.k8s.io/version"): | ||
| return "minikube" | ||
| if provider_id.startswith("kind://"): | ||
| return "kind" | ||
| if provider_id.startswith("k3s://"): | ||
| return "k3s" | ||
| if annotations.get("rke.cattle.io/external-ip") or annotations.get("rke.cattle.io/internal-ip"): | ||
| return "rancher_rke" | ||
| return "generic" | ||
| except Exception as e: # pylint: disable=broad-except | ||
| logger.debug("Error occured while trying to fetch kubernetes distribution: " + str(e)) | ||
| utils.kubernetes_exception_handler(e, consts.Get_Kubernetes_Distro_Fault_Type, 'Unable to fetch kubernetes distribution', | ||
| raise_error=False) | ||
| return "generic" | ||
|
|
||
|
|
||
| def get_kubernetes_infra(api_response): # Heuristic | ||
| if api_response is None: | ||
| return "generic" | ||
| try: | ||
| for node in api_response.items: | ||
| provider_id = str(node.spec.provider_id) | ||
| infra = provider_id.split(':')[0] | ||
| if infra == "k3s" or infra == "kind": | ||
| return "generic" | ||
| if infra == "azure": | ||
| return "azure" | ||
| if infra == "gce": | ||
| return "gcp" | ||
| if infra == "aws": | ||
| return "aws" | ||
| k8s_infra = utils.validate_infrastructure_type(infra) | ||
| if k8s_infra is not None: | ||
| return k8s_infra | ||
| return "generic" | ||
| except Exception as e: # pylint: disable=broad-except | ||
| logger.debug("Error occured while trying to fetch kubernetes infrastructure: " + str(e)) | ||
| utils.kubernetes_exception_handler(e, consts.Get_Kubernetes_Infra_Fault_Type, 'Unable to fetch kubernetes infrastructure', | ||
| raise_error=False) | ||
| return "generic" | ||
|
|
||
|
|
||
| def check_linux_amd64_node(api_response): | ||
| try: | ||
| for item in api_response.items: | ||
|
|
@@ -985,26 +921,19 @@ def update_connected_cluster(cmd, client, resource_group_name, cluster_name, htt | |
|
|
||
| # Fetch Connected Cluster for agent version | ||
| connected_cluster = get_connectedk8s(cmd, client, resource_group_name, cluster_name) | ||
| api_instance = kube_client.CoreV1Api() | ||
| node_api_response = None | ||
| # api_instance = kube_client.CoreV1Api() | ||
| # node_api_response = None | ||
|
|
||
| kubernetes_properties = {'Context.Default.AzureCLI.KubernetesVersion': kubernetes_version} | ||
|
|
||
| if hasattr(connected_cluster, 'distribution') and (connected_cluster.distribution is not None): | ||
| kubernetes_distro = connected_cluster.distribution | ||
| else: | ||
| node_api_response = utils.validate_node_api_response(api_instance, node_api_response) | ||
| kubernetes_distro = get_kubernetes_distro(node_api_response) | ||
| kubernetes_properties['Context.Default.AzureCLI.KubernetesDistro'] = kubernetes_distro | ||
|
|
||
| if hasattr(connected_cluster, 'infrastructure') and (connected_cluster.infrastructure is not None): | ||
| kubernetes_infra = connected_cluster.infrastructure | ||
| else: | ||
| node_api_response = utils.validate_node_api_response(api_instance, node_api_response) | ||
| kubernetes_infra = get_kubernetes_infra(node_api_response) | ||
| kubernetes_properties['Context.Default.AzureCLI.KubernetesInfra'] = kubernetes_infra | ||
|
|
||
| kubernetes_properties = { | ||
| 'Context.Default.AzureCLI.KubernetesVersion': kubernetes_version, | ||
| 'Context.Default.AzureCLI.KubernetesDistro': kubernetes_distro, | ||
| 'Context.Default.AzureCLI.KubernetesInfra': kubernetes_infra | ||
| } | ||
| telemetry.add_extension_event('connectedk8s', kubernetes_properties) | ||
|
|
||
| # Adding helm repo | ||
|
|
@@ -1123,7 +1052,7 @@ def upgrade_agents(cmd, client, resource_group_name, cluster_name, kube_config=N | |
|
|
||
| utils.try_list_node_fix() | ||
| api_instance = kube_client.CoreV1Api() | ||
| node_api_response = None | ||
| # node_api_response = None | ||
|
|
||
| # Install helm client | ||
| helm_client_location = install_helm_client() | ||
|
|
@@ -1171,23 +1100,16 @@ def upgrade_agents(cmd, client, resource_group_name, cluster_name, kube_config=N | |
| # Fetch Connected Cluster for agent version | ||
| connected_cluster = get_connectedk8s(cmd, client, resource_group_name, cluster_name) | ||
|
|
||
| kubernetes_properties = {'Context.Default.AzureCLI.KubernetesVersion': kubernetes_version} | ||
|
|
||
| if hasattr(connected_cluster, 'distribution') and (connected_cluster.distribution is not None): | ||
| kubernetes_distro = connected_cluster.distribution | ||
| else: | ||
| node_api_response = utils.validate_node_api_response(api_instance, node_api_response) | ||
| kubernetes_distro = get_kubernetes_distro(node_api_response) | ||
| kubernetes_properties['Context.Default.AzureCLI.KubernetesDistro'] = kubernetes_distro | ||
|
|
||
| if hasattr(connected_cluster, 'infrastructure') and (connected_cluster.infrastructure is not None): | ||
| kubernetes_infra = connected_cluster.infrastructure | ||
| else: | ||
| node_api_response = utils.validate_node_api_response(api_instance, node_api_response) | ||
| kubernetes_infra = get_kubernetes_infra(node_api_response) | ||
| kubernetes_properties['Context.Default.AzureCLI.KubernetesInfra'] = kubernetes_infra | ||
|
|
||
| kubernetes_properties = { | ||
| 'Context.Default.AzureCLI.KubernetesVersion': kubernetes_version, | ||
| 'Context.Default.AzureCLI.KubernetesDistro': kubernetes_distro, | ||
| 'Context.Default.AzureCLI.KubernetesInfra': kubernetes_infra | ||
| } | ||
| telemetry.add_extension_event('connectedk8s', kubernetes_properties) | ||
|
|
||
| # Adding helm repo | ||
|
|
@@ -1403,8 +1325,8 @@ def enable_features(cmd, client, resource_group_name, cluster_name, features, ku | |
| kubernetes_version = check_kube_connection() | ||
|
|
||
| utils.try_list_node_fix() | ||
| api_instance = kube_client.CoreV1Api() | ||
| node_api_response = None | ||
| # api_instance = kube_client.CoreV1Api() | ||
| # node_api_response = None | ||
|
|
||
| # Install helm client | ||
| helm_client_location = install_helm_client() | ||
|
|
@@ -1414,23 +1336,16 @@ def enable_features(cmd, client, resource_group_name, cluster_name, features, ku | |
| # Fetch Connected Cluster for agent version | ||
| connected_cluster = get_connectedk8s(cmd, client, resource_group_name, cluster_name) | ||
|
|
||
| kubernetes_properties = {'Context.Default.AzureCLI.KubernetesVersion': kubernetes_version} | ||
|
|
||
| if hasattr(connected_cluster, 'distribution') and (connected_cluster.distribution is not None): | ||
| kubernetes_distro = connected_cluster.distribution | ||
| else: | ||
| node_api_response = utils.validate_node_api_response(api_instance, node_api_response) | ||
| kubernetes_distro = get_kubernetes_distro(node_api_response) | ||
| kubernetes_properties['Context.Default.AzureCLI.KubernetesDistro'] = kubernetes_distro | ||
|
|
||
| if hasattr(connected_cluster, 'infrastructure') and (connected_cluster.infrastructure is not None): | ||
| kubernetes_infra = connected_cluster.infrastructure | ||
| else: | ||
| node_api_response = utils.validate_node_api_response(api_instance, node_api_response) | ||
| kubernetes_infra = get_kubernetes_infra(node_api_response) | ||
| kubernetes_properties['Context.Default.AzureCLI.KubernetesInfra'] = kubernetes_infra | ||
|
|
||
| kubernetes_properties = { | ||
| 'Context.Default.AzureCLI.KubernetesVersion': kubernetes_version, | ||
| 'Context.Default.AzureCLI.KubernetesDistro': kubernetes_distro, | ||
| 'Context.Default.AzureCLI.KubernetesInfra': kubernetes_infra | ||
| } | ||
| telemetry.add_extension_event('connectedk8s', kubernetes_properties) | ||
|
|
||
| # Adding helm repo | ||
|
|
@@ -1522,8 +1437,8 @@ def disable_features(cmd, client, resource_group_name, cluster_name, features, k | |
| kubernetes_version = check_kube_connection() | ||
|
|
||
| utils.try_list_node_fix() | ||
| api_instance = kube_client.CoreV1Api() | ||
| node_api_response = None | ||
| # api_instance = kube_client.CoreV1Api() | ||
| # node_api_response = None | ||
|
|
||
| # Install helm client | ||
| helm_client_location = install_helm_client() | ||
|
|
@@ -1533,23 +1448,16 @@ def disable_features(cmd, client, resource_group_name, cluster_name, features, k | |
| # Fetch Connected Cluster for agent version | ||
| connected_cluster = get_connectedk8s(cmd, client, resource_group_name, cluster_name) | ||
|
|
||
| kubernetes_properties = {'Context.Default.AzureCLI.KubernetesVersion': kubernetes_version} | ||
|
|
||
| if hasattr(connected_cluster, 'distribution') and (connected_cluster.distribution is not None): | ||
| kubernetes_distro = connected_cluster.distribution | ||
| else: | ||
| node_api_response = utils.validate_node_api_response(api_instance, node_api_response) | ||
| kubernetes_distro = get_kubernetes_distro(node_api_response) | ||
| kubernetes_properties['Context.Default.AzureCLI.KubernetesDistro'] = kubernetes_distro | ||
|
|
||
| if hasattr(connected_cluster, 'infrastructure') and (connected_cluster.infrastructure is not None): | ||
| kubernetes_infra = connected_cluster.infrastructure | ||
| else: | ||
| node_api_response = utils.validate_node_api_response(api_instance, node_api_response) | ||
| kubernetes_infra = get_kubernetes_infra(node_api_response) | ||
| kubernetes_properties['Context.Default.AzureCLI.KubernetesInfra'] = kubernetes_infra | ||
|
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. did we test if telemetry is flowing through correctly like this? |
||
|
|
||
| kubernetes_properties = { | ||
| 'Context.Default.AzureCLI.KubernetesVersion': kubernetes_version, | ||
| 'Context.Default.AzureCLI.KubernetesDistro': kubernetes_distro, | ||
| 'Context.Default.AzureCLI.KubernetesInfra': kubernetes_infra | ||
| } | ||
| telemetry.add_extension_event('connectedk8s', kubernetes_properties) | ||
|
|
||
| if disable_cluster_connect: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.