diff --git a/samples/voting/ingress.yml b/samples/voting/ingress.yml deleted file mode 100644 index 704b8831..00000000 --- a/samples/voting/ingress.yml +++ /dev/null @@ -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(/|$)(.*) \ No newline at end of file diff --git a/samples/voting/tye.yaml b/samples/voting/tye.yaml index f8eb59e4..52e0f652 100644 --- a/samples/voting/tye.yaml +++ b/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 diff --git a/src/Microsoft.Tye.Core/ApplicationFactory.cs b/src/Microsoft.Tye.Core/ApplicationFactory.cs index 5e161a36..8bb8e417 100644 --- a/src/Microsoft.Tye.Core/ApplicationFactory.cs +++ b/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); diff --git a/src/Microsoft.Tye.Core/ConfigModel/ConfigIngressRule.cs b/src/Microsoft.Tye.Core/ConfigModel/ConfigIngressRule.cs index 521cce32..701e9ab0 100644 --- a/src/Microsoft.Tye.Core/ConfigModel/ConfigIngressRule.cs +++ b/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; } diff --git a/src/Microsoft.Tye.Core/IngressRuleBuilder.cs b/src/Microsoft.Tye.Core/IngressRuleBuilder.cs index 5b6a11e7..bf627c9c 100644 --- a/src/Microsoft.Tye.Core/IngressRuleBuilder.cs +++ b/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; } } } diff --git a/src/Microsoft.Tye.Core/Serialization/ConfigIngressParser.cs b/src/Microsoft.Tye.Core/Serialization/ConfigIngressParser.cs index 94d2e5e1..d05416e3 100644 --- a/src/Microsoft.Tye.Core/Serialization/ConfigIngressParser.cs +++ b/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; diff --git a/src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor b/src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor index 6185c3dd..a55f0cc4 100644 --- a/src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor +++ b/src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor @@ -38,7 +38,7 @@ @if (service.Description.RunInfo!.Private) { -

Cluster IP

+

Private

} else if (service.Description.Bindings.Any()) { diff --git a/src/Microsoft.Tye.Hosting/HttpProxyService.cs b/src/Microsoft.Tye.Hosting/HttpProxyService.cs index 9f14c523..2a368844 100644 --- a/src/Microsoft.Tye.Hosting/HttpProxyService.cs +++ b/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); diff --git a/src/Microsoft.Tye.Hosting/Model/IngressRule.cs b/src/Microsoft.Tye.Hosting/Model/IngressRule.cs index 0a4bfbc5..542a8222 100644 --- a/src/Microsoft.Tye.Hosting/Model/IngressRule.cs +++ b/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; } } } diff --git a/src/Microsoft.Tye.Hosting/TransformProjectsIntoContainers.cs b/src/Microsoft.Tye.Hosting/TransformProjectsIntoContainers.cs index a60472f5..0b043721 100644 --- a/src/Microsoft.Tye.Hosting/TransformProjectsIntoContainers.cs +++ b/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)); diff --git a/src/Microsoft.Tye.HttpProxy/Startup.cs b/src/Microsoft.Tye.HttpProxy/Startup.cs index 46e9aecd..842bcba2 100644 --- a/src/Microsoft.Tye.HttpProxy/Startup.cs +++ b/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(); 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); diff --git a/src/tye/ApplicationBuilderExtensions.cs b/src/tye/ApplicationBuilderExtensions.cs index 288045d2..f7d79489 100644 --- a/src/tye/ApplicationBuilderExtensions.cs +++ b/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;