optimize destinationRule generate (#782)

This commit is contained in:
澄潭
2024-01-19 18:06:19 +08:00
committed by GitHub
parent b8a01113e3
commit d3d000753d
3 changed files with 25 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ import (
"encoding/json"
"errors"
"fmt"
"sort"
"strings"
"sync"
@@ -673,6 +674,18 @@ func (m *IngressConfig) convertDestinationRule(configs []common.WrapperConfig) [
out := make([]config.Config, 0, len(destinationRules))
for _, dr := range destinationRules {
sort.SliceStable(dr.DestinationRule.TrafficPolicy.PortLevelSettings, func(i, j int) bool {
portI := dr.DestinationRule.TrafficPolicy.PortLevelSettings[i].Port
portJ := dr.DestinationRule.TrafficPolicy.PortLevelSettings[j].Port
if portI == nil && portJ == nil {
return true
} else if portI == nil {
return true
} else if portJ == nil {
return false
}
return portI.Number < portJ.Number
})
drName := util.CreateDestinationRuleName(m.clusterId, dr.ServiceKey.Namespace, dr.ServiceKey.Name)
out = append(out, config.Config{
Meta: config.Meta{

View File

@@ -65,7 +65,12 @@ func (u upstreamTLS) Parse(annotations Annotations, config *Ingress, _ *GlobalCo
}
defer func() {
config.UpstreamTLS = upstreamTLSConfig
if upstreamTLSConfig.BackendProtocol == defaultBackendProtocol {
// no need destination rule when use HTTP protocol
config.UpstreamTLS = nil
} else {
config.UpstreamTLS = upstreamTLSConfig
}
}()
if proto, err := annotations.ParseStringASAP(backendProtocol); err == nil {

View File

@@ -33,6 +33,12 @@ func TestUpstreamTLSParse(t *testing.T) {
input: Annotations{},
expect: nil,
},
{
input: Annotations{
buildNginxAnnotationKey(backendProtocol): "HTTP",
},
expect: nil,
},
{
input: Annotations{
buildNginxAnnotationKey(proxySSLSecret): "",