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 18, 2024
1 parent bbcd707 commit db5c5e8
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 39 deletions.
23 changes: 23 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 @@ -3346,12 +3349,32 @@ 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 is_k8s_node_gke_cos(core_api):
node = core_api.read_node(get_self_host_id())
return is_k8s_node_label(core_api,
K8S_GKE_OS_DISTRO_LABEL,
K8S_GKE_OS_DISTRO_COS,
node.metadata.name)


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 db5c5e8

Please sign in to comment.