Merge pull request #588 from philk/kubernetes-priorities

Prioritize kubernetes routes by path length
This commit is contained in:
Vincent Demeester 2016-08-05 11:08:07 +02:00 committed by GitHub
commit 1fc4c56bc4
3 changed files with 20 additions and 7 deletions

View file

@ -209,6 +209,7 @@ func (provider *Kubernetes) loadIngresses(k8sClient k8s.Client) (*types.Configur
Backend: r.Host + pa.Path,
PassHostHeader: PassHostHeader,
Routes: make(map[string]types.Route),
Priority: len(pa.Path),
}
}
if len(r.Host) > 0 {

View file

@ -237,6 +237,7 @@ func TestLoadIngresses(t *testing.T) {
"foo/bar": {
Backend: "foo/bar",
PassHostHeader: true,
Priority: len("/bar"),
Routes: map[string]types.Route{
"/bar": {
Rule: "PathPrefix:/bar",
@ -426,6 +427,7 @@ func TestRuleType(t *testing.T) {
expected := map[string]*types.Frontend{
"foo1/bar1": {
Backend: "foo1/bar1",
Priority: len("/bar1"),
Routes: map[string]types.Route{
"/bar1": {
Rule: "PathPrefixStrip:/bar1",
@ -437,6 +439,7 @@ func TestRuleType(t *testing.T) {
},
"foo1/bar2": {
Backend: "foo1/bar2",
Priority: len("/bar2"),
Routes: map[string]types.Route{
"/bar2": {
Rule: "Path:/bar2",
@ -448,6 +451,7 @@ func TestRuleType(t *testing.T) {
},
"foo2/bar1": {
Backend: "foo2/bar1",
Priority: len("/bar1"),
Routes: map[string]types.Route{
"/bar1": {
Rule: "PathPrefix:/bar1",
@ -459,6 +463,7 @@ func TestRuleType(t *testing.T) {
},
"foo2/bar2": {
Backend: "foo2/bar2",
Priority: len("/bar2"),
Routes: map[string]types.Route{
"/bar2": {
Rule: "PathStrip:/bar2",
@ -470,6 +475,7 @@ func TestRuleType(t *testing.T) {
},
"foo1/bar3": {
Backend: "foo1/bar3",
Priority: len("/bar3"),
Routes: map[string]types.Route{
"/bar3": {
Rule: "PathPrefix:/bar3",
@ -560,6 +566,7 @@ func TestGetPassHostHeader(t *testing.T) {
Frontends: map[string]*types.Frontend{
"foo/bar": {
Backend: "foo/bar",
Priority: len("/bar"),
Routes: map[string]types.Route{
"/bar": {
Rule: "PathPrefix:/bar",
@ -869,6 +876,7 @@ func TestLoadNamespacedIngresses(t *testing.T) {
"foo/bar": {
Backend: "foo/bar",
PassHostHeader: true,
Priority: len("/bar"),
Routes: map[string]types.Route{
"/bar": {
Rule: "PathPrefix:/bar",
@ -1116,6 +1124,7 @@ func TestLoadMultipleNamespacedIngresses(t *testing.T) {
"foo/bar": {
Backend: "foo/bar",
PassHostHeader: true,
Priority: len("/bar"),
Routes: map[string]types.Route{
"/bar": {
Rule: "PathPrefix:/bar",
@ -1137,6 +1146,7 @@ func TestLoadMultipleNamespacedIngresses(t *testing.T) {
"awesome/quix": {
Backend: "awesome/quix",
PassHostHeader: true,
Priority: len("/quix"),
Routes: map[string]types.Route{
"/quix": {
Rule: "PathPrefix:/quix",
@ -1227,6 +1237,7 @@ func TestHostlessIngress(t *testing.T) {
Frontends: map[string]*types.Frontend{
"/bar": {
Backend: "/bar",
Priority: len("/bar"),
Routes: map[string]types.Route{
"/bar": {
Rule: "PathPrefix:/bar",

View file

@ -9,6 +9,7 @@
[frontends]{{range $frontendName, $frontend := .Frontends}}
[frontends."{{$frontendName}}"]
backend = "{{$frontend.Backend}}"
priority = {{$frontend.Priority}}
passHostHeader = {{$frontend.PassHostHeader}}
{{range $routeName, $route := $frontend.Routes}}
[frontends."{{$frontendName}}".routes."{{$routeName}}"]