Skip to content

Commit

Permalink
Merge pull request #15 from AOEpeople/prefer-direct-path-ingresses
Browse files Browse the repository at this point in the history
Prefer direct path ingresses
  • Loading branch information
michaelklapper authored Oct 23, 2020
2 parents c4fdba7 + 764c834 commit 07be859
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/model/kube/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package kube
import (
"log"
"regexp"
"sort"

apps "k8s.io/api/apps/v1"
v1Batch "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -119,10 +120,19 @@ func groupByServiceName(ingresses *extensions.IngressList) map[string][]K8sIngre
for _, rule := range ing.Spec.Rules {
for _, p := range rule.HTTP.Paths {
name := p.Backend.ServiceName
ingressIndex[name] = append(ingressIndex[name], K8sIngressInfo{URL: rule.Host + p.Path, Host: rule.Host})
ingressIndex[name] = append(ingressIndex[name], K8sIngressInfo{URL: rule.Host + p.Path, Host: rule.Host, Path: p.Path})
}
}
}

// sort the available ingresses for an application by their path's length
// => prefer direct path ingresses
for name, ingresses := range ingressIndex {
sort.Slice(ingresses, func(i, j int) bool {
return len(ingresses[i].Path) < len(ingresses[j].Path)
})
ingressIndex[name] = ingresses
}
return ingressIndex
}

Expand Down
1 change: 1 addition & 0 deletions src/model/kube/statusFetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type (
K8sIngressInfo struct {
URL string
Host string
Path string
Alive bool
}

Expand Down

0 comments on commit 07be859

Please sign in to comment.