Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(integration/manual): support GKE Container-Optimized OS #1819

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Dependency setup for GKE cluster using Container-Optimized OS as base image
---

## Related issues

- https://github.com/longhorn/longhorn/issues/6165

## Test step

**Given** GKE cluster using Continer-Optimized OS (`COS_CONTAINER`) as the base image.

**When** Follow [instruction](https://github.com/longhorn/website/pull/884) to deploy the Longhorn GKE COS node agent.

**Then** Follow the [instruction](https://github.com/longhorn/website/pull/884) to verify dependency configuration/setup.
**And** Integration tests should pass.
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 @@ -3369,12 +3372,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