Skip to content

Commit

Permalink
udpate k8s ingress controller route policy (#651)
Browse files Browse the repository at this point in the history
* udpate k8s ingress controller route policy

* udpate k8s ingress controller route policy
  • Loading branch information
suchen-sci committed Jun 28, 2022
1 parent ce53b79 commit de365ae
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/object/ingresscontroller/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ type (
}
)

func (b *httpServerSpecBuilder) sortRules() {
hostRules := []*httpserver.Rule{}
hostRegRules := []*httpserver.Rule{}
noHostRules := []*httpserver.Rule{}
for _, rule := range b.Rules {
if rule.Host != "" {
hostRules = append(hostRules, rule)
} else if rule.HostRegexp != "" {
hostRegRules = append(hostRegRules, rule)
} else {
noHostRules = append(noHostRules, rule)
}
}
sort.Slice(hostRules, func(i, j int) bool {
return hostRules[i].Host < hostRules[j].Host
})
sort.Slice(hostRegRules, func(i, j int) bool {
return hostRegRules[i].HostRegexp < hostRegRules[j].HostRegexp
})
newRules := append(hostRules, hostRegRules...)
newRules = append(newRules, noHostRules...)
b.Rules = newRules
}

func newPipelineSpecBuilder(name string) *pipelineSpecBuilder {
return &pipelineSpecBuilder{
Kind: httppipeline.Kind,
Expand Down Expand Up @@ -388,6 +412,7 @@ func (st *specTranslator) translate() error {
}
st.translateIngressRules(b, ingress)
}
b.sortRules()

if p := st.pipelines[defaultPipelineName]; p != nil {
b.Rules = append(b.Rules, &httpserver.Rule{
Expand Down

0 comments on commit de365ae

Please sign in to comment.