MCPcopy Create free account
hub / github.com/deepflowio/deepflow / getSubDomainIPs

Method getSubDomainIPs

server/controller/cloud/sub_domain.go:704–766  ·  view source on GitHub ↗
(subDomainLcuuid string, cResource model.Resource, kResource *kubernetes_model.KubernetesGatherResource, existNodeIPs map[string]bool)

Source from the content-addressed store, hash-verified

702}
703
704func (c *Cloud) getSubDomainIPs(subDomainLcuuid string, cResource model.Resource, kResource *kubernetes_model.KubernetesGatherResource, existNodeIPs map[string]bool) ([]model.IP, map[string]int, map[string]string) {
705 var retIPs []model.IP
706 var reservedPodSubnetLcuuidToIPNum map[string]int
707 var updatedVInterfaceLcuuidToNetworkLcuuid map[string]string
708
709 // POD/Service IP无需处理子网信息,直接补充subDomainLcuuid
710 for _, ips := range [][]model.IP{kResource.PodIPs, kResource.PodServiceIPs} {
711 for _, ip := range ips {
712 retIPs = append(retIPs, model.IP{
713 Lcuuid: ip.Lcuuid,
714 VInterfaceLcuuid: ip.VInterfaceLcuuid,
715 IP: ip.IP,
716 SubnetLcuuid: ip.SubnetLcuuid,
717 RegionLcuuid: ip.RegionLcuuid,
718 SubDomainLcuuid: subDomainLcuuid,
719 })
720 }
721 }
722 // 容器节点IP需要检查是否属于云平台已有子网
723 // - 如果属于,更新SubnetLcuuid为云平台已有子网
724 // - 否则,保持原有SubnetLcuuid
725 // 针对KubernetesGather返回的子网,记录子网下剩余的IP个数,用于后期生成子网返回结果
726 subnets := []model.Subnet{}
727 reservedPodSubnetLcuuidToIPNum = make(map[string]int)
728 updatedVInterfaceLcuuidToNetworkLcuuid = make(map[string]string)
729 for _, subnet := range cResource.Subnets {
730 if subnet.VPCLcuuid != kResource.VPC.Lcuuid {
731 continue
732 }
733 subnets = append(subnets, subnet)
734 }
735 for _, ip := range kResource.PodNodeIPs {
736 // 过滤掉主云平台已经存在的node ip
737 if _, ok := existNodeIPs[ip.IP]; ok {
738 log.Debugf("subdomain node ip (%s) already exists on the vm ip", ip.IP, logger.NewORGPrefix(c.orgID))
739 continue
740 }
741 ipAddr, _ := netaddr.ParseIP(ip.IP)
742 subnetLcuuid := ""
743 for _, subnet := range subnets {
744 subnetCidr, _ := netaddr.ParseIPPrefix(subnet.CIDR)
745 if subnetCidr.Contains(ipAddr) {
746 subnetLcuuid = subnet.Lcuuid
747 updatedVInterfaceLcuuidToNetworkLcuuid[ip.VInterfaceLcuuid] = subnet.NetworkLcuuid
748 break
749 }
750 }
751 // 如果IP不在云平台已有子网中,则更新需要保留的kubernetesGather子网信息
752 if subnetLcuuid == "" {
753 reservedPodSubnetLcuuidToIPNum[ip.SubnetLcuuid] += 1
754 subnetLcuuid = ip.SubnetLcuuid
755 }
756 retIPs = append(retIPs, model.IP{
757 Lcuuid: ip.Lcuuid,
758 VInterfaceLcuuid: ip.VInterfaceLcuuid,
759 IP: ip.IP,
760 SubnetLcuuid: subnetLcuuid,
761 RegionLcuuid: ip.RegionLcuuid,

Callers 1

Calls 2

ContainsMethod · 0.80
DebugfMethod · 0.45

Tested by

no test coverage detected