Browse Source

Adds preservePath for ingress (#747)

finitereality/replica-status-colors
Justin Kotalik 6 years ago
committed by GitHub
parent
commit
df18a1d31b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/Microsoft.Tye.Core/ApplicationFactory.cs
  2. 1
      src/Microsoft.Tye.Core/ConfigModel/ConfigIngressRule.cs
  3. 2
      src/Microsoft.Tye.Core/IngressRuleBuilder.cs
  4. 2
      src/Microsoft.Tye.Core/KubernetesManifestGenerator.cs
  5. 7
      src/Microsoft.Tye.Core/Serialization/ConfigIngressParser.cs
  6. 4
      src/Microsoft.Tye.Hosting/DockerRunner.cs
  7. 3
      src/Microsoft.Tye.Hosting/HttpProxyService.cs
  8. 4
      src/Microsoft.Tye.Hosting/Model/IngressRule.cs
  9. 4
      src/schema/tye-schema.json
  10. 2
      src/tye/ApplicationBuilderExtensions.cs

1
src/Microsoft.Tye.Core/ApplicationFactory.cs

@ -465,6 +465,7 @@ namespace Microsoft.Tye
{ {
Host = configRule.Host, Host = configRule.Host,
Path = configRule.Path, Path = configRule.Path,
PreservePath = configRule.PreservePath,
Service = configRule.Service!, // validated elsewhere Service = configRule.Service!, // validated elsewhere
}; };
ingress.Rules.Add(rule); ingress.Rules.Add(rule);

1
src/Microsoft.Tye.Core/ConfigModel/ConfigIngressRule.cs

@ -10,6 +10,7 @@ namespace Microsoft.Tye.ConfigModel
{ {
public string? Path { get; set; } public string? Path { get; set; }
public string? Host { get; set; } public string? Host { get; set; }
public bool PreservePath { get; set; }
[Required] [Required]
public string? Service { get; set; } public string? Service { get; set; }

2
src/Microsoft.Tye.Core/IngressRuleBuilder.cs

@ -8,6 +8,8 @@ namespace Microsoft.Tye
{ {
public string? Path { get; set; } public string? Path { get; set; }
public string? Host { get; set; } public string? Host { get; set; }
public bool PreservePath { get; set; }
public string Service { get; set; } = default!; public string Service { get; set; } = default!;
} }
} }

2
src/Microsoft.Tye.Core/KubernetesManifestGenerator.cs

@ -92,7 +92,7 @@ namespace Microsoft.Tye
// //
// Therefore our rewrite-target is set to $2 - we want to make sure we have // Therefore our rewrite-target is set to $2 - we want to make sure we have
// two capture groups. // 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. path.Add("path", "/()(.*)"); // () is an empty capture group.
} }

7
src/Microsoft.Tye.Core/Serialization/ConfigIngressParser.cs

@ -98,6 +98,13 @@ namespace Tye.Serialization
case "path": case "path":
rule.Path = YamlParser.GetScalarValue(key, child.Value); rule.Path = YamlParser.GetScalarValue(key, child.Value);
break; 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": case "service":
rule.Service = YamlParser.GetScalarValue(key, child.Value).ToLowerInvariant(); rule.Service = YamlParser.GetScalarValue(key, child.Value).ToLowerInvariant();
break; break;

4
src/Microsoft.Tye.Hosting/DockerRunner.cs

@ -53,7 +53,9 @@ namespace Microsoft.Tye.Hosting
var proxies = new List<Service>(); var proxies = new List<Service>();
foreach (var service in application.Services.Values) 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; continue;
} }

3
src/Microsoft.Tye.Hosting/HttpProxyService.cs

@ -151,10 +151,9 @@ namespace Microsoft.Tye.Hosting
await context.Response.WriteAsync("Bad gateway"); await context.Response.WriteAsync("Bad gateway");
return; return;
} }
var uri = new UriBuilder(uris[next].Uri) 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 Query = context.Request.QueryString.Value
}; };

4
src/Microsoft.Tye.Hosting/Model/IngressRule.cs

@ -11,15 +11,17 @@ namespace Microsoft.Tye.Hosting.Model
{ {
public class IngressRule public class IngressRule
{ {
public IngressRule(string? host, string? path, string service) public IngressRule(string? host, string? path, string service, bool preservePath)
{ {
Host = host; Host = host;
Path = path; Path = path;
PreservePath = preservePath;
Service = service; Service = service;
} }
public string? Host { get; } public string? Host { get; }
public string? Path { get; } public string? Path { get; }
public bool PreservePath { get; }
public string Service { get; } public string Service { get; }
} }
} }

4
src/schema/tye-schema.json

@ -447,6 +447,10 @@
"protocol": { "protocol": {
"description": "The protocol used by the binding", "description": "The protocol used by the binding",
"type": "string" "type": "string"
},
"preservePath": {
"description": "Whether to keep the path that was originally present or not.",
"type": "boolean"
} }
} }
}, },

2
src/tye/ApplicationBuilderExtensions.cs

@ -190,7 +190,7 @@ namespace Microsoft.Tye
foreach (var rule in ingress.Rules) 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); var runInfo = new IngressRunInfo(rules);

Loading…
Cancel
Save