def test_happy_path_sleeper(): settings = new_settings() hello_app = app_translator.load("tests/test_marathon/test_app_transtalor/resources/simple-command-app.json")[0] translated = app_translator.translate_app(hello_app, settings) assert (translated.deployment['kind'] == "Deployment") assert (translated.deployment['metadata']['name'] == "sleep") assert (translated.deployment['metadata']['labels'] == {'app': 'sleep'}) assert (translated.deployment['spec']['replicas'] == 10) container = translated.deployment['spec']['template']['spec']['containers'][0] assert (container['command'] == ['/bin/sh', '-c', 'sleep 3600']) assert (container['image'] == 'busybox') assert (container['resources'] == { 'requests': { 'cpu': 0.01, 'memory': '64Mi' }, 'limits': { 'cpu': 0.01, 'memory': '64Mi' } }) assert (container['name'] == 'main')
def translate(path: str, settings: Settings, selected_app_id: str) -> None: apps = load(path) for app in apps: app_id = app.get('id', "(NO ID)") if selected_app_id and selected_app_id != app_id: continue app_label = marathon_app_id_to_k8s_app_id(app_id) dcos_package_name = app.get('labels', {}).get("DCOS_PACKAGE_NAME") if dcos_package_name is None: translated = translate_app(app, settings) print("# Converted from an app {}".format(app_id)) print("\n\n".join([''] + translated.warnings).replace( '\n', '\n# ')) print(yaml.safe_dump(translated.deployment)) print("---") k8s_app_id: str = translated.deployment['metadata']['labels'][ 'app'] result, warnings = translate_service(k8s_app_id, app) if result: print("# Converted from an app {}".format(app_id)) print("\n\n".join([''] + list(warnings)).replace('\n', '\n# ')) print(yaml.safe_dump(result)) else: print( '# Skipped an app {}: it is installed from a DCOS package "{}"' .format(app_id, dcos_package_name)) print('---')
def test_translates_args(): settings = new_settings() hello_app = app_translator.load("tests/test_marathon/test_app_transtalor/resources/container-args-app.json")[0] translated = app_translator.translate_app(hello_app, settings) assert (translated.deployment['kind'] == "Deployment") assert (translated.deployment['metadata']['name'] == "args") container = translated.deployment['spec']['template']['spec']['containers'][0] assert (not "command" in container) assert (container['args'] == ["args", "passed", "to", "entrypoint"])
def test_happy_path_stateful(): settings = new_settings() hello_app = app_translator.load("tests/test_marathon/test_app_transtalor/resources/stateful-app.json")[0] translated = app_translator.translate_app(hello_app, settings) assert (translated.deployment['kind'] == 'StatefulSet') [mount] = translated.deployment['spec']['template']['spec']['containers'][0]['volumeMounts'] [vc_template] = translated.deployment['spec']['volumeClaimTemplates'] assert mount['name'] == "data" assert vc_template['spec']['accessModes'] == ['ReadWriteOnce'] assert vc_template['spec']['resources']['requests']['storage'] == '512Mi' assert not 'strategy' in translated.deployment['spec'].keys()
def test_vip_translation_real_app_with_named_vip(): this: List[int] = [] postgres_app = app_translator.load( "tests/test_marathon/test_app_transtalor/resources/nginx-vip-app.json" )[0] result, warnings = __translate_service(postgres_app) assert (result['metadata']['labels'][DCOS_IO_L4LB_NAME] == 'nginx.marathon.l4lb.thisdcos.directory') assert (result["metadata"]["name"] == "nginx") assert (result["spec"]["selector"] == {'app': 'nginx'}) assert (result["spec"]["ports"] == [{ 'name': 'http', 'port': 80, 'protocol': 'TCP' }, { 'name': 'https', 'port': 443, 'protocol': 'TCP' }]) assert ("clusterIP" not in result["spec"])