def deploy_api_ingresses()

in nuvolaris/endpoint.py [0:0]


def deploy_api_ingresses(apihost, namespace,should_create_www=False):
    logging.info(f"**** configuring ingresses based endpoint for apihost {apihost}")
    res = ""   
    api = IngressData(apihost)
    api.with_ingress_name(api_ingress_name(namespace,"apihost"))
    api.with_secret_name(api_secret_name(namespace))
    api.with_context_path("/api/v1")
    api.with_context_regexp("(/|$)(.*)")
    api.with_rewrite_target("/api/v1/$2")
    api.with_service_name("controller")
    api.with_service_port("3233")
    api.with_middleware_ingress_name(api_middleware_ingress_name(namespace,"apihost"))

    my = IngressData(apihost)
    my.with_ingress_name(api_ingress_name(namespace,"apihost-my"))
    my.with_secret_name(api_secret_name(namespace))
    my.with_context_path("/api/my")
    my.with_context_regexp("(/|$)(.*)")
    my.with_rewrite_target(f"/api/v1/web/{namespace}/$2")
    my.with_service_name("controller")
    my.with_service_port("3233")
    my.with_middleware_ingress_name(api_middleware_ingress_name(namespace,"apihost-my"))

    if api.requires_traefik_middleware():
        logging.info("*** configuring traefik middleware for apihost ingress")
        path_to_template_yaml = api.render_traefik_middleware_template(namespace)
        res += kube.kubectl("apply", "-f",path_to_template_yaml)
        os.remove(path_to_template_yaml)

    if my.requires_traefik_middleware():
        logging.info("*** configuring traefik middleware for apihost-my ingress")
        path_to_template_yaml = my.render_traefik_middleware_template(namespace)
        res += kube.kubectl("apply", "-f",path_to_template_yaml)
        os.remove(path_to_template_yaml)        

    logging.info(f"*** configuring static ingress for apihost")
    path_to_template_yaml = api.render_template(namespace)
    res += kube.kubectl("apply", "-f",path_to_template_yaml)
    os.remove(path_to_template_yaml)

    logging.info(f"*** configuring static ingress for apihost-my")
    path_to_template_yaml = my.render_template(namespace)
    res += kube.kubectl("apply", "-f",path_to_template_yaml)
    os.remove(path_to_template_yaml)

    if should_create_www:
        www_my = IngressData(apihost_util.append_prefix_to_url(apihost,"www"))
        www_my.with_ingress_name(api_ingress_name(namespace,"apihost-www-my"))
        www_my.with_secret_name(api_secret_name(namespace)+"-www")
        www_my.with_context_path("/api/my")
        www_my.with_context_regexp("(/|$)(.*)")
        www_my.with_rewrite_target(f"/api/v1/web/{namespace}/$2")
        www_my.with_service_name("controller")
        www_my.with_service_port("3233")
        www_my.with_middleware_ingress_name(api_middleware_ingress_name(namespace,"apihost-www-my"))

        if www_my.requires_traefik_middleware():
            logging.info("*** configuring traefik middleware for apihost-www-my ingress")
            path_to_template_yaml = www_my.render_traefik_middleware_template(namespace)
            res += kube.kubectl("apply", "-f",path_to_template_yaml)
            os.remove(path_to_template_yaml)

        logging.info(f"*** configuring static ingress for apihost-www-my")
        path_to_template_yaml = www_my.render_template(namespace)
        res += kube.kubectl("apply", "-f",path_to_template_yaml)
        os.remove(path_to_template_yaml)                     

    return res