Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Augment proxy rewrite #303

Merged
merged 5 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tycho/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "1.16.1"
VERSION = "1.17.1"
4 changes: 3 additions & 1 deletion tycho/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tycho/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 7 additions & 1 deletion tycho/template/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down