Skip to content

Commit

Permalink
test(integration): support GKE Container-Optimized OS
Browse files Browse the repository at this point in the history
longhorn/longhorn-6165

Signed-off-by: Chin-Ya Huang <[email protected]>
  • Loading branch information
c3y1huang committed Mar 25, 2024
1 parent c38eea7 commit 1437559
Show file tree
Hide file tree
Showing 2 changed files with 287 additions and 58 deletions.
47 changes: 47 additions & 0 deletions manager/integration/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@

K8S_ZONE_LABEL = "topology.kubernetes.io/zone"

K8S_GKE_OS_DISTRO_LABEL = "cloud.google.com/gke-os-distribution"
K8S_GKE_OS_DISTRO_COS = "cos"

K8S_CLUSTER_AUTOSCALER_EVICT_KEY = \
"cluster-autoscaler.kubernetes.io/safe-to-evict"
K8S_CLUSTER_AUTOSCALER_SCALE_DOWN_DISABLED_KEY = \
Expand Down Expand Up @@ -3347,12 +3350,56 @@ def set_k8s_node_label(core_api, node_name, key, value):
core_api.patch_node(node_name, body=payload)


def is_k8s_node_label(core_api, label_key, label_value, node_name):
node = core_api.read_node(node_name)

if label_key in node.metadata.labels:
if node.metadata.labels[label_key] == label_value:
return True
return False


def set_k8s_node_zone_label(core_api, node_name, zone_name):
if is_k8s_node_label(core_api, K8S_ZONE_LABEL, zone_name, node_name):
return

k8s_zone_label = get_k8s_zone_label()

set_k8s_node_label(core_api, node_name, k8s_zone_label, zone_name)


def set_and_wait_k8s_nodes_zone_label(core_api, node_zone_map):
k8s_zone_label = get_k8s_zone_label()

for _ in range(RETRY_COUNTS):
for node_name, zone_name in node_zone_map.items():
set_k8s_node_label(core_api, node_name, k8s_zone_label, zone_name)

is_updated = False
for node_name, zone_name in node_zone_map.items():
is_updated = \
is_k8s_node_label(core_api,
k8s_zone_label, zone_name, node_name)
if not is_updated:
break

if is_updated:
break

time.sleep(RETRY_INTERVAL)

assert is_updated, \
f"Timeout while waiting for nodes zone label to be updated\n" \
f"Expected: {node_zone_map}"


def is_k8s_node_gke_cos(core_api):
return is_k8s_node_label(core_api,
K8S_GKE_OS_DISTRO_LABEL,
K8S_GKE_OS_DISTRO_COS,
get_self_host_id())


def get_k8s_zone_label():
ver_api = get_version_api_client()
k8s_ver_data = ver_api.get_code()
Expand Down
Loading

0 comments on commit 1437559

Please sign in to comment.