Skip to content

Commit 5477901

Browse files
authored
Pavan/distro detect (#1708)
1 parent 6bb06a7 commit 5477901

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/connectedk8s/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Release History
44
===============
55

6+
0.2.1
7+
++++++
8+
* `az connectedk8s connect`: Added kubernetes distribution.
9+
610
0.2.0
711
++++++
812
* `az connectedk8s connect`: Added telemetry.

src/connectedk8s/azext_connectedk8s/custom.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
Pull_HelmChart_Fault_Type = 'helm-chart-pull-error'
5858
Export_HelmChart_Fault_Type = 'helm-chart-export-error'
5959
Get_Kubernetes_Version_Fault_Type = 'kubernetes-get-version-error'
60+
Get_Kubernetes_Distro_Fault_Type = 'kubernetes-get-distribution-error'
6061

6162

6263
# pylint:disable=unused-argument
@@ -102,7 +103,8 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, location
102103

103104
# Get kubernetes cluster info for telemetry
104105
kubernetes_version = get_server_version(configuration)
105-
kubernetes_distro = 'default'
106+
kubernetes_distro = get_kubernetes_distro(configuration)
107+
106108
kubernetes_properties = {
107109
'Context.Default.AzureCLI.KubernetesVersion': kubernetes_version,
108110
'Context.Default.AzureCLI.KubernetesDistro': kubernetes_distro
@@ -243,6 +245,7 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name, location
243245
chart_path = os.getenv('HELMCHART') if os.getenv('HELMCHART') else helm_chart_path
244246
cmd_helm_install = ["helm", "upgrade", "--install", "azure-arc", chart_path,
245247
"--set", "global.subscriptionId={}".format(subscription_id),
248+
"--set", "global.kubernetesDistro={}".format(kubernetes_distro),
246249
"--set", "global.resourceGroupName={}".format(resource_group_name),
247250
"--set", "global.resourceName={}".format(cluster_name),
248251
"--set", "global.location={}".format(location),
@@ -455,6 +458,21 @@ def get_server_version(configuration):
455458
logger.warning("Unable to fetch kubernetes version: %s\n", e)
456459

457460

461+
def get_kubernetes_distro(configuration):
462+
api_instance = kube_client.CoreV1Api(kube_client.ApiClient(configuration))
463+
try:
464+
api_response = api_instance.list_node()
465+
if api_response.items:
466+
labels = api_response.items[0].metadata.labels
467+
if labels.get("node.openshift.io/os_id") == "rhcos" or labels.get("node.openshift.io/os_id") == "rhel":
468+
return "openshift"
469+
return "default"
470+
except Exception as e: # pylint: disable=broad-except
471+
telemetry.set_exception(exception=e, fault_type=Get_Kubernetes_Distro_Fault_Type,
472+
summary='Unable to fetch kubernetes distribution')
473+
logger.warning("Exception while trying to fetch kubernetes distribution: %s\n", e)
474+
475+
458476
def generate_request_payload(configuration, location, public_key, tags):
459477
# Create connected cluster resource object
460478
aad_profile = ConnectedClusterAADProfile(

src/connectedk8s/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
# TODO: Confirm this is the right version number you want and it matches your
1818
# HISTORY.rst entry.
19-
VERSION = '0.2.0'
19+
20+
VERSION = '0.2.1'
2021

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

0 commit comments

Comments
 (0)