From e350d8481cab5c8b6179b85c77175278550e971b Mon Sep 17 00:00:00 2001 From: waTeim Date: Mon, 23 Oct 2023 21:12:25 -0400 Subject: [PATCH 1/5] Add support for setting the target in proxy_rewrite. --- tests/test_model.py | 2 +- tycho/__init__.py | 2 +- tycho/context.py | 4 +++- tycho/model.py | 6 +++--- tycho/template/service.yaml | 8 +++++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/test_model.py b/tests/test_model.py index c2ab82a5..1dac1836 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 d5704ef3..b32887e0 100644 --- a/tycho/__init__.py +++ b/tycho/__init__.py @@ -1 +1 @@ -VERSION = "1.16.1" +VERSION = "1.17.0" diff --git a/tycho/context.py b/tycho/context.py index eb11a7e0..1a8bd1fa 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 b614576f..8851aa21 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 45f52e0d..a99f2976 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 }} + {% endif %} + add_response_headers: + X-Original-Path: /private/{{system.system_name}}/{{system.username}}/{{system.identifier}}/{{system.conn_string}} {% endif %} retry_policy: retry_on: gateway-error From da5dd94bae387b4684eb69350727d55660196716 Mon Sep 17 00:00:00 2001 From: waTeim Date: Mon, 23 Oct 2023 21:38:55 -0400 Subject: [PATCH 2/5] Only set original-path if target is set --- tycho/template/service.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tycho/template/service.yaml b/tycho/template/service.yaml index a99f2976..a41aaacc 100644 --- a/tycho/template/service.yaml +++ b/tycho/template/service.yaml @@ -37,10 +37,10 @@ metadata: rewrite: /private/{{system.system_name}}/{{system.username}}/{{system.identifier}}/{{system.conn_string}} {% else %} rewrite: {{ system.proxy_rewrite.target }} - {% endif %} 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 num_retries: 10 From 1c58a384cbbc8a6cf561eb5c6e5e9ea49d39f541 Mon Sep 17 00:00:00 2001 From: waTeim Date: Mon, 23 Oct 2023 21:45:40 -0400 Subject: [PATCH 3/5] version++ --- tycho/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tycho/__init__.py b/tycho/__init__.py index b32887e0..45c7fd17 100644 --- a/tycho/__init__.py +++ b/tycho/__init__.py @@ -1 +1 @@ -VERSION = "1.17.0" +VERSION = "1.17.1" From 7d9992c4088fcef5ed584f8fd29ff1d8643adc11 Mon Sep 17 00:00:00 2001 From: waTeim Date: Tue, 24 Oct 2023 11:36:29 -0400 Subject: [PATCH 4/5] README++ --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 4049fbf6..84f2eb9d 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 consiste +nt location view at the system level. + +- **context.py**: Processes external specifications, capturing "proxy_rewrite" d +irectives, and transforms them into an internal representation. +- **model.py**: Forms the structural foundation of the system, accurately reflec +ting the "proxy_rewrite" configurations and their implications. +- **service.yaml**: Serves as a template for Kubernetes service definitions. Whe +n interpreted, it influences Ambassador's behavior using "proxy_rewrite" annotat +ions, ensuring path and location consistency across the system. From bcac45f154fa87675854784ac529a3bb23d032a0 Mon Sep 17 00:00:00 2001 From: waTeim Date: Tue, 24 Oct 2023 11:48:20 -0400 Subject: [PATCH 5/5] approximately 80 characters per line --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 84f2eb9d..6c811c77 100644 --- a/README.md +++ b/README.md @@ -242,13 +242,13 @@ client = client_factory.get_client () 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 consiste -nt location view at the system level. - -- **context.py**: Processes external specifications, capturing "proxy_rewrite" d -irectives, and transforms them into an internal representation. -- **model.py**: Forms the structural foundation of the system, accurately reflec -ting the "proxy_rewrite" configurations and their implications. -- **service.yaml**: Serves as a template for Kubernetes service definitions. Whe -n interpreted, it influences Ambassador's behavior using "proxy_rewrite" annotat -ions, ensuring path and location consistency across the system. +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.