Skip to content

Commit

Permalink
fix issue #633
Browse files Browse the repository at this point in the history
  • Loading branch information
localvar committed Jun 14, 2022
1 parent 786c7c9 commit ba8ffec
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions pkg/object/ingresscontroller/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,41 @@ func (st *specTranslator) translate() error {
st.translateIngressRules(b, ingress)
}

// sort rules by host
// * precise hosts first(in alphabetical order)
// * wildcard hosts next(in alphabetical order)
// * empty host last
sort.Slice(b.Rules, func(i, j int) bool {
r1, r2 := b.Rules[i], b.Rules[j]

if r1.Host != "" {
if r2.Host == "" {
return true
}
return r1.Host < r2.Host
}
if r2.Host != "" {
return false
}

if r1.HostRegexp == "" {
return false
}
if r2.HostRegexp == "" {
return true
}
return r1.HostRegexp < r2.HostRegexp
})

if p := st.pipelines[defaultPipelineName]; p != nil {
b.Rules = append(b.Rules, &httpserver.Rule{
Paths: []*httpserver.Path{
{
Backend: defaultPipelineName,
PathPrefix: "/",
},
},
r := b.Rules[len(b.Rules)-1]
if r.Host != "" || r.HostRegexp != "" {
r = &httpserver.Rule{}
b.Rules = append(b.Rules, r)
}
r.Paths = append(r.Paths, &httpserver.Path{
Backend: defaultPipelineName,
PathPrefix: "/",
})
}

Expand Down

0 comments on commit ba8ffec

Please sign in to comment.