|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# This file is part of REANA. |
| 4 | +# Copyright (C) 2025 CERN. |
| 5 | +# |
| 6 | +# REANA is free software; you can redistribute it and/or modify it |
| 7 | +# under the terms of the MIT License; see LICENSE file for more details. |
| 8 | + |
| 9 | +"""REANA-Commons kubernetes queues validation.""" |
| 10 | + |
| 11 | +from reana_commons.errors import REANAValidationError |
| 12 | + |
| 13 | + |
| 14 | +def validate_kubernetes_queues( |
| 15 | + reana_yaml: dict, |
| 16 | + kueue_enabled: bool, |
| 17 | + supported_queues: list[str], |
| 18 | + default_queue: str | None, |
| 19 | +) -> None: |
| 20 | + """Validate Kubernetes queues in REANA specification file. |
| 21 | +
|
| 22 | + :param reana_yaml: dictionary which represents REANA specification file. |
| 23 | + :param kueue_enabled: whether Kueue is enabled. |
| 24 | + :param supported_queues: list of supported Kubernetes queues. |
| 25 | + :param default_queue: default Kubernetes queue. |
| 26 | +
|
| 27 | + :raises REANAValidationError: Given Kubernetes queue specified in REANA spec file does not validate against |
| 28 | + supported Kubernetes queues. |
| 29 | + """ |
| 30 | + workflow: dict = reana_yaml["workflow"] |
| 31 | + workflow_steps: list[dict] = workflow["specification"]["steps"] |
| 32 | + |
| 33 | + for step in workflow_steps: |
| 34 | + queue = step.get("kubernetes_queue") |
| 35 | + if queue: |
| 36 | + if not kueue_enabled: |
| 37 | + raise REANAValidationError( |
| 38 | + f'Kubernetes queue "{queue}" found in step "{step.get("name")}" but Kueue is not enabled.' |
| 39 | + ) |
| 40 | + if queue not in supported_queues: |
| 41 | + raise REANAValidationError( |
| 42 | + f'Kubernetes queue "{queue}" in step "{step.get("name")}" is not in list of supported queues: {", ".join(supported_queues)}' |
| 43 | + ) |
| 44 | + elif kueue_enabled and not default_queue: |
| 45 | + raise REANAValidationError( |
| 46 | + f'Kubernetes queue expected in step "{step.get("name")}" since Kueue is enabled and no default queue is set.' |
| 47 | + ) |
0 commit comments