-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print supported configurations of 3rd-parties with versions compatibi…
…lity
- Loading branch information
Showing
5 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |