Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt cmp.Or #388

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1274,23 +1274,21 @@ func (lbc *LoadBalancerController) createConfig(ctx context.Context) (*nghttpx.I
}

slices.SortFunc(upstreams, func(a, b *nghttpx.Upstream) int {
if c := cmp.Compare(a.Host, b.Host); c != 0 {
return c
}

return cmp.Compare(a.Path, b.Path)
return cmp.Or(
cmp.Compare(a.Host, b.Host),
cmp.Compare(a.Path, b.Path),
)
})

upstreams = removeUpstreamsWithInconsistentBackendParams(ctx, upstreams)

for _, value := range upstreams {
backends := value.Backends
slices.SortFunc(backends, func(a, b nghttpx.Backend) int {
if c := cmp.Compare(a.Address, b.Address); c != 0 {
return c
}

return cmp.Compare(a.Port, b.Port)
return cmp.Or(
cmp.Compare(a.Address, b.Address),
cmp.Compare(a.Port, b.Port),
)
})

// remove duplicate Backend
Expand Down
9 changes: 4 additions & 5 deletions pkg/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ func loadBalancerIngressesIPEqual(a, b []networkingv1.IngressLoadBalancerIngress
// sortLoadBalancerIngress sorts a by IP and Hostname in the ascending order.
func sortLoadBalancerIngress(lbIngs []networkingv1.IngressLoadBalancerIngress) {
slices.SortFunc(lbIngs, func(a, b networkingv1.IngressLoadBalancerIngress) int {
if c := cmp.Compare(a.IP, b.IP); c != 0 {
return c
}

return cmp.Compare(a.Hostname, b.Hostname)
return cmp.Or(
cmp.Compare(a.IP, b.IP),
cmp.Compare(a.Hostname, b.Hostname),
)
})
}

Expand Down
14 changes: 5 additions & 9 deletions pkg/nghttpx/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,11 @@ func TLSCredShareSamePaths(a, b *TLSCred) bool {
}

func TLSCredCompare(a, b *TLSCred) int {
if c := cmp.Compare(a.Key.Path, b.Key.Path); c != 0 {
return c
}

if c := cmp.Compare(a.Cert.Path, b.Cert.Path); c != 0 {
return c
}

return cmp.Compare(a.OCSPResp.GetPath(), b.OCSPResp.GetPath())
return cmp.Or(
cmp.Compare(a.Key.Path, b.Key.Path),
cmp.Compare(a.Cert.Path, b.Cert.Path),
cmp.Compare(a.OCSPResp.GetPath(), b.OCSPResp.GetPath()),
)
}

// SortTLSCred sorts creds in ascending order of Key.Path, Cert.Path, and OCSPResp.Path.
Expand Down