From 06e2207448de8b2ef0b2a9e0b3150b23403c1b46 Mon Sep 17 00:00:00 2001 From: Hannes Baum Date: Wed, 10 Apr 2024 10:44:22 +0200 Subject: [PATCH 01/10] Updates to Node distribution test (#489) - added a new input that enables testing the test by providing yaml files containing label information for different nodes - added "test-example.yaml" containing an example for such a test file - removed the internal config, since the normal config file is already provided and read in as a default Signed-off-by: Hannes Baum --- .../k8s-node-distribution-check.py | 47 ++++++++----------- .../k8s-node-distribution/test-example.yaml | 27 +++++++++++ 2 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 Tests/kaas/k8s-node-distribution/test-example.yaml diff --git a/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py b/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py index a0c167ff9..8423f2d61 100755 --- a/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py +++ b/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py @@ -40,27 +40,6 @@ import yaml -logging_config = { - "level": "INFO", - "version": 1, - "disable_existing_loggers": False, - "formatters": { - "k8s-node-distribution-check": { - "format": "%(levelname)s: %(message)s" - } - }, - "handlers": { - "console": { - "class": "logging.StreamHandler", - "formatter": "k8s-node-distribution-check", - "stream": "ext://sys.stdout" - } - }, - "root": { - "handlers": ["console"] - } -} - logger = logging.getLogger(__name__) @@ -79,6 +58,7 @@ class DistributionException(BaseException): class Config: config_path = "./config.yaml" kubeconfig = None + testconfig = None logging = None @@ -99,6 +79,7 @@ def print_usage(): The following arguments can be set: -c/--config PATH/TO/CONFIG - Path to the config file of the test script -k/--kubeconfig PATH/TO/KUBECONFIG - Path to the kubeconfig of the server we want to check + -t/--test PATH/TO/YAML - Input a formatted yaml file to test the script functionality -h - Output help """) @@ -108,7 +89,7 @@ def parse_arguments(argv): config = Config() try: - opts, args = getopt.gnu_getopt(argv, "c:k:h", ["config", "kubeconfig", "help"]) + opts, args = getopt.gnu_getopt(argv, "c:k:t:h", ["config", "kubeconfig", "test", "help"]) except getopt.GetoptError: raise ConfigException @@ -119,6 +100,9 @@ def parse_arguments(argv): config.config_path = opt[1] if opt[0] == "-k" or opt[0] == "--kubeconfig": config.kubeconfig = opt[1] + if opt[0] == "-t" or opt[0] == "--test": + with open(opt[1], 'r') as file: + config.testconfig = yaml.safe_load(file) return config @@ -143,12 +127,12 @@ def initialize_config(config): with open(config.config_path, "r") as f: config.logging = yaml.safe_load(f)['logging'] except OSError: - logger.warning(f"The config file under {config.config_path} couldn't be found, " - f"falling back to the default config.") + logger.warning(f"The config file under {config.config_path} couldn't be found.") + exit(1) finally: # Setup logging if the config file with the relevant information could be loaded before # Otherwise, we initialize logging with the included literal - setup_logging(config.logging or logging_config) + setup_logging(config.logging) if config.kubeconfig is None: raise ConfigException("A kubeconfig needs to be set in order to test a k8s cluster version.") @@ -194,7 +178,10 @@ def compare_labels(node_list, labels, node_type="master"): logger.warning(f"There seems to be no distribution across multiple {label.split('/')[1]}s " "or labels aren't set correctly across nodes.") else: - logger.info(f"The nodes are distributed across {str(len(set(label_data[label])))} {label.split('/')[1]}s.") + logger.info( + f"The {node_type} nodes are distributed across " + f"{str(len(set(label_data[label])))} {label.split('/')[1]}s." + ) return if node_type == "master": @@ -225,7 +212,13 @@ async def main(argv): "topology.scs.community/host-id", ) - nodes = await get_k8s_cluster_labelled_nodes(config.kubeconfig, labels + ("node-role.kubernetes.io/control-plane", )) + if isinstance(config.testconfig, dict): + nodes = [v for _, v in config.testconfig.items()] + else: + nodes = await get_k8s_cluster_labelled_nodes( + config.kubeconfig, + labels + ("node-role.kubernetes.io/control-plane", ) + ) if len(nodes) < 2: logger.error("The tested cluster only contains a single node, which can't comply with the standard.") diff --git a/Tests/kaas/k8s-node-distribution/test-example.yaml b/Tests/kaas/k8s-node-distribution/test-example.yaml new file mode 100644 index 000000000..e81018a4e --- /dev/null +++ b/Tests/kaas/k8s-node-distribution/test-example.yaml @@ -0,0 +1,27 @@ +master0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" +master1: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone2" + topology.scs.community/host-id: "vm1" +master2: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone3" + topology.scs.community/host-id: "vm2" +worker0: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm3" +worker1: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone2" + topology.scs.community/host-id: "vm4" +worker2: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone3" + topology.scs.community/host-id: "vm5" From 300090e4a437d8eba098403f568a2ebabc4e0de4 Mon Sep 17 00:00:00 2001 From: Hannes Baum Date: Mon, 15 Apr 2024 16:11:51 +0200 Subject: [PATCH 02/10] Change for requested updates Some dates fixing some problems mentioned by @martinmo. Signed-off-by: Hannes Baum --- .../k8s-node-distribution-check.py | 103 ++++++------------ 1 file changed, 35 insertions(+), 68 deletions(-) diff --git a/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py b/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py index 8423f2d61..4a41635d9 100755 --- a/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py +++ b/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py @@ -37,8 +37,17 @@ import logging import logging.config import sys -import yaml +# It is important to note, that the order of these labels matters for this test. +# 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 don't need to check anymore, since a distribution was already detected. +labels = ( + "topology.kubernetes.io/region", + "topology.kubernetes.io/zone", + "topology.scs.community/host-id", +) logger = logging.getLogger(__name__) @@ -56,10 +65,7 @@ class DistributionException(BaseException): class Config: - config_path = "./config.yaml" kubeconfig = None - testconfig = None - logging = None def print_usage(): @@ -77,9 +83,7 @@ def print_usage(): 2 - No distribution according to the standard could be detected for the nodes available. The following arguments can be set: - -c/--config PATH/TO/CONFIG - Path to the config file of the test script -k/--kubeconfig PATH/TO/KUBECONFIG - Path to the kubeconfig of the server we want to check - -t/--test PATH/TO/YAML - Input a formatted yaml file to test the script functionality -h - Output help """) @@ -89,54 +93,27 @@ def parse_arguments(argv): config = Config() try: - opts, args = getopt.gnu_getopt(argv, "c:k:t:h", ["config", "kubeconfig", "test", "help"]) + opts, args = getopt.gnu_getopt(argv, "k:t:h", ["kubeconfig=", "test=", "help"]) except getopt.GetoptError: raise ConfigException for opt in opts: if opt[0] == "-h" or opt[0] == "--help": raise HelpException - if opt[0] == "-c" or opt[0] == "--config": - config.config_path = opt[1] if opt[0] == "-k" or opt[0] == "--kubeconfig": config.kubeconfig = opt[1] - if opt[0] == "-t" or opt[0] == "--test": - with open(opt[1], 'r') as file: - config.testconfig = yaml.safe_load(file) return config -def setup_logging(config_log): - - logging.config.dictConfig(config_log) - loggers = [ - logging.getLogger(name) - for name in logging.root.manager.loggerDict - if not logging.getLogger(name).level - ] - - for log in loggers: - log.setLevel(config_log['level']) - - def initialize_config(config): """Initialize the configuration for the test script""" - try: - with open(config.config_path, "r") as f: - config.logging = yaml.safe_load(f)['logging'] - except OSError: - logger.warning(f"The config file under {config.config_path} couldn't be found.") - exit(1) - finally: - # Setup logging if the config file with the relevant information could be loaded before - # Otherwise, we initialize logging with the included literal - setup_logging(config.logging) - if config.kubeconfig is None: raise ConfigException("A kubeconfig needs to be set in order to test a k8s cluster version.") + logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO) + return config @@ -160,7 +137,7 @@ async def get_k8s_cluster_labelled_nodes(kubeconfig, interesting_labels): return nodes -def compare_labels(node_list, labels, node_type="master"): +def compare_labels(node_list, node_type="master"): label_data = {key: list() for key in labels} @@ -192,34 +169,7 @@ def compare_labels(node_list, labels, node_type="master"): return -async def main(argv): - try: - config = initialize_config(parse_arguments(argv)) - except (OSError, ConfigException, HelpException) as e: - if hasattr(e, 'message'): - logger.error(e.message) - print_usage() - return 1 - - # It is important to note, that the order of these labels matters for this test. - # 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 don't need to check anymore, since a distribution was already detected. - labels = ( - "topology.kubernetes.io/region", - "topology.kubernetes.io/zone", - "topology.scs.community/host-id", - ) - - if isinstance(config.testconfig, dict): - nodes = [v for _, v in config.testconfig.items()] - else: - nodes = await get_k8s_cluster_labelled_nodes( - config.kubeconfig, - labels + ("node-role.kubernetes.io/control-plane", ) - ) - +def check_nodes(nodes): if len(nodes) < 2: logger.error("The tested cluster only contains a single node, which can't comply with the standard.") return 2 @@ -229,10 +179,10 @@ async def main(argv): if len(labelled_master_nodes) >= 1: worker_nodes = [node for node in nodes if "node-role.kubernetes.io/control-plane" not in node] # Compare the labels of both types, since we have enough of them with labels - compare_labels(labelled_master_nodes, labels, "master") - compare_labels(worker_nodes, labels, "worker") + compare_labels(labelled_master_nodes, "master") + compare_labels(worker_nodes, "worker") else: - compare_labels(nodes, labels) + compare_labels(nodes) except DistributionException as e: logger.error(str(e)) return 2 @@ -240,6 +190,23 @@ async def main(argv): return 0 +async def main(argv): + try: + config = initialize_config(parse_arguments(argv)) + except (OSError, ConfigException, HelpException) as e: + if hasattr(e, 'message'): + logger.error(e.message) + print_usage() + return 1 + + nodes = await get_k8s_cluster_labelled_nodes( + config.kubeconfig, + labels + ("node-role.kubernetes.io/control-plane", ) + ) + + return check_nodes(nodes) + + if __name__ == "__main__": return_code = asyncio.run(main(sys.argv[1:])) sys.exit(return_code) From c71520a0af44b548d6ede851e8fc557be2b5e70d Mon Sep 17 00:00:00 2001 From: Hannes Baum Date: Thu, 18 Apr 2024 10:32:33 +0200 Subject: [PATCH 03/10] Add additional test files Adds additional test files and removes previously deprecated config (template) files. Signed-off-by: Hannes Baum --- .../config.yaml.template | 24 ------------------- .../test-no-distribution.yaml | 9 +++++++ .../test-not-enough-nodes.yaml | 5 ++++ .../{test-example.yaml => test-success.yaml} | 0 4 files changed, 14 insertions(+), 24 deletions(-) delete mode 100644 Tests/kaas/k8s-node-distribution/config.yaml.template create mode 100644 Tests/kaas/k8s-node-distribution/test-no-distribution.yaml create mode 100644 Tests/kaas/k8s-node-distribution/test-not-enough-nodes.yaml rename Tests/kaas/k8s-node-distribution/{test-example.yaml => test-success.yaml} (100%) diff --git a/Tests/kaas/k8s-node-distribution/config.yaml.template b/Tests/kaas/k8s-node-distribution/config.yaml.template deleted file mode 100644 index 0f96da24d..000000000 --- a/Tests/kaas/k8s-node-distribution/config.yaml.template +++ /dev/null @@ -1,24 +0,0 @@ -## Configuration file for the K8s Version Recency Test - -logging: - level: INFO - version: 1 - disable_existing_loggers: False - formatters: - k8s-node-distribution-check: - format: "%(levelname)s: %(message)s" - handlers: - console: - class: logging.StreamHandler - formatter: k8s-node-distribution-check - stream: ext://sys.stdout - file: - class: logging.handlers.WatchedFileHandler - formatter: k8s-node-distribution-check - filename: MY-LOG-FILE-NAME.log - root: # Configuring the default (root) logger is highly recommended - handlers: [console] - loggers: - k8s-node-distribution-check: - handlers: [console, file] - propagate: no \ No newline at end of file diff --git a/Tests/kaas/k8s-node-distribution/test-no-distribution.yaml b/Tests/kaas/k8s-node-distribution/test-no-distribution.yaml new file mode 100644 index 000000000..b8e565e3f --- /dev/null +++ b/Tests/kaas/k8s-node-distribution/test-no-distribution.yaml @@ -0,0 +1,9 @@ +master0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" +worker0: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" \ No newline at end of file diff --git a/Tests/kaas/k8s-node-distribution/test-not-enough-nodes.yaml b/Tests/kaas/k8s-node-distribution/test-not-enough-nodes.yaml new file mode 100644 index 000000000..f0a3f9101 --- /dev/null +++ b/Tests/kaas/k8s-node-distribution/test-not-enough-nodes.yaml @@ -0,0 +1,5 @@ +node0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" \ No newline at end of file diff --git a/Tests/kaas/k8s-node-distribution/test-example.yaml b/Tests/kaas/k8s-node-distribution/test-success.yaml similarity index 100% rename from Tests/kaas/k8s-node-distribution/test-example.yaml rename to Tests/kaas/k8s-node-distribution/test-success.yaml From a22b8c3f818e0ca1d41f7cd6cc29bbbfe26b7153 Mon Sep 17 00:00:00 2001 From: Martin Morgenstern Date: Wed, 24 Apr 2024 18:42:19 +0200 Subject: [PATCH 04/10] Add pytest script and more scenarios Signed-off-by: Martin Morgenstern --- .../k8s-node-distribution/check_nodes_test.py | 69 +++++++++++++++++++ .../testdata/test-missing-labels.yaml | 10 +++ .../test-no-distribution-1.yaml} | 0 .../testdata/test-no-distribution-2.yaml | 27 ++++++++ .../{ => testdata}/test-not-enough-nodes.yaml | 0 .../test-success-1.yaml} | 3 + .../testdata/test-success-2.yaml | 30 ++++++++ 7 files changed, 139 insertions(+) create mode 100644 Tests/kaas/k8s-node-distribution/check_nodes_test.py create mode 100644 Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml rename Tests/kaas/k8s-node-distribution/{test-no-distribution.yaml => testdata/test-no-distribution-1.yaml} (100%) create mode 100644 Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml rename Tests/kaas/k8s-node-distribution/{ => testdata}/test-not-enough-nodes.yaml (100%) rename Tests/kaas/k8s-node-distribution/{test-success.yaml => testdata/test-success-1.yaml} (90%) create mode 100644 Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml diff --git a/Tests/kaas/k8s-node-distribution/check_nodes_test.py b/Tests/kaas/k8s-node-distribution/check_nodes_test.py new file mode 100644 index 000000000..8d29ff3a0 --- /dev/null +++ b/Tests/kaas/k8s-node-distribution/check_nodes_test.py @@ -0,0 +1,69 @@ +""" +Unit tests for node distribution check functions. + +(c) Martin Morgenstern , 4/2024 +SPDX-License-Identifier: CC-BY-SA-4.0 +""" + +from pathlib import Path +import importlib +import yaml + +import pytest + + +check_nodes = importlib.import_module("k8s-node-distribution-check").check_nodes + + +HERE = Path(__file__).parent + + +def load_testdata(filename): + with open(Path(HERE, "testdata", filename)) as stream: + return yaml.load(stream, yaml.SafeLoader) + + +@pytest.mark.parametrize("yaml_file", ["test-success-1.yaml", "test-success-2.yaml"]) +def test_success_single_region_warning(yaml_file, caplog): + data = load_testdata(yaml_file) + assert check_nodes(data.values()) == 0 + assert len(caplog.records) == 2 + for record in caplog.records: + assert "no distribution across multiple regions" in record.message + assert record.levelname == "WARNING" + + +def test_not_enough_nodes(caplog): + data = load_testdata("test-not-enough-nodes.yaml") + assert check_nodes(data.values()) == 2 + assert len(caplog.records) == 1 + assert "cluster only contains a single node" in caplog.records[0].message + assert caplog.records[0].levelname == "ERROR" + + +@pytest.mark.parametrize("yaml_file", ["test-no-distribution-1.yaml", "test-no-distribution-2.yaml"]) +def test_no_distribution(yaml_file, caplog): + data = load_testdata(yaml_file) + with caplog.at_level("ERROR"): + assert check_nodes(data.values()) == 2 + assert len(caplog.records) == 1 + record = caplog.records[0] + assert "distribution of nodes described in the standard couldn't be detected" in record.message + assert record.levelname == "ERROR" + + +def test_missing_label(caplog): + data = load_testdata("test-missing-labels.yaml") + assert check_nodes(data.values()) == 2 + no_distribution_records = [ + record for record in caplog.records + if "distribution of nodes described in the standard couldn't be detected" in record.message + ] + assert len(no_distribution_records) == 1 + assert no_distribution_records[0].levelname == "ERROR" + hostid_missing_records = [ + record for record in caplog.records + if "label for host-ids" in record.message + ] + assert len(hostid_missing_records) == 1 + assert hostid_missing_records[0].levelname == "ERROR" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml new file mode 100644 index 000000000..d0613ffc8 --- /dev/null +++ b/Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml @@ -0,0 +1,10 @@ +control0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" +control1: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + # host-id missing diff --git a/Tests/kaas/k8s-node-distribution/test-no-distribution.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml similarity index 100% rename from Tests/kaas/k8s-node-distribution/test-no-distribution.yaml rename to Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml new file mode 100644 index 000000000..ae86ef1b5 --- /dev/null +++ b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml @@ -0,0 +1,27 @@ +master0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" +master1: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" +master2: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" +worker0: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm1" +worker1: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm1" +worker2: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm1" diff --git a/Tests/kaas/k8s-node-distribution/test-not-enough-nodes.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-not-enough-nodes.yaml similarity index 100% rename from Tests/kaas/k8s-node-distribution/test-not-enough-nodes.yaml rename to Tests/kaas/k8s-node-distribution/testdata/test-not-enough-nodes.yaml diff --git a/Tests/kaas/k8s-node-distribution/test-success.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml similarity index 90% rename from Tests/kaas/k8s-node-distribution/test-success.yaml rename to Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml index e81018a4e..d95230f05 100644 --- a/Tests/kaas/k8s-node-distribution/test-success.yaml +++ b/Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml @@ -1,3 +1,6 @@ +# Success Scenario 1: +# All nodes have distinct host-ids and zones, but share the region. + master0: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml new file mode 100644 index 000000000..08dc26e83 --- /dev/null +++ b/Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml @@ -0,0 +1,30 @@ +# Success Scenario 2: +# Nodes share the host-id and region, but are in different zones. + +master0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" +master1: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone2" + topology.scs.community/host-id: "vm0" +master2: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone3" + topology.scs.community/host-id: "vm0" +worker0: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm1" +worker1: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone2" + topology.scs.community/host-id: "vm1" +worker2: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone3" + topology.scs.community/host-id: "vm1" From a00f5a944620e13cdb60675208583bfc474f28d8 Mon Sep 17 00:00:00 2001 From: Martin Morgenstern Date: Wed, 24 Apr 2024 18:44:01 +0200 Subject: [PATCH 05/10] Replace masterN with control-N in test data Signed-off-by: Martin Morgenstern --- .../testdata/test-no-distribution-1.yaml | 4 ++-- .../testdata/test-no-distribution-2.yaml | 12 ++++++------ .../testdata/test-success-1.yaml | 12 ++++++------ .../testdata/test-success-2.yaml | 12 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml index b8e565e3f..954618504 100644 --- a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml +++ b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml @@ -1,9 +1,9 @@ -master0: +control-0: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm0" -worker0: +worker-0: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm0" \ No newline at end of file diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml index ae86ef1b5..b1bb6b130 100644 --- a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml +++ b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml @@ -1,27 +1,27 @@ -master0: +control-0: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm0" -master1: +control-1: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm0" -master2: +control-2: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm0" -worker0: +worker-0: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm1" -worker1: +worker-1: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm1" -worker2: +worker-2: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm1" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml index d95230f05..1098d51fb 100644 --- a/Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml +++ b/Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml @@ -1,30 +1,30 @@ # Success Scenario 1: # All nodes have distinct host-ids and zones, but share the region. -master0: +control-0: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm0" -master1: +control-1: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone2" topology.scs.community/host-id: "vm1" -master2: +control-2: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone3" topology.scs.community/host-id: "vm2" -worker0: +worker-0: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm3" -worker1: +worker-1: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone2" topology.scs.community/host-id: "vm4" -worker2: +worker-2: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone3" topology.scs.community/host-id: "vm5" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml index 08dc26e83..715b25e44 100644 --- a/Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml +++ b/Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml @@ -1,30 +1,30 @@ # Success Scenario 2: # Nodes share the host-id and region, but are in different zones. -master0: +control-0: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm0" -master1: +control-1: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone2" topology.scs.community/host-id: "vm0" -master2: +control-2: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone3" topology.scs.community/host-id: "vm0" -worker0: +worker-0: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm1" -worker1: +worker-1: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone2" topology.scs.community/host-id: "vm1" -worker2: +worker-2: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone3" topology.scs.community/host-id: "vm1" From a7db76e509471c050cb329d5778da2c2b58e5335 Mon Sep 17 00:00:00 2001 From: Martin Morgenstern Date: Wed, 24 Apr 2024 18:49:58 +0200 Subject: [PATCH 06/10] Streamline testdata Signed-off-by: Martin Morgenstern --- .../k8s-node-distribution/testdata/test-missing-labels.yaml | 4 ++-- .../testdata/test-no-distribution-1.yaml | 2 +- .../k8s-node-distribution/testdata/test-not-enough-nodes.yaml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml index d0613ffc8..ec22e19a0 100644 --- a/Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml +++ b/Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml @@ -1,9 +1,9 @@ -control0: +control-0: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" topology.scs.community/host-id: "vm0" -control1: +control-1: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml index 954618504..d3fbc9a84 100644 --- a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml +++ b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml @@ -6,4 +6,4 @@ control-0: worker-0: topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" \ No newline at end of file + topology.scs.community/host-id: "vm0" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-not-enough-nodes.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-not-enough-nodes.yaml index f0a3f9101..974ca3cc3 100644 --- a/Tests/kaas/k8s-node-distribution/testdata/test-not-enough-nodes.yaml +++ b/Tests/kaas/k8s-node-distribution/testdata/test-not-enough-nodes.yaml @@ -1,5 +1,5 @@ -node0: +node-0: node-role.kubernetes.io/control-plane: "" topology.kubernetes.io/region: "region" topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" \ No newline at end of file + topology.scs.community/host-id: "vm0" From 4f363df7f97540f18e131450ee165a9a7473a577 Mon Sep 17 00:00:00 2001 From: Hannes Baum Date: Thu, 25 Apr 2024 13:20:45 +0200 Subject: [PATCH 07/10] Small fixes to the compliant to standard Some fixes and updates in order to be compliant with the testdata. Thanks to @martinmo. Signed-off-by: Hannes Baum --- .../k8s-node-distribution/check_nodes_test.py | 6 ------ .../k8s-node-distribution-check.py | 20 ++++++++++--------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Tests/kaas/k8s-node-distribution/check_nodes_test.py b/Tests/kaas/k8s-node-distribution/check_nodes_test.py index 8d29ff3a0..30b048410 100644 --- a/Tests/kaas/k8s-node-distribution/check_nodes_test.py +++ b/Tests/kaas/k8s-node-distribution/check_nodes_test.py @@ -55,12 +55,6 @@ def test_no_distribution(yaml_file, caplog): def test_missing_label(caplog): data = load_testdata("test-missing-labels.yaml") assert check_nodes(data.values()) == 2 - no_distribution_records = [ - record for record in caplog.records - if "distribution of nodes described in the standard couldn't be detected" in record.message - ] - assert len(no_distribution_records) == 1 - assert no_distribution_records[0].levelname == "ERROR" hostid_missing_records = [ record for record in caplog.records if "label for host-ids" in record.message diff --git a/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py b/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py index 4a41635d9..01e01d4ea 100755 --- a/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py +++ b/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py @@ -64,6 +64,10 @@ class DistributionException(BaseException): """Exception raised if the distribution seems to be not enough""" +class LabelException(BaseException): + """Exception raised if a label isn't set""" + + class Config: kubeconfig = None @@ -137,7 +141,7 @@ async def get_k8s_cluster_labelled_nodes(kubeconfig, interesting_labels): return nodes -def compare_labels(node_list, node_type="master"): +def compare_labels(node_list, node_type="control"): label_data = {key: list() for key in labels} @@ -146,11 +150,9 @@ def compare_labels(node_list, node_type="master"): try: label_data[key].append(node[key]) except KeyError: - logger.warning(f"The label for {key.split('/')[1]}s don't seem to be set for all nodes.") + raise LabelException(f"The label for {key.split('/')[1]}s doesn't seem to be set for all nodes.") for label in labels: - if len(label_data[label]) < len(node_list): - logger.warning(f"The label for {label.split('/')[1]}s doesn't seem to be set for all nodes.") if len(set(label_data[label])) <= 1: logger.warning(f"There seems to be no distribution across multiple {label.split('/')[1]}s " "or labels aren't set correctly across nodes.") @@ -161,7 +163,7 @@ def compare_labels(node_list, node_type="master"): ) return - if node_type == "master": + if node_type == "control": raise DistributionException("The distribution of nodes described in the standard couldn't be detected.") elif node_type == "worker": logger.warning("No node distribution could be detected for the worker nodes. " @@ -174,16 +176,16 @@ def check_nodes(nodes): logger.error("The tested cluster only contains a single node, which can't comply with the standard.") return 2 - labelled_master_nodes = [node for node in nodes if "node-role.kubernetes.io/control-plane" in node] + labelled_control_nodes = [node for node in nodes if "node-role.kubernetes.io/control-plane" in node] try: - if len(labelled_master_nodes) >= 1: + if len(labelled_control_nodes) >= 1: worker_nodes = [node for node in nodes if "node-role.kubernetes.io/control-plane" not in node] # Compare the labels of both types, since we have enough of them with labels - compare_labels(labelled_master_nodes, "master") + compare_labels(labelled_control_nodes, "control") compare_labels(worker_nodes, "worker") else: compare_labels(nodes) - except DistributionException as e: + except (DistributionException, LabelException) as e: logger.error(str(e)) return 2 From 50824e919e9a5a8b2390ab0a5d82c529d5e7f5c9 Mon Sep 17 00:00:00 2001 From: Martin Morgenstern Date: Fri, 26 Apr 2024 14:19:12 +0200 Subject: [PATCH 08/10] =?UTF-8?q?Use=20yaml.safe=5Fload(=E2=80=A6)=20inste?= =?UTF-8?q?ad=20of=20yaml.load(=E2=80=A6,=20yaml.SafeLoader)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Morgenstern --- Tests/kaas/k8s-node-distribution/check_nodes_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/kaas/k8s-node-distribution/check_nodes_test.py b/Tests/kaas/k8s-node-distribution/check_nodes_test.py index 30b048410..b6e51744c 100644 --- a/Tests/kaas/k8s-node-distribution/check_nodes_test.py +++ b/Tests/kaas/k8s-node-distribution/check_nodes_test.py @@ -20,7 +20,7 @@ def load_testdata(filename): with open(Path(HERE, "testdata", filename)) as stream: - return yaml.load(stream, yaml.SafeLoader) + return yaml.safe_load(stream) @pytest.mark.parametrize("yaml_file", ["test-success-1.yaml", "test-success-2.yaml"]) From 0854a95cf4a41b545ef853a7368d86b5ec130087 Mon Sep 17 00:00:00 2001 From: Hannes Baum Date: Fri, 3 May 2024 16:39:38 +0200 Subject: [PATCH 09/10] PEP-8 changes (#475) Small pep-8 changes. Signed-off-by: Hannes Baum --- .../k8s-node-distribution-check.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py b/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py index 01e01d4ea..fc33c5155 100755 --- a/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py +++ b/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py @@ -43,7 +43,7 @@ # 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 don't need to check anymore, since a distribution was already detected. -labels = ( +LABELS = ( "topology.kubernetes.io/region", "topology.kubernetes.io/zone", "topology.scs.community/host-id", @@ -143,16 +143,16 @@ async def get_k8s_cluster_labelled_nodes(kubeconfig, interesting_labels): def compare_labels(node_list, node_type="control"): - label_data = {key: list() for key in labels} + label_data = {key: list() for key in LABELS} for node in node_list: - for key in labels: + for key in LABELS: try: label_data[key].append(node[key]) except KeyError: raise LabelException(f"The label for {key.split('/')[1]}s doesn't seem to be set for all nodes.") - for label in labels: + for label in LABELS: if len(set(label_data[label])) <= 1: logger.warning(f"There seems to be no distribution across multiple {label.split('/')[1]}s " "or labels aren't set correctly across nodes.") @@ -203,7 +203,7 @@ async def main(argv): nodes = await get_k8s_cluster_labelled_nodes( config.kubeconfig, - labels + ("node-role.kubernetes.io/control-plane", ) + LABELS + ("node-role.kubernetes.io/control-plane", ) ) return check_nodes(nodes) From 3eb16be323ad7518622d28ea99925aa737cd1e0b Mon Sep 17 00:00:00 2001 From: Hannes Baum Date: Mon, 6 May 2024 08:29:45 +0200 Subject: [PATCH 10/10] Update test according to change requests (#489) @mbuechse had some change requests, that are tackled with this commit. Signed-off-by: Hannes Baum --- .../k8s-node-distribution/check_nodes_test.py | 30 ++-- ...heck.py => k8s_node_distribution_check.py} | 1 + .../testdata/scenarios.yaml | 128 ++++++++++++++++++ .../testdata/test-missing-labels.yaml | 10 -- .../testdata/test-no-distribution-1.yaml | 9 -- .../testdata/test-no-distribution-2.yaml | 27 ---- .../testdata/test-not-enough-nodes.yaml | 5 - .../testdata/test-success-1.yaml | 30 ---- .../testdata/test-success-2.yaml | 30 ---- Tests/scs-compatible-kaas.yaml | 2 +- 10 files changed, 145 insertions(+), 127 deletions(-) rename Tests/kaas/k8s-node-distribution/{k8s-node-distribution-check.py => k8s_node_distribution_check.py} (99%) create mode 100644 Tests/kaas/k8s-node-distribution/testdata/scenarios.yaml delete mode 100644 Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml delete mode 100644 Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml delete mode 100644 Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml delete mode 100644 Tests/kaas/k8s-node-distribution/testdata/test-not-enough-nodes.yaml delete mode 100644 Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml delete mode 100644 Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml diff --git a/Tests/kaas/k8s-node-distribution/check_nodes_test.py b/Tests/kaas/k8s-node-distribution/check_nodes_test.py index b6e51744c..d32edccfb 100644 --- a/Tests/kaas/k8s-node-distribution/check_nodes_test.py +++ b/Tests/kaas/k8s-node-distribution/check_nodes_test.py @@ -2,30 +2,30 @@ Unit tests for node distribution check functions. (c) Martin Morgenstern , 4/2024 +(c) Hannes Baum , 5/2024 SPDX-License-Identifier: CC-BY-SA-4.0 """ from pathlib import Path -import importlib import yaml import pytest - -check_nodes = importlib.import_module("k8s-node-distribution-check").check_nodes +from k8s_node_distribution_check import check_nodes HERE = Path(__file__).parent -def load_testdata(filename): - with open(Path(HERE, "testdata", filename)) as stream: +@pytest.fixture +def load_testdata(): + with open(Path(HERE, "testdata", "scenarios.yaml")) as stream: return yaml.safe_load(stream) -@pytest.mark.parametrize("yaml_file", ["test-success-1.yaml", "test-success-2.yaml"]) -def test_success_single_region_warning(yaml_file, caplog): - data = load_testdata(yaml_file) +@pytest.mark.parametrize("yaml_key", ["success-1", "success-2"]) +def test_success_single_region_warning(yaml_key, caplog, load_testdata): + data = load_testdata[yaml_key] assert check_nodes(data.values()) == 0 assert len(caplog.records) == 2 for record in caplog.records: @@ -33,17 +33,17 @@ def test_success_single_region_warning(yaml_file, caplog): assert record.levelname == "WARNING" -def test_not_enough_nodes(caplog): - data = load_testdata("test-not-enough-nodes.yaml") +def test_not_enough_nodes(caplog, load_testdata): + data = load_testdata["not-enough-nodes"] assert check_nodes(data.values()) == 2 assert len(caplog.records) == 1 assert "cluster only contains a single node" in caplog.records[0].message assert caplog.records[0].levelname == "ERROR" -@pytest.mark.parametrize("yaml_file", ["test-no-distribution-1.yaml", "test-no-distribution-2.yaml"]) -def test_no_distribution(yaml_file, caplog): - data = load_testdata(yaml_file) +@pytest.mark.parametrize("yaml_key", ["no-distribution-1", "no-distribution-2"]) +def test_no_distribution(yaml_key, caplog, load_testdata): + data = load_testdata[yaml_key] with caplog.at_level("ERROR"): assert check_nodes(data.values()) == 2 assert len(caplog.records) == 1 @@ -52,8 +52,8 @@ def test_no_distribution(yaml_file, caplog): assert record.levelname == "ERROR" -def test_missing_label(caplog): - data = load_testdata("test-missing-labels.yaml") +def test_missing_label(caplog, load_testdata): + data = load_testdata["missing-labels"] assert check_nodes(data.values()) == 2 hostid_missing_records = [ record for record in caplog.records diff --git a/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py b/Tests/kaas/k8s-node-distribution/k8s_node_distribution_check.py similarity index 99% rename from Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py rename to Tests/kaas/k8s-node-distribution/k8s_node_distribution_check.py index fc33c5155..8bc6fb7dd 100755 --- a/Tests/kaas/k8s-node-distribution/k8s-node-distribution-check.py +++ b/Tests/kaas/k8s-node-distribution/k8s_node_distribution_check.py @@ -28,6 +28,7 @@ node-role.kubernetes.io/control-plane (c) Hannes Baum , 6/2023 +(c) Martin Morgenstern , 4/2024 License: CC-BY-SA 4.0 """ diff --git a/Tests/kaas/k8s-node-distribution/testdata/scenarios.yaml b/Tests/kaas/k8s-node-distribution/testdata/scenarios.yaml new file mode 100644 index 000000000..5cec0118d --- /dev/null +++ b/Tests/kaas/k8s-node-distribution/testdata/scenarios.yaml @@ -0,0 +1,128 @@ +# Success Scenario 1: +# All nodes have distinct host-ids and zones, but share the region. +success-1: + control-0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" + control-1: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone2" + topology.scs.community/host-id: "vm1" + control-2: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone3" + topology.scs.community/host-id: "vm2" + worker-0: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm3" + worker-1: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone2" + topology.scs.community/host-id: "vm4" + worker-2: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone3" + topology.scs.community/host-id: "vm5" + +# Success Scenario 2: +# Nodes share the host-id and region, but are in different zones. +success-2: + control-0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" + control-1: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone2" + topology.scs.community/host-id: "vm0" + control-2: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone3" + topology.scs.community/host-id: "vm0" + worker-0: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm1" + worker-1: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone2" + topology.scs.community/host-id: "vm1" + worker-2: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone3" + topology.scs.community/host-id: "vm1" + +# Failure Scenario: +# No distribution detectable because of too few nodes +no-distribution-1: + control-0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" + worker-0: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" + +# Failure Scenario: +# No distribution detectable because all nodes are in the same zone +no-distribution-2: + control-0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" + control-1: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" + control-2: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" + worker-0: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm1" + worker-1: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm1" + worker-2: + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm1" + +# Failure Scenario: +# A host-id label is missing on a control node +missing-labels: + control-0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" + control-1: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + # host-id missing + +# Failure Scenario: +# Not enough nodes available, so no distribution is detectable +not-enough-nodes: + node-0: + node-role.kubernetes.io/control-plane: "" + topology.kubernetes.io/region: "region" + topology.kubernetes.io/zone: "zone1" + topology.scs.community/host-id: "vm0" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml deleted file mode 100644 index ec22e19a0..000000000 --- a/Tests/kaas/k8s-node-distribution/testdata/test-missing-labels.yaml +++ /dev/null @@ -1,10 +0,0 @@ -control-0: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" -control-1: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - # host-id missing diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml deleted file mode 100644 index d3fbc9a84..000000000 --- a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-1.yaml +++ /dev/null @@ -1,9 +0,0 @@ -control-0: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" -worker-0: - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml deleted file mode 100644 index b1bb6b130..000000000 --- a/Tests/kaas/k8s-node-distribution/testdata/test-no-distribution-2.yaml +++ /dev/null @@ -1,27 +0,0 @@ -control-0: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" -control-1: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" -control-2: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" -worker-0: - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm1" -worker-1: - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm1" -worker-2: - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm1" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-not-enough-nodes.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-not-enough-nodes.yaml deleted file mode 100644 index 974ca3cc3..000000000 --- a/Tests/kaas/k8s-node-distribution/testdata/test-not-enough-nodes.yaml +++ /dev/null @@ -1,5 +0,0 @@ -node-0: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml deleted file mode 100644 index 1098d51fb..000000000 --- a/Tests/kaas/k8s-node-distribution/testdata/test-success-1.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# Success Scenario 1: -# All nodes have distinct host-ids and zones, but share the region. - -control-0: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" -control-1: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone2" - topology.scs.community/host-id: "vm1" -control-2: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone3" - topology.scs.community/host-id: "vm2" -worker-0: - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm3" -worker-1: - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone2" - topology.scs.community/host-id: "vm4" -worker-2: - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone3" - topology.scs.community/host-id: "vm5" diff --git a/Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml b/Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml deleted file mode 100644 index 715b25e44..000000000 --- a/Tests/kaas/k8s-node-distribution/testdata/test-success-2.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# Success Scenario 2: -# Nodes share the host-id and region, but are in different zones. - -control-0: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm0" -control-1: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone2" - topology.scs.community/host-id: "vm0" -control-2: - node-role.kubernetes.io/control-plane: "" - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone3" - topology.scs.community/host-id: "vm0" -worker-0: - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone1" - topology.scs.community/host-id: "vm1" -worker-1: - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone2" - topology.scs.community/host-id: "vm1" -worker-2: - topology.kubernetes.io/region: "region" - topology.kubernetes.io/zone: "zone3" - topology.scs.community/host-id: "vm1" diff --git a/Tests/scs-compatible-kaas.yaml b/Tests/scs-compatible-kaas.yaml index 81098b7c3..5ad86dcbf 100644 --- a/Tests/scs-compatible-kaas.yaml +++ b/Tests/scs-compatible-kaas.yaml @@ -15,7 +15,7 @@ versions: - name: Kubernetes node distribution and availability url: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Standards/scs-0214-v1-k8s-node-distribution.md checks: - - executable: ./kaas/k8s-node-distribution/k8s-node-distribution-check.py + - executable: ./kaas/k8s-node-distribution/k8s_node_distribution_check.py args: -k {kubeconfig} id: node-distribution-check - name: CNCF Kubernetes conformance