diff --git a/README.md b/README.md index 4049fbf..6c811c7 100644 --- a/README.md +++ b/README.md @@ -236,3 +236,19 @@ Using the command lines above without the `-s` flag for server will work on GKE. client_factory = TychoClientFactory () client = client_factory.get_client () ``` + +### "proxy_rewrite" Feature Overview: + +The "proxy_rewrite" feature ensures system-wide consistency in handling service +locations, especially when interacting with higher-level reverse proxies. By def +ining annotations in `service.yaml`, Ambassador's behavior is tailored, allowing +the underlying service to perceive an altered path while maintaining a consistent +location view at the system level. + +- **context.py**: Processes external specifications, capturing "proxy_rewrite" +directives, and transforms them into an internal representation. +- **model.py**: Forms the structural foundation of the system, accurately reflecting +the "proxy_rewrite" configurations and their implications. +- **service.yaml**: Serves as a template for Kubernetes service definitions. When +interpreted, it influences Ambassador's behavior using "proxy_rewrite" annotations, +ensuring path and location consistency across the system. diff --git a/tests/test_model.py b/tests/test_model.py index c2ab82a..1dac183 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -17,7 +17,7 @@ def test_system_model(request): "principal": {"username": "renci"}, "service_account": "default", "conn_string": "", - "proxy_rewrite_rule": False, + "proxy_rewrite": { 'enabled': False }, "containers": [ { "name": "nginx-container", diff --git a/tycho/__init__.py b/tycho/__init__.py index d5704ef..45c7fd1 100644 --- a/tycho/__init__.py +++ b/tycho/__init__.py @@ -1 +1 @@ -VERSION = "1.16.1" +VERSION = "1.17.1" diff --git a/tycho/context.py b/tycho/context.py index eb11a7e..1a8bd1f 100644 --- a/tycho/context.py +++ b/tycho/context.py @@ -328,7 +328,9 @@ def start (self, principal, app_id, resource_request, host): spec["services"][app_id]["conn_string"] = conn_string """ Add a proxy rewrite rule """ proxy_rewrite_rule = self.apps.get(app_id).get("proxy-rewrite-rule", False) - spec["services"][app_id]["proxy_rewrite_rule"] = proxy_rewrite_rule + proxy_rewrite = self.apps.get(app_id).get("proxy-rewrite", { "enabled":False, "target":None }) + spec["services"][app_id]["proxy_rewrite"] = proxy_rewrite + if proxy_rewrite_rule: spec["services"][app_id]["proxy_rewrite"]["enabled"] = True """ Add gitea integration rule """ gitea_integration = self.apps.get(app_id).get("gitea-integration", False) spec["services"][app_id]["gitea_integration"] = gitea_integration diff --git a/tycho/model.py b/tycho/model.py index b614576..8851aa2 100644 --- a/tycho/model.py +++ b/tycho/model.py @@ -164,7 +164,7 @@ def __repr__(self): class System: """ Distributed system of interacting containerized software. """ - def __init__(self, config, name, principal, service_account, conn_string, proxy_rewrite_rule, containers, identifier, + def __init__(self, config, name, principal, service_account, conn_string, proxy_rewrite, containers, identifier, gitea_integration, services={}, security_context={}, init_security_context={}): """ Construct a new abstract model of a system given a name and set of containers. @@ -242,7 +242,7 @@ def __init__(self, config, name, principal, service_account, conn_string, proxy_ self.init_memory = os.environ.get("TYCHO_APP_INIT_MEMORY", "250Mi") self.gpu_resource_name = os.environ.get("TYCHO_APP_GPU_RESOURCE_NAME", "nvidia.com/gpu") """Proxy rewrite rule for ambassador service annotations""" - self.proxy_rewrite_rule = proxy_rewrite_rule + self.proxy_rewrite = proxy_rewrite # """Flag for checking if an IRODS connection is enabled""" if os.environ.get("IROD_HOST") != None: logger.info("Irods host enabled") @@ -452,7 +452,7 @@ def parse (config, name, principal, system, service_account, env={}, services={} "principal": principal, "service_account": service_account, "conn_string": spec.get("conn_string", ""), - "proxy_rewrite_rule": spec.get("proxy_rewrite_rule", False), + "proxy_rewrite": spec.get("proxy_rewrite", { 'target':None, 'enabled':False }), "containers": containers, "identifier": identifier, "gitea_integration": spec.get("gitea_integration", False), diff --git a/tycho/template/service.yaml b/tycho/template/service.yaml index 45f52e0..a41aaac 100644 --- a/tycho/template/service.yaml +++ b/tycho/template/service.yaml @@ -32,8 +32,14 @@ metadata: headers: REMOTE_USER: {{system.username}} {% endif %} - {% if system.proxy_rewrite_rule == True %} + {% if system.proxy_rewrite.enabled == True %} + {% if system.proxy_rewrite.target == None %} rewrite: /private/{{system.system_name}}/{{system.username}}/{{system.identifier}}/{{system.conn_string}} + {% else %} + rewrite: {{ system.proxy_rewrite.target }} + add_response_headers: + X-Original-Path: /private/{{system.system_name}}/{{system.username}}/{{system.identifier}}/{{system.conn_string}} + {% endif %} {% endif %} retry_policy: retry_on: gateway-error