Skip to content
Merged
Show file tree
Hide file tree
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 Dec 6, 2022
d34a3cb
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani Dec 6, 2022
6842e24
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani Dec 6, 2022
9aafd26
modified: src/connectedk8s/HISTORY.rst
rohan-dassani Dec 6, 2022
69ce330
modified: src/connectedk8s/azext_connectedk8s/_constants.py
rohan-dassani Dec 26, 2022
8b7f6d3
modified: src/connectedk8s/HISTORY.rst
rohan-dassani Dec 26, 2022
60f1b98
modified: src/connectedk8s/HISTORY.rst
rohan-dassani Jan 3, 2023
bd81d60
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani Jan 3, 2023
257478a
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani Jan 3, 2023
f862fc8
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani Jan 4, 2023
2407073
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani Jan 4, 2023
1b90a22
modified: src/connectedk8s/azext_connectedk8s/_constants.py
rohan-dassani Jan 4, 2023
01b9cf2
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani Jan 5, 2023
6e581ba
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani Jan 5, 2023
67ceb35
modified: .github/CODEOWNERS
rohan-dassani Jan 31, 2023
516eb42
modified: src/connectedk8s/azext_connectedk8s/_precheckutils.py
rohan-dassani Jan 31, 2023
f39dc33
Revert " modified: .github/CODEOWNERS"
rohan-dassani Jan 31, 2023
df18eb6
Merge branch 'cli_heuristics_change' of https://github.com/rohan-dass…
rohan-dassani Jan 31, 2023
63e0c33
Merge https://github.com/Azure/azure-cli-extensions into cli_heuristi…
rohan-dassani Jan 31, 2023
0d4ce97
modified: src/connectedk8s/azext_connectedk8s/custom.py
rohan-dassani Jan 31, 2023
8288271
Merge branch 'cli_heuristics_change' of https://github.com/rohan-dass…
rohan-dassani Jan 31, 2023
4bd6385
modified: src/connectedk8s/azext_connectedk8s/_precheckutils.py
rohan-dassani Jan 31, 2023
1316c35
modified: src/connectedk8s/HISTORY.rst
rohan-dassani Jan 31, 2023
c67c88c
modified: src/connectedk8s/azext_connectedk8s/_precheckutils.py
rohan-dassani Jan 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/connectedk8s/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Release History
===============
1.3.7
++++++

* Added heuristics change - Remove detection of Distro and infra

1.3.6
++++++

Expand Down
4 changes: 2 additions & 2 deletions src/connectedk8s/azext_connectedk8s/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

# pylint: disable=line-too-long

Distribution_Enum_Values = ["auto", "generic", "openshift", "rancher_rke", "kind", "k3s", "minikube", "gke", "eks", "aks", "aks_management", "aks_workload", "capz", "aks_engine", "tkg", "canonical", "karbon"]
Infrastructure_Enum_Values = ["auto", "generic", "azure", "aws", "gcp", "azure_stack_hci", "azure_stack_hub", "azure_stack_edge", "vsphere", "windows_server"]
Distribution_Enum_Values = ["generic", "openshift", "rancher_rke", "kind", "k3s", "minikube", "gke", "eks", "aks", "aks_management", "aks_workload", "capz", "aks_engine", "tkg", "canonical", "karbon", "aks_edge_k3s", "aks_edge_k8s"]
Infrastructure_Enum_Values = ["generic", "azure", "aws", "gcp", "azure_stack_hci", "azure_stack_hub", "azure_stack_edge", "vsphere", "windows_server", "Windows 11 Enterprise", "Windows 11 Enterprise N", "Windows 11 IoT Enterprise", "Windows 11 Pro", "Windows 10 Enterprise", "Windows 10 Enterprise N", "Windows 10 Enterprise LTSC 2021", "Windows 10 Enterprise N LTSC 2021", "Windows 10 IoT Enterprise", "Windows 10 IoT Enterprise LTSC 2021", "Windows 10 Pro", "Windows 10 Enterprise LTSC 2019", "Windows 10 Enterprise N LTSC 2019", "Windows 10 IoT Enterprise LTSC 2019", "Windows Server 2022", "Windows Server 2022 Datacenter", "Windows Server 2022 Standard", "Windows Server 2019", "Windows Server 2019 Datacenter", "Windows Server 2019 Standard"]
AHB_Enum_Values = ["True", "False", "NotApplicable"]
Feature_Values = ["cluster-connect", "azure-rbac", "custom-locations"]
CRD_FOR_FORCE_DELETE = ["arccertificates.clusterconfig.azure.com", "azureclusteridentityrequests.clusterconfig.azure.com", "azureextensionidentities.clusterconfig.azure.com", "connectedclusters.arc.azure.com", "customlocationsettings.clusterconfig.azure.com", "extensionconfigs.clusterconfig.azure.com", "gitconfigs.clusterconfig.azure.com"]
Expand Down
144 changes: 26 additions & 118 deletions src/connectedk8s/azext_connectedk8s/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Comment thread
rohan-dassani marked this conversation as resolved.
Outdated

# Install helm client
helm_client_location = install_helm_client()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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:
Expand Down
2 changes: 1 addition & 1 deletion src/connectedk8s/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.

VERSION = '1.3.6'
VERSION = '1.3.7'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down