Browse Source

Added support for preserving the path as part of ingress rules

pull/463/head
David Fowler 6 years ago
parent
commit
0c481e4b8f
  1. 21
      samples/voting/ingress.yml
  2. 11
      samples/voting/tye.yaml
  3. 1
      src/Microsoft.Tye.Core/ApplicationFactory.cs
  4. 1
      src/Microsoft.Tye.Core/ConfigModel/ConfigIngressRule.cs
  5. 1
      src/Microsoft.Tye.Core/IngressRuleBuilder.cs
  6. 7
      src/Microsoft.Tye.Core/Serialization/ConfigIngressParser.cs
  7. 2
      src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor
  8. 2
      src/Microsoft.Tye.Hosting/HttpProxyService.cs
  9. 4
      src/Microsoft.Tye.Hosting/Model/IngressRule.cs
  10. 1
      src/Microsoft.Tye.Hosting/TransformProjectsIntoContainers.cs
  11. 3
      src/Microsoft.Tye.HttpProxy/Startup.cs
  12. 5
      src/tye/ApplicationBuilderExtensions.cs

21
samples/voting/ingress.yml

@ -1,21 +0,0 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-basic
namespace: default
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- http:
paths:
- backend:
serviceName: vote
servicePort: 80
path: /vote(/|$)(.*)
- backend:
serviceName: results
servicePort: 80
path: /results(/|$)(.*)

11
samples/voting/tye.yaml

@ -1,4 +1,15 @@
name: VotingSample
ingress:
name: ingress
rules:
- path: /vote
preservePath: true
service: vote
- path: /results
preservePath: true
service: results
services:
- name: vote
project: vote/vote.csproj

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

@ -322,6 +322,7 @@ namespace Microsoft.Tye
{
Host = configRule.Host,
Path = configRule.Path,
PreservePath = configRule.PreservePath,
Service = configRule.Service!, // validated elsewhere
};
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? Host { get; set; }
public bool PreservePath { get; set; }
[Required]
public string? Service { get; set; }

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

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

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

@ -79,6 +79,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);
break;

2
src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor

@ -38,7 +38,7 @@
<td>
@if (service.Description.RunInfo!.Private)
{
<p>Cluster IP</p>
<p>Private</p>
}
else if (service.Description.Bindings.Any())
{

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

@ -127,7 +127,7 @@ namespace Microsoft.Tye.Hosting
var uri = new UriBuilder(uris[next])
{
Path = (string)context.Request.RouteValues["path"] ?? "/"
Path = rule.PreservePath ? context.Request.Path.ToString() : (string)context.Request.RouteValues["path"] ?? "/"
};
return context.ProxyRequest(invoker, uri.Uri);

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

@ -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;
Service = service;
PreservePath = preservePath;
}
public string? Host { get; }
public string? Path { get; }
public bool PreservePath { get; set; }
public string Service { get; }
}
}

1
src/Microsoft.Tye.Hosting/TransformProjectsIntoContainers.cs

@ -102,6 +102,7 @@ namespace Microsoft.Tye.Hosting
service.Description.Configuration.Add(new EnvironmentVariable($"{rulePrefix}Host", rule.Host));
service.Description.Configuration.Add(new EnvironmentVariable($"{rulePrefix}Path", rule.Path));
service.Description.Configuration.Add(new EnvironmentVariable($"{rulePrefix}PreservePath", rule.PreservePath.ToString()));
service.Description.Configuration.Add(new EnvironmentVariable($"{rulePrefix}Service", rule.Service));
service.Description.Configuration.Add(new EnvironmentVariable($"{rulePrefix}Port", (targetBinding.ContainerPort ?? targetBinding.Port).ToString()));
service.Description.Configuration.Add(new EnvironmentVariable($"{rulePrefix}Protocol", targetBinding.Protocol));

3
src/Microsoft.Tye.HttpProxy/Startup.cs

@ -44,6 +44,7 @@ namespace Microsoft.Tye.HttpProxy
{
var host = rule["Host"];
var path = rule["Path"];
var preservePath = rule.GetSection("PreservePath").Get<bool>();
var service = rule["Service"];
var port = rule["Port"];
var protocol = rule["Protocol"];
@ -54,7 +55,7 @@ namespace Microsoft.Tye.HttpProxy
{
var uri = new UriBuilder(url)
{
Path = (string)context.Request.RouteValues["path"] ?? "/"
Path = preservePath ? context.Request.Path.ToString() : (string)context.Request.RouteValues["path"] ?? "/"
};
return context.ProxyRequest(invoker, uri.Uri);

5
src/tye/ApplicationBuilderExtensions.cs

@ -41,7 +41,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);
@ -64,6 +64,9 @@ namespace Microsoft.Tye
services.Add(ingress.Name, new Service(description));
}
// If there's an ingress then the service is private
var privateService = ingress != null;
foreach (var service in application.Services)
{
RunInfo? runInfo;

Loading…
Cancel
Save