Esempio n. 1
0
def kafka_delete(del_cluster_assets=False, del_pv=True):

    namespace = 'kafka'
    locale = get_locale(__file__)

    print('point')

    module_root = f'{locale.datastores_root}kubernetes-kafka'

    kafka_res = get_ordered_kafka_res()
    delete_multiple(res_tuples=kafka_res, module_root=module_root)

    zoo_res = get_ordered_zoo_res()
    delete_multiple(res_tuples=zoo_res, module_root=module_root)

    if del_pv:
        os.system(f'kubectl delete -f {module_root}/variants/docker-desktop/docker-storage.yaml --wait=false')
        logging.debug('tsav')
        delete_pvc_pv('data-kafka', namespace=namespace)
        logging.debug('mamoota')
        delete_pvc_pv('data-zoo', namespace=namespace)
        logging.debug('arnav')
        delete_pvc_pv('data-pzoo', namespace=namespace)

    if del_cluster_assets:

        res = get_ordered_cluster_res()

        for r in reversed(res):
            os.system(f'kubectl delete -f {module_root}/{r} --wait=false')
Esempio n. 2
0
def kafka_wield(action=None, auto_approve=False, service_only=False):

    locale = get_locale(__file__)

    action, mode, enable_debug, local_mount, service_mode = replace_none_vars_from_args(
        action=action,
        mode=None,
        enable_debug=None,
        local_mount=None,
        service_mode=None,
        project_override=None
    )

    service = WieldService(
        name='kafka',
        locale=locale,
        mode=mode,
        service_mode=service_mode,
    )

    service.plan.wield(
        action=action,
        auto_approve=auto_approve,
        service_only=service_only
    )
Esempio n. 3
0
def micros_image(parallel=True, action=None, delete_project_res=False):

    wield_mode, conf, action = get_project_deploy_mode(action)

    locale = get_locale(__file__)

    deployments = conf.deployments

    for deploy in deployments:

        print(f'{deploy}')

        module_root = get_module_locale(deploy).module_root

        image_script = f'{module_root}wield/{deploy}_image.py'

        print(f'{image_script}')
Esempio n. 4
0
def kafka_wield():

    locale = get_locale(__file__)

    logging.debug('break')

    module_root = f'{locale.datastores_root}kubernetes-kafka'

    res = get_ordered_cluster_res()

    for r in res:
        os.system(f'kubectl apply -f {module_root}/{r}')

    zoo_res = get_ordered_zoo_res()

    apply_multiple(res_tuples=zoo_res, module_root=module_root)

    kafka_res = get_ordered_kafka_res()

    apply_multiple(res_tuples=kafka_res, module_root=module_root)
Esempio n. 5
0
def micros_wield(parallel=True, action=None, delete_project_res=False):

    wield_mode, conf, action = get_project_deploy_mode(action)

    locale = get_locale(__file__)

    print('\nAttempting to create project level kubernetes resources e.g. namespaces\n')

    project = WieldProject(
        name='project',
        locale=locale,
        conf=conf,
        mode=wield_mode
    )

    if action == WieldAction.DELETE and not delete_project_res:
        print('skipping deletion of project level cluster resources such as namespaces')
    else:
        
        installations(project.conf.installations, action)
        
        project.plan.wield(
            action=action,
            auto_approve=True
        )

    deployments = conf.deployments

    init_tuples = []

    for deploy in deployments:

        conf_service_mode = conf[deploy].WieldServiceMode

        service_mode = WieldServiceMode(
            observe=conf_service_mode.observe,
            service_only=conf_service_mode.service_only,
            debug_mode=conf_service_mode.debug_mode,
            local_mount=conf_service_mode.local_mount
        )

        init_tuples.append((launch_service, deploy, service_mode))

    if parallel:

        source = rx.from_(init_tuples)

        with concurrent.futures.ProcessPoolExecutor(len(init_tuples)) as executor:

            composed = source.pipe(
                ops.flat_map(lambda s: executor.submit(
                    s[0],
                    name=s[1],
                    mode=wield_mode,
                    service_mode=s[2],
                    project_override=True,
                    action=action,
                    auto_approve=True
                ))
            )
            composed.subscribe(output)

    else:

        for t in init_tuples:

            t[0](
                name=t[1],
                mode=wield_mode,
                service_mode=t[2],
                project_override=True,
                action=action,
                auto_approve=True
            )
Esempio n. 6
0
def pep_image(force_last=True, push=False):

    locale = get_locale(__file__)

    action, mode, enable_debug, local_mount, service_mode = replace_none_vars_from_args(
        action=None,
        mode=None,
        enable_debug=None,
        local_mount=None,
        service_mode=None,
        project_override=None
    )

    service = WieldService(
        name='pep',
        locale=locale,
        mode=mode,
        service_mode=service_mode,
    )

    plan = service.plan.module_conf.packaging

    image_name = plan.image_name

    tag = plan.git.branch

    project_root = u.get_project_root()
    conf = u.get_conf_context_project(project_root=project_root)

    image_root = u.get_project_image_root()

    pack_image(
        conf=conf,
        name='perl',
        image_root=image_root,
        push=False,
        force=True,
        tag=tag
    )

    pack_image(
        conf=conf,
        name='perl_py',
        image_root=image_root,
        push=False,
        force=True,
        tag=tag
    )

    try:
        origin_path = plan.origin_path
        origin_regex = plan.origin_regex
    except AttributeError:
        super_project_root = u.get_super_project_root()
        origin_path = f'{super_project_root}/micros/perl/pep'
        origin_regex = 'pep.pl'

    module_root = u.get_module_root(__file__)
    image_root = f'{module_root}image'
    destination_path = f'{image_root}/{image_name}'

    artifacts_dir = f'{destination_path}/artifacts'

    artifact_method = plan.artifact_method

    if artifact_method == ArtifactMethod.GET_DIR.value or artifact_method == ArtifactMethod.INIT_REPO.value:
        rmtree(artifacts_dir, ignore_errors=True)

    if artifact_method == ArtifactMethod.GET_DIR.value:

        replace_dir_contents(
            origin_path,
            origin_regex,
            destination_path=destination_path,
            destination_dir_name='artifacts'
        )
    else:
        clone_or_update(source=origin_path, destination=artifacts_dir, branch=plan.git.branch)

        if artifact_method == ArtifactMethod.INIT_REPO.value:

            for art in plan.artifacts:

                os.makedirs(f"{artifacts_dir}/{art[0]}", exist_ok=True)

                try:
                    copyfile(src=f"{origin_path}/{art[0]}/{art[1]}", dst=f"{artifacts_dir}/{art[0]}/{art[1]}")

                except Exception as e:
                    logging.error(str(e))

            _cmd = f'{artifacts_dir}/pypep/prepare.bash'

            a = async_cmd(_cmd)

            for b in a:
                print(b)

    pack_image(
        conf,
        name=image_name,
        image_root=image_root,
        push=False,
        force=force_last,
        tag=tag
    )

    gcp_conf = conf.providers.gcp

    if push:
        push_image(gcp_conf, name=image_name, group='wielder', tag=tag)