def _discover_components(cfg, inventory_path):
    """
    Discover components in `inventory_path/`. Parse all classes found in
    inventory_path and look for class includes starting with `components.`.
    """
    reset_reclass_cache()
    kapitan_inventory = inventory_reclass(inventory_path, ignore_class_notfound=True)[
        "nodes"
    ]["cluster"]
    components = set()
    for kls in kapitan_inventory["classes"]:
        if kls.startswith("components."):
            component = kls.split(".")[1]
            if cfg.debug:
                click.echo(f"   > Found component {component}")
            components.add(component)
    return sorted(components)
Beispiel #2
0
def compile(config, cluster_id):
    if config.local:
        catalog_repo = _local_setup(config, cluster_id, TARGET)
    else:
        clean_working_tree(config)
        catalog_repo = _regular_setup(config, cluster_id, TARGET)

    # Compile kapitan inventory to extract component versions. Component
    # versions are assumed to be defined in the inventory key
    # 'parameters.component_versions'
    reset_reclass_cache()
    kapitan_inventory = inventory_reclass("inventory")["nodes"][TARGET]
    versions = kapitan_inventory["parameters"].get("component_versions", None)
    if versions and not config.local:
        set_component_overrides(config, versions)
        update_target(config, TARGET)
    # Rebuild reclass inventory to use new version of components
    reset_reclass_cache()
    kapitan_inventory = inventory_reclass("inventory")["nodes"][TARGET]
    jsonnet_libs = (kapitan_inventory["parameters"].get("commodore", {}).get(
        "jsonnet_libs", None))
    if jsonnet_libs and not config.local:
        fetch_jsonnet_libs(config, jsonnet_libs)

    if not config.local:
        write_jsonnetfile(config)
        fetch_jsonnet_libraries()

    clean_catalog(catalog_repo)

    # Generate Kapitan secret references from refs found in inventory
    # parameters
    update_refs(config, kapitan_inventory["parameters"])

    kapitan_compile(config, search_paths=["./vendor/"])

    postprocess_components(config, kapitan_inventory, TARGET,
                           config.get_components())

    update_catalog(config, TARGET, catalog_repo)

    click.secho("Catalog compiled! 🎉", bold=True)
Beispiel #3
0
def kapitan_compile(
    config: Config,
    target="cluster",
    output_dir="./",
    search_paths=None,
    fake_refs=False,
    fetch_dependencies=True,
    reveal=False,
):
    if not search_paths:
        search_paths = []
    search_paths = search_paths + [
        "./",
        __install_dir__,
    ]
    reset_reclass_cache()
    refController = RefController("./catalog/refs")
    if fake_refs:
        refController.register_backend(FakeVaultBackend())
    click.secho("Compiling catalog...", bold=True)
    cached.args["compile"] = ArgumentCache(inventory_path="./inventory")
    targets.compile_targets(
        inventory_path="./inventory",
        search_paths=search_paths,
        output_path=output_dir,
        targets=[target],
        parallel=4,
        labels=None,
        ref_controller=refController,
        verbose=config.trace,
        prune=False,
        indent=2,
        reveal=reveal,
        cache=False,
        cache_paths=None,
        fetch_dependencies=fetch_dependencies,
        validate=False,
        schemas_path="./schemas",
        jinja2_filters=defaults.DEFAULT_JINJA2_FILTERS_PATH,
    )
Beispiel #4
0
def compile(config, cluster_id):
    if config.local:
        cluster, target_name, catalog_repo = _local_setup(config, cluster_id)
    else:
        clean_working_tree(config)
        cluster, target_name, catalog_repo = _regular_setup(config, cluster_id)

    # Compile kapitan inventory to extract component versions. Component
    # versions are assumed to be defined in the inventory key
    # 'parameters.component_versions'
    kapitan_inventory = inventory_reclass('inventory')['nodes'][target_name]
    versions = kapitan_inventory['parameters'].get('component_versions', None)
    if versions and not config.local:
        set_component_overrides(config, versions)
        update_target(config, cluster)
    # Rebuild reclass inventory to use new version of components
    reset_reclass_cache()
    kapitan_inventory = inventory_reclass('inventory')['nodes'][target_name]
    jsonnet_libs = kapitan_inventory['parameters'].get('commodore', {}).get(
        'jsonnet_libs', None)
    if jsonnet_libs and not config.local:
        fetch_jsonnet_libs(config, jsonnet_libs)

    clean_catalog(catalog_repo)

    # Generate Kapitan secret references from refs found in inventory
    # parameters
    update_refs(config, kapitan_inventory['parameters'])

    kapitan_compile(config)

    postprocess_components(config, kapitan_inventory, target_name,
                           config.get_components())

    update_catalog(config, target_name, catalog_repo)

    click.secho('Catalog compiled! 🎉', bold=True)