Skip to content

Commit

Permalink
fixup! Provide node distribution test (#481)
Browse files Browse the repository at this point in the history
Signed-off-by: Hannes Baum <hannes.baum@cloudandheat.com>
  • Loading branch information
cah-hbaum committed Feb 27, 2024
1 parent 9581df5 commit 4f85444
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,22 @@ def initialize_config(config):
return config


async def get_k8s_cluster_labelled_nodes(kubeconfig, labels):
"""Get the labels of the k8s cluster under test."""
_ = await kubernetes_asyncio.config.load_kube_config(kubeconfig)
async def get_k8s_cluster_labelled_nodes(kubeconfig, interesting_labels):
"""Get the labels per node of the k8s cluster under test, ignoring labels we don't need."""
await kubernetes_asyncio.config.load_kube_config(kubeconfig)

nodes = list()

async with kubernetes_asyncio.client.ApiClient() as api:
core_api = kubernetes_asyncio.client.CoreV1Api(api)
result = await core_api.list_node()
for item in result.items:
node = dict()
node_labels = item.metadata.labels
for label in labels:
try:
node[label] = node_labels[label]
except KeyError:
# Node is not labelled as a control plane node
pass
nodes.append(node)
for node in result.items:
filtered_labels = {
label: value
for label, value in node.metadata.labels.items()
if label in interesting_labels
}
nodes.append(filtered_labels)

return nodes

Expand Down Expand Up @@ -221,7 +218,7 @@ async def main(argv):
# Since we want to check if nodes are distributed, we want to do this from bigger
# infrastructure parts to smaller ones. So we first look if nodes are distributed
# across regions, then zones and then hosts. If one of these requirements is fulfilled,
# we probably don't need to check anymore, since a distribution was already detected.
# we don't need to check anymore, since a distribution was already detected.
labels = (
"topology.kubernetes.io/region",
"topology.kubernetes.io/zone",
Expand Down

0 comments on commit 4f85444

Please sign in to comment.