diff --git a/microservices/gatewayApi/v2/routes/gateway.py b/microservices/gatewayApi/v2/routes/gateway.py index e6dc56e..efa5dca 100644 --- a/microservices/gatewayApi/v2/routes/gateway.py +++ b/microservices/gatewayApi/v2/routes/gateway.py @@ -13,7 +13,7 @@ from werkzeug.exceptions import HTTPException, NotFound from flask import Blueprint, config, jsonify, request, Response, make_response, abort, g, current_app as app from io import TextIOWrapper -from clients.ocp_routes import get_host_list +from clients.ocp_routes import get_host_list, get_route_overrides from v2.auth.auth import admin_jwt, uma_enforce @@ -339,7 +339,10 @@ def write_config(namespace: str) -> object: route_payload = { "hosts": host_list, "select_tag": selectTag, - "ns_attributes": ns_attributes.getAttrs() + "ns_attributes": ns_attributes.getAttrs(), + "overrides": { + "aps.route.session.cookie.enabled": get_route_overrides(tempFolder, "aps.route.session.cookie.enabled") + } } rqst_url = app.config['data_planes'][dp]["kube-api"] log.debug("[%s] - Initiating request to kube API" % (dp)) diff --git a/microservices/gatewayJobScheduler/main.py b/microservices/gatewayJobScheduler/main.py index 572eb79..7b54b32 100644 --- a/microservices/gatewayJobScheduler/main.py +++ b/microservices/gatewayJobScheduler/main.py @@ -101,9 +101,13 @@ def transform_data_by_ns(data): # check if namespace has data plane attribute if ns_attr_dict[namespace].get('perm-data-plane', [''])[0] == os.getenv('DATA_PLANE'): + session_cookie_enabled = False + if 'aps.route.session.cookie.enabled' in route_obj['tags']: + session_cookie_enabled = True for host in route_obj['hosts']: name = 'wild-%s-%s' % (select_tag.replace(".", "-"), host) ns_dict[namespace].append({"name": name, "selectTag": select_tag, "host": host, + "session_cookie_enabled": session_cookie_enabled, "dataPlane": os.getenv('DATA_PLANE')}) return ns_dict except Exception as err: diff --git a/microservices/kubeApi/clients/ocp_routes.py b/microservices/kubeApi/clients/ocp_routes.py index aed15d3..4134f36 100644 --- a/microservices/kubeApi/clients/ocp_routes.py +++ b/microservices/kubeApi/clients/ocp_routes.py @@ -135,18 +135,23 @@ def prepare_route_last_version(ns, select_tag): return resource_versions -def prepare_apply_routes(ns, select_tag, hosts, rootPath, data_plane, template_version): +def prepare_apply_routes(ns, select_tag, hosts, rootPath, data_plane, ns_template_version, overrides): out_filename = "%s/routes-current.yaml" % rootPath ts = int(time.time()) fmt_time = datetime.now().strftime("%Y.%m-%b.%d") resource_versions = prepare_route_last_version(ns, select_tag) - route_template = ROUTES[template_version]["ROUTE"] with open(out_filename, 'w') as out_file: index = 1 for host in hosts: + templ_version = ns_template_version + if 'aps.route.session.cookie.enabled' in overrides and host in overrides['aps.route.session.cookie.enabled']: + templ_version = 'v1' + + route_template = ROUTES[templ_version]["ROUTE"] + # If host transformation is disabled, then select the appropriate # SSL cert based on the suffix mapping ssl_ref = "tls" @@ -168,7 +173,7 @@ def prepare_apply_routes(ns, select_tag, hosts, rootPath, data_plane, template_v (select_tag, index, select_tag.replace('.', '-'), host, resource_version)) out_file.write(route_template.substitute(name=name, ns=ns, select_tag=select_tag, resource_version=resource_version, host=host, path='/', ssl_ref=ssl_ref, ssl_key=ssl_key, ssl_crt=ssl_crt, service_name=data_plane, timestamp=ts, fmt_time=fmt_time, data_plane=data_plane, - template_version=template_version)) + template_version=templ_version)) out_file.write('\n---\n') index = index + 1 out_file.close() diff --git a/microservices/kubeApi/routers/routes.py b/microservices/kubeApi/routers/routes.py index a450714..19e80bf 100644 --- a/microservices/kubeApi/routers/routes.py +++ b/microservices/kubeApi/routers/routes.py @@ -24,6 +24,7 @@ class OCPRoute(BaseModel): hosts: list select_tag: str ns_attributes: dict + overrides: dict @router.put("/namespaces/{namespace}/routes", status_code=201, dependencies=[Depends(verify_credentials)]) @@ -59,13 +60,13 @@ def add_routes(namespace: str, route: OCPRoute): try: hosts = [a for a in route.hosts if not a.endswith(".cluster.local")] - template_version = get_template_version(route.ns_attributes) + ns_template_version = get_template_version(route.ns_attributes) # do routeable hosts source_folder = "%s/%s/%s" % ('/tmp', uuid.uuid4(), namespace) os.makedirs(source_folder, exist_ok=False) route_count = prepare_apply_routes(namespace, route.select_tag, hosts, - source_folder, get_data_plane(route.ns_attributes), template_version) + source_folder, get_data_plane(route.ns_attributes), ns_template_version, route.overrides) logger.debug("[%s] - Prepared %s routes" % (namespace, route_count)) if route_count > 0: apply_routes(source_folder) @@ -158,7 +159,7 @@ async def verify_and_create_routes(namespace: str, request: Request): # TODO: We shouldn't assume it is always v2 - caller needs to get # this info from ns_attributes - template_version = "v2" + ns_template_version = "v2" try: if len(insert_batch) > 0: @@ -167,8 +168,11 @@ async def verify_and_create_routes(namespace: str, request: Request): os.makedirs(source_folder, exist_ok=False) for route in insert_batch: + overrides = {} + if route['session_cookie_enabled']: + overrides['aps.route.session.cookie.enabled'] = [ route['host'] ] route_count = prepare_apply_routes(namespace, route['selectTag'], [ - route['host']], source_folder, route["dataPlane"], template_version) + route['host']], source_folder, route["dataPlane"], ns_template_version, overrides) logger.debug("[%s] - Prepared %d routes" % (namespace, route_count)) apply_routes(source_folder) logger.debug("[%s] - Applied %d routes" % (namespace, route_count))