Browse Source
Adds preservePath for ingress (#747)
finitereality/replica-status-colors
Justin Kotalik
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with
24 additions and
6 deletions
-
src/Microsoft.Tye.Core/ApplicationFactory.cs
-
src/Microsoft.Tye.Core/ConfigModel/ConfigIngressRule.cs
-
src/Microsoft.Tye.Core/IngressRuleBuilder.cs
-
src/Microsoft.Tye.Core/KubernetesManifestGenerator.cs
-
src/Microsoft.Tye.Core/Serialization/ConfigIngressParser.cs
-
src/Microsoft.Tye.Hosting/DockerRunner.cs
-
src/Microsoft.Tye.Hosting/HttpProxyService.cs
-
src/Microsoft.Tye.Hosting/Model/IngressRule.cs
-
src/schema/tye-schema.json
-
src/tye/ApplicationBuilderExtensions.cs
|
|
|
@ -465,6 +465,7 @@ namespace Microsoft.Tye |
|
|
|
{ |
|
|
|
Host = configRule.Host, |
|
|
|
Path = configRule.Path, |
|
|
|
PreservePath = configRule.PreservePath, |
|
|
|
Service = configRule.Service!, // validated elsewhere
|
|
|
|
}; |
|
|
|
ingress.Rules.Add(rule); |
|
|
|
|
|
|
|
@ -10,6 +10,7 @@ namespace Microsoft.Tye.ConfigModel |
|
|
|
{ |
|
|
|
public string? Path { get; set; } |
|
|
|
public string? Host { get; set; } |
|
|
|
public bool PreservePath { get; set; } |
|
|
|
|
|
|
|
[Required] |
|
|
|
public string? Service { get; set; } |
|
|
|
|
|
|
|
@ -8,6 +8,8 @@ namespace Microsoft.Tye |
|
|
|
{ |
|
|
|
public string? Path { get; set; } |
|
|
|
public string? Host { get; set; } |
|
|
|
public bool PreservePath { get; set; } |
|
|
|
|
|
|
|
public string Service { get; set; } = default!; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -92,7 +92,7 @@ namespace Microsoft.Tye |
|
|
|
//
|
|
|
|
// Therefore our rewrite-target is set to $2 - we want to make sure we have
|
|
|
|
// two capture groups.
|
|
|
|
if (string.IsNullOrEmpty(ingressRule.Path) || ingressRule.Path == "/") |
|
|
|
if (string.IsNullOrEmpty(ingressRule.Path) || ingressRule.Path == "/" || ingressRule.PreservePath) |
|
|
|
{ |
|
|
|
path.Add("path", "/()(.*)"); // () is an empty capture group.
|
|
|
|
} |
|
|
|
|
|
|
|
@ -98,6 +98,13 @@ namespace Tye.Serialization |
|
|
|
case "path": |
|
|
|
rule.Path = YamlParser.GetScalarValue(key, child.Value); |
|
|
|
break; |
|
|
|
case "preservePath": |
|
|
|
if (!bool.TryParse(YamlParser.GetScalarValue(key, child.Value), out var preservePath)) |
|
|
|
{ |
|
|
|
throw new TyeYamlException(child.Value.Start, CoreStrings.FormatMustBeABoolean(key)); |
|
|
|
} |
|
|
|
rule.PreservePath = preservePath; |
|
|
|
break; |
|
|
|
case "service": |
|
|
|
rule.Service = YamlParser.GetScalarValue(key, child.Value).ToLowerInvariant(); |
|
|
|
break; |
|
|
|
|
|
|
|
@ -53,7 +53,9 @@ namespace Microsoft.Tye.Hosting |
|
|
|
var proxies = new List<Service>(); |
|
|
|
foreach (var service in application.Services.Values) |
|
|
|
{ |
|
|
|
if (service.Description.RunInfo is DockerRunInfo || service.Description.Bindings.Count == 0) |
|
|
|
if (service.Description.RunInfo is DockerRunInfo || |
|
|
|
service.Description.RunInfo is IngressRunInfo || |
|
|
|
service.Description.Bindings.Count == 0) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
@ -151,10 +151,9 @@ namespace Microsoft.Tye.Hosting |
|
|
|
await context.Response.WriteAsync("Bad gateway"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var uri = new UriBuilder(uris[next].Uri) |
|
|
|
{ |
|
|
|
Path = (string)context.Request.RouteValues["path"]!, |
|
|
|
Path = rule.PreservePath ? $"{context.Request.Path}{context.Request.RouteValues["path"]}" : (string)context.Request.RouteValues["path"] ?? "/", |
|
|
|
Query = context.Request.QueryString.Value |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
@ -11,15 +11,17 @@ namespace Microsoft.Tye.Hosting.Model |
|
|
|
{ |
|
|
|
public class IngressRule |
|
|
|
{ |
|
|
|
public IngressRule(string? host, string? path, string service) |
|
|
|
public IngressRule(string? host, string? path, string service, bool preservePath) |
|
|
|
{ |
|
|
|
Host = host; |
|
|
|
Path = path; |
|
|
|
PreservePath = preservePath; |
|
|
|
Service = service; |
|
|
|
} |
|
|
|
|
|
|
|
public string? Host { get; } |
|
|
|
public string? Path { get; } |
|
|
|
public bool PreservePath { get; } |
|
|
|
public string Service { get; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -447,6 +447,10 @@ |
|
|
|
"protocol": { |
|
|
|
"description": "The protocol used by the binding", |
|
|
|
"type": "string" |
|
|
|
}, |
|
|
|
"preservePath": { |
|
|
|
"description": "Whether to keep the path that was originally present or not.", |
|
|
|
"type": "boolean" |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
@ -190,7 +190,7 @@ namespace Microsoft.Tye |
|
|
|
|
|
|
|
foreach (var rule in ingress.Rules) |
|
|
|
{ |
|
|
|
rules.Add(new IngressRule(rule.Host, rule.Path, rule.Service!)); |
|
|
|
rules.Add(new IngressRule(rule.Host, rule.Path, rule.Service!, rule.PreservePath)); |
|
|
|
} |
|
|
|
|
|
|
|
var runInfo = new IngressRunInfo(rules); |
|
|
|
|