Skip to content

Commit

Permalink
Print supported configurations of 3rd-parties with versions compatibi…
Browse files Browse the repository at this point in the history
…lity
  • Loading branch information
ilia1243 committed Mar 1, 2024
1 parent 9d8b43f commit 54e42ec
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
1 change: 1 addition & 0 deletions kubemarine.spec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ a = Analysis(['./kubemarine/__main__.py'],
'kubemarine.procedures.add_node',
'kubemarine.procedures.check_iaas',
'kubemarine.procedures.check_paas',
'kubemarine.procedures.config',
'kubemarine.procedures.do',
'kubemarine.procedures.install',
'kubemarine.procedures.migrate_kubemarine',
Expand Down
6 changes: 5 additions & 1 deletion kubemarine/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
'description': "Print current release version",
'group': 'other'
},
'config': {
'description': "Print supported configurations of 3rd-parties with versions compatibility",
'group': 'other'
},
'do': {
'description': "Execute shell command on cluster nodes",
'group': 'other'
Expand Down Expand Up @@ -198,7 +202,7 @@ def selftest() -> None:

if "main" not in dir(module):
raise Exception("No main method in %s" % procedure)
if procedure not in ["do", "migrate_kubemarine"]:
if procedure not in ["do", "migrate_kubemarine", "config"]:
if "tasks" not in dir(module):
raise Exception("Tasks tree is not presented in %s" % procedure)
if not isinstance(module.tasks, OrderedDict):
Expand Down
70 changes: 70 additions & 0 deletions kubemarine/procedures/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import argparse
import json
import sys
from typing import List

import yaml

from kubemarine import plugins
from kubemarine.core import static, utils

HELP_DESCRIPTION = """\
Print supported configurations of 3rd-parties with versions compatibility.
How to use:
"""


def make_config() -> dict:
kubernetes_versions: dict = {}
for version, compatibility_map in static.KUBERNETES_VERSIONS['compatibility_map'].items():
kubernetes_version = kubernetes_versions.setdefault(version, {})

minor_version = utils.minor_version(version)
supported = static.KUBERNETES_VERSIONS['kubernetes_versions'][minor_version]
kubernetes_version['supported'] = bool(supported)

plugins_ = plugins.oob_plugins
thirdparties_ = ['crictl']

for software, software_version in compatibility_map.items():
if software in plugins_:
kubernetes_version.setdefault('plugins', {}) \
.setdefault(software, {})['version'] = software_version

if software in thirdparties_:
kubernetes_version.setdefault('thirdparties', {}) \
.setdefault(software, {})['version'] = software_version

return {'kubernetes': kubernetes_versions}


def print_config(cfg: dict, arguments: dict) -> None:
format_ = arguments['output']
if format_ == 'yaml':
print(yaml.safe_dump(cfg, sort_keys=False), end='')
elif format_ == 'json':
print(json.dumps(cfg, indent=4))


def main(cli_arguments: List[str] = None) -> None:
if cli_arguments is None:
cli_arguments = sys.argv[1:]

parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
prog='config',
description=HELP_DESCRIPTION)

parser.add_argument('-o', '--output',
choices=['yaml', 'json'], default='yaml',
help='output format')

arguments = vars(parser.parse_args(cli_arguments))

cfg = make_config()
print_config(cfg, arguments)


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion kubemarine/procedures/do.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def run(self, res: DynamicResources) -> None:

def main(cli_arguments: List[str] = None) -> None:

if not cli_arguments:
if cli_arguments is None:
cli_arguments = sys.argv[1:]

if '--' in cli_arguments:
Expand Down
15 changes: 15 additions & 0 deletions test/unit/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

from kubemarine.core import static
from kubemarine.procedures import config


class ProcedureConfigTest(unittest.TestCase):
def test_make_config(self):
"""Does basic smoke test that kubemarine.procedures.config.make_config() exits successfully"""
cfg = config.make_config()
self.assertEqual(list(static.KUBERNETES_VERSIONS['compatibility_map']), list(cfg['kubernetes']))


if __name__ == '__main__':
unittest.main()

0 comments on commit 54e42ec

Please sign in to comment.