Exemplo n.º 1
0
def compile_target(target_obj, search_paths, compile_path, ref_controller,
                   **kwargs):
    """Compiles target_obj and writes to compile_path"""
    start = time.time()

    compile_objs = target_obj["compile"]
    ext_vars = target_obj["vars"]
    target_name = ext_vars["target"]

    jinja2_compiler = Jinja2(compile_path, search_paths, ref_controller)
    jsonnet_compiler = Jsonnet(compile_path, search_paths, ref_controller)
    kadet_compiler = Kadet(compile_path, search_paths, ref_controller)

    for comp_obj in compile_objs:
        input_type = comp_obj["input_type"]
        output_path = comp_obj["output_path"]
        if input_type == "jinja2":
            input_compiler = jinja2_compiler
        elif input_type == "jsonnet":
            input_compiler = jsonnet_compiler
        elif input_type == "kadet":
            input_compiler = kadet_compiler
        else:
            err_msg = "Invalid input_type: \"{}\". Supported input_types: jsonnet, jinja2, kadet"
            raise CompileError(err_msg.format(input_type))

        input_compiler.make_compile_dirs(target_name, output_path)
        input_compiler.compile_obj(comp_obj, ext_vars, **kwargs)

    logger.info("Compiled %s (%.2fs)", target_name, time.time() - start)
Exemplo n.º 2
0
def compile_target(target_obj,
                   search_paths,
                   compile_path,
                   ref_controller,
                   globals_cached=None,
                   **kwargs):
    """Compiles target_obj and writes to compile_path"""
    start = time.time()
    compile_objs = target_obj["compile"]
    ext_vars = target_obj["vars"]
    target_name = ext_vars["target"]

    if globals_cached:
        cached.from_dict(globals_cached)

    for comp_obj in compile_objs:
        input_type = comp_obj["input_type"]
        output_path = comp_obj["output_path"]

        if input_type == "jinja2":
            input_compiler = Jinja2(compile_path, search_paths, ref_controller)
            if "input_params" in comp_obj:
                input_compiler.set_input_params(comp_obj["input_params"])
        elif input_type == "jsonnet":
            input_compiler = Jsonnet(compile_path, search_paths,
                                     ref_controller)
        elif input_type == "kadet":
            input_compiler = Kadet(compile_path, search_paths, ref_controller)
            if "input_params" in comp_obj:
                input_compiler.set_input_params(comp_obj["input_params"])
        elif input_type == "helm":
            input_compiler = Helm(compile_path, search_paths, ref_controller,
                                  comp_obj)
        elif input_type == "copy":
            ignore_missing = comp_obj.get("ignore_missing", False)
            input_compiler = Copy(compile_path, search_paths, ref_controller,
                                  ignore_missing)
        elif input_type == "remove":
            input_compiler = Remove(compile_path, search_paths, ref_controller)
        elif input_type == "external":
            input_compiler = External(compile_path, search_paths,
                                      ref_controller)
            if "args" in comp_obj:
                input_compiler.set_args(comp_obj["args"])
            if "env_vars" in comp_obj:
                input_compiler.set_env_vars(comp_obj["env_vars"])
        else:
            err_msg = 'Invalid input_type: "{}". Supported input_types: jsonnet, jinja2, kadet, helm, copy, remove, external'
            raise CompileError(err_msg.format(input_type))

        # logger.info("about to compile %s ", target_obj["target_full_path"])
        input_compiler.make_compile_dirs(target_name, output_path)
        input_compiler.compile_obj(comp_obj, ext_vars, **kwargs)

    logger.info("Compiled %s (%.2fs)", target_obj["target_full_path"],
                time.time() - start)
Exemplo n.º 3
0
def compile_target(target_obj, search_paths, compile_path, ref_controller,
                   **kwargs):
    """Compiles target_obj and writes to compile_path"""
    start = time.time()
    compile_objs = target_obj["compile"]
    ext_vars = target_obj["vars"]
    target_name = ext_vars["target"]

    for comp_obj in compile_objs:
        input_type = comp_obj["input_type"]
        output_path = comp_obj["output_path"]

        if input_type == "jinja2":
            input_compiler = Jinja2(compile_path, search_paths, ref_controller)
        elif input_type == "jsonnet":
            input_compiler = Jsonnet(compile_path, search_paths,
                                     ref_controller)
        elif input_type == "kadet":
            input_compiler = Kadet(compile_path, search_paths, ref_controller)
            if "input_params" in comp_obj:
                input_compiler.set_input_params(comp_obj["input_params"])
        elif input_type == "helm":
            input_compiler = Helm(compile_path, search_paths, ref_controller)
            if "helm_values" in comp_obj:
                input_compiler.dump_helm_values(comp_obj["helm_values"])
            if "helm_params" in comp_obj:
                input_compiler.set_helm_params(comp_obj["helm_params"])
            if "helm_values_files" in comp_obj:
                input_compiler.set_helm_values_files(
                    comp_obj["helm_values_files"])
            if "kube_version" in comp_obj:
                input_compiler.set_kube_version(comp_obj["kube_version"])
        elif input_type == "copy":
            input_compiler = Copy(compile_path, search_paths, ref_controller)
        elif input_type == "remove":
            input_compiler = Remove(compile_path, search_paths, ref_controller)
        elif input_type == "external":
            input_compiler = External(compile_path, search_paths,
                                      ref_controller)
            if "args" in comp_obj:
                input_compiler.set_args(comp_obj["args"])
            if "env_vars" in comp_obj:
                input_compiler.set_env_vars(comp_obj["env_vars"])
        else:
            err_msg = 'Invalid input_type: "{}". Supported input_types: jsonnet, jinja2, kadet, helm, copy, remove, external'
            raise CompileError(err_msg.format(input_type))

        input_compiler.make_compile_dirs(target_name, output_path)
        input_compiler.compile_obj(comp_obj, ext_vars, **kwargs)

    logger.info("Compiled %s (%.2fs)", target_obj["target_full_path"],
                time.time() - start)
Exemplo n.º 4
0
def compile_target(target_obj, search_paths, compile_path, ref_controller, inventory_path, **kwargs):
    """Compiles target_obj and writes to compile_path"""
    start = time.time()
    compile_objs = target_obj["compile"]
    ext_vars = target_obj["vars"]
    target_name = ext_vars["target"]

    jinja2_compiler = Jinja2(compile_path, search_paths, ref_controller, inventory_path)
    jsonnet_compiler = Jsonnet(compile_path, search_paths, ref_controller)
    kadet_compiler = Kadet(compile_path, search_paths, ref_controller)
    helm_compiler = Helm(compile_path, search_paths, ref_controller)
    copy_compiler = Copy(compile_path, search_paths, ref_controller)
    remove_compiler = Remove(compile_path, search_paths, ref_controller)

    for comp_obj in compile_objs:
        input_type = comp_obj["input_type"]
        output_path = comp_obj["output_path"]
        if input_type == "jinja2":
            input_compiler = jinja2_compiler
        elif input_type == "jsonnet":
            input_compiler = jsonnet_compiler
        elif input_type == "kadet":
            input_compiler = kadet_compiler
            if "input_params" in comp_obj:
                kadet_compiler.set_input_params(comp_obj["input_params"])
        elif input_type == "helm":
            if "helm_values" in comp_obj:
                helm_compiler.dump_helm_values(comp_obj["helm_values"])
            if "helm_params" in comp_obj:
                helm_compiler.set_helm_params(comp_obj["helm_params"])
            if "helm_values_files" in comp_obj:
                helm_compiler.set_helm_values_files(comp_obj["helm_values_files"])
            input_compiler = helm_compiler
        elif input_type == "copy":
            input_compiler = copy_compiler
        elif input_type == "remove":
            input_compiler = remove_compiler
        else:
            err_msg = (
                'Invalid input_type: "{}". Supported input_types: jsonnet, jinja2, kadet, helm, copy, remove'
            )
            raise CompileError(err_msg.format(input_type))

        input_compiler.make_compile_dirs(target_name, output_path)
        input_compiler.compile_obj(comp_obj, ext_vars, **kwargs)

    logger.info("Compiled %s (%.2fs)", target_obj["target_full_path"], time.time() - start)