github.com/cilium/cilium@v1.16.2/pkg/k8s/watchers/utils/utils.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package utils
     5  
     6  import "github.com/cilium/cilium/pkg/loadbalancer"
     7  
     8  // Compare slices of backends to see if they are deeply equal.
     9  // The comparison is agnostic of the order in which the slices are provided.
    10  func DeepEqualBackends(backends1 []*loadbalancer.Backend, backends2 []*loadbalancer.Backend) bool {
    11  	if len(backends1) != len(backends2) {
    12  		return false
    13  	}
    14  
    15  	l3n4AddrMap := make(map[loadbalancer.L3n4Addr]struct{})
    16  
    17  	for _, backend1 := range backends1 {
    18  		l3n4AddrMap[backend1.L3n4Addr] = struct{}{}
    19  	}
    20  
    21  	for _, backend2 := range backends2 {
    22  		if _, ok := l3n4AddrMap[backend2.L3n4Addr]; ok {
    23  			continue
    24  		}
    25  		return false
    26  	}
    27  
    28  	return true
    29  }