Skip to content

Commit

Permalink
[computes] add k8s label selector filter for service discovery
Browse files Browse the repository at this point in the history
In some cases, there might be multiple clusters running in the same
k8s environment. In such cases, we can pass a label selector to limit
the k8s namespaces that hue service-discovery looks at.

Change-Id: Ib98aeeafc7a19313abc3d7bc81bc17e4b646dd43
  • Loading branch information
amitsrivastava committed May 23, 2024
1 parent 9e27d5f commit b302114
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions desktop/core/src/desktop/management/commands/sync_warehouses.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@

# HUE_CONF_DIR=/etc/hue/conf HUE_IGNORE_PASSWORD_SCRIPT_ERRORS=1 /opt/hive/build/env/bin/hue sync_warehouses

from beeswax import models
from beeswax.conf import AUTH_USERNAME, AUTH_PASSWORD
from django.core.management.base import BaseCommand
from hadoop import confparse
import json
from kubernetes import client, config
import logging
import os
import re
import sys
import json
import logging

from django.core.management.base import BaseCommand
from kubernetes import client, config

from beeswax import models
from beeswax.conf import AUTH_PASSWORD, AUTH_USERNAME
from hadoop import confparse

LOG = logging.getLogger()

Expand Down Expand Up @@ -95,15 +97,17 @@ def get_computes_from_k8s():
catalogs = []
computes = []

for n in core_v1.list_namespace().items:
label_selector = os.environ.get("K8S_LABEL_SELECTOR") # clusterid=env-urmgt6-env

for n in core_v1.list_namespace(label_selector=label_selector).items:
try:
namespace = n.metadata.name
LOG.info('Getting details for ns: %s' % namespace)
item = {
'name': n.metadata.labels.get('displayname'),
'description': '%s (%s)' % (n.metadata.labels.get('displayname'), n.metadata.name),
'external_id': namespace,
#'creation_timestamp': n.metadata.labels.get('creation_timestamp'),
# 'creation_timestamp': n.metadata.labels.get('creation_timestamp'),
}

if namespace.startswith('warehouse-'):
Expand All @@ -119,6 +123,7 @@ def get_computes_from_k8s():

return computes


def update_hive_configs(namespace, hive, host, port=80):
hs2_stfs = apps_v1.read_namespaced_stateful_set('hiveserver2', namespace)

Expand Down Expand Up @@ -187,6 +192,7 @@ def populate_impala(namespace, impala):
impala['api_port'] = next((p.port for p in ports if p.name == 'web'), 25000)
update_impala_configs(namespace, impala, 'coordinator.%s.svc.cluster.local' % namespace)


def update_impala_configs(namespace, impala, host):
hive_configs = core_v1.read_namespaced_config_map('impala-coordinator-hive-conf', namespace)
hive_site_data = confparse.ConfParse(hive_configs.data['hive-site.xml'])
Expand Down

0 comments on commit b302114

Please sign in to comment.