37 Star 396 Fork 72

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
globaldns_common.go 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
package globaldns
import (
"fmt"
"strings"
"github.com/rancher/types/apis/management.cattle.io/v3"
"k8s.io/api/core/v1"
)
func gatherIngressEndpoints(ingressEps []v1.LoadBalancerIngress) []string {
var endpoints []string
for _, ep := range ingressEps {
if ep.IP != "" {
endpoints = append(endpoints, ep.IP)
} else if ep.Hostname != "" {
endpoints = append(endpoints, ep.Hostname)
}
}
return endpoints
}
func getMultiClusterAppName(multiClusterAppName string) (string, error) {
split := strings.SplitN(multiClusterAppName, ":", 2)
if len(split) != 2 {
return "", fmt.Errorf("error in splitting multiclusterapp ID %v", multiClusterAppName)
}
mcappName := split[1]
return mcappName, nil
}
func ifEndpointsDiffer(endpointsOne []string, endpointsTwo []string) bool {
if len(endpointsOne) != len(endpointsTwo) {
return true
}
mapEndpointsOne := make(map[string]bool)
for _, ep := range endpointsOne {
mapEndpointsOne[ep] = true
}
for _, ep := range endpointsTwo {
if !mapEndpointsOne[ep] {
return true
}
}
return false
}
func dedupEndpoints(endpoints []string) []string {
mapEndpoints := make(map[string]bool)
res := []string{}
for _, ep := range endpoints {
if !mapEndpoints[ep] {
mapEndpoints[ep] = true
res = append(res, ep)
}
}
return res
}
func reconcileGlobalDNSEndpoints(globalDNS *v3.GlobalDNS) {
//aggregate all clusterEndpoints and form the final DNS endpoints[]
var reconciledEps []string
originalEps := globalDNS.Status.Endpoints
for _, clusterEndpoints := range globalDNS.Status.ClusterEndpoints {
reconciledEps = append(reconciledEps, clusterEndpoints...)
}
//update the DNS endpoints if different
if ifEndpointsDiffer(originalEps, reconciledEps) {
globalDNS.Status.Endpoints = reconciledEps
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.0-rc15

搜索帮助

344bd9b3 5694891 D2dac590 5694891