Skip to content

Commit

Permalink
feat: default genesis sync vpc name
Browse files Browse the repository at this point in the history
  • Loading branch information
askyrie authored and SongZhen0704 committed Sep 13, 2024
1 parent f5f2f22 commit a5ea2c2
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 62 deletions.
1 change: 0 additions & 1 deletion server/controller/cloud/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type CloudConfig struct {
KubernetesGatherInterval uint32 `default:"30" yaml:"kubernetes_gather_interval"`
AliyunRegionName string `default:"cn-beijing" yaml:"aliyun_region_name"`
AWSRegionName string `default:"cn-north-1" yaml:"aws_region_name"`
GenesisDefaultVpcName string `default:"default_vpc" yaml:"genesis_default_vpc"`
HostnameToIPFile string `default:"/etc/hostname_to_ip.csv" yaml:"hostname_to_ip_file"`
DNSEnable bool `default:"false" yaml:"dns_enable"`
HTTPTimeout int `default:"30" yaml:"http_timeout"`
Expand Down
12 changes: 0 additions & 12 deletions server/controller/cloud/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ import (
var log = logging.MustGetLogger("cloud.genesis")

type Genesis struct {
defaultVpc bool
ipV4CIDRMaxMask int
ipV6CIDRMaxMask int
Name string
Lcuuid string
UuidGenerate string
regionUuid string
azLcuuid string
defaultVpcName string
ips []cloudmodel.IP
subnets []cloudmodel.Subnet
genesisData genesis.GenesisSyncData
Expand All @@ -73,7 +71,6 @@ func NewGenesis(domain mysql.Domain, cfg config.CloudConfig) (*Genesis, error) {
Name: domain.Name,
Lcuuid: domain.Lcuuid,
UuidGenerate: domain.DisplayName,
defaultVpcName: cfg.GenesisDefaultVpcName,
regionUuid: config.Get("region_uuid").MustString(),
genesisData: genesis.GenesisSyncData{},
cloudStatsd: statsd.NewCloudStatsd(),
Expand Down Expand Up @@ -258,7 +255,6 @@ func (g *Genesis) generateIPsAndSubnets() {

func (g *Genesis) GetCloudData() (cloudmodel.Resource, error) {
g.azLcuuid = ""
g.defaultVpc = false
g.cloudStatsd = statsd.NewCloudStatsd()

if genesis.GenesisService == nil {
Expand Down Expand Up @@ -312,14 +308,6 @@ func (g *Genesis) GetCloudData() (cloudmodel.Resource, error) {
if err != nil {
return cloudmodel.Resource{}, err
}
if g.defaultVpc {
vpc := cloudmodel.VPC{
Lcuuid: common.GetUUID(g.defaultVpcName, uuid.Nil),
Name: g.defaultVpcName,
RegionLcuuid: g.regionUuid,
}
vpcs = append(vpcs, vpc)
}

resource := cloudmodel.Resource{
IPs: ips,
Expand Down
10 changes: 1 addition & 9 deletions server/controller/cloud/genesis/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
"time"

"github.com/deepflowio/deepflow/server/controller/cloud/model"
"github.com/deepflowio/deepflow/server/controller/common"

uuid "github.com/satori/go.uuid"
)

func (g *Genesis) getNetworks() ([]model.Network, error) {
Expand All @@ -38,11 +35,6 @@ func (g *Genesis) getNetworks() ([]model.Network, error) {
log.Debug("segmentation id not found")
continue
}
vpcLcuuid := n.VPCLcuuid
if vpcLcuuid == "" {
vpcLcuuid = common.GetUUID(g.defaultVpcName, uuid.Nil)
g.defaultVpc = true
}
networkName := n.Name
if networkName == "" {
networkName = "subnet_vni_" + strconv.Itoa(int(n.SegmentationID))
Expand All @@ -51,7 +43,7 @@ func (g *Genesis) getNetworks() ([]model.Network, error) {
Lcuuid: n.Lcuuid,
Name: networkName,
SegmentationID: int(n.SegmentationID),
VPCLcuuid: vpcLcuuid,
VPCLcuuid: n.VPCLcuuid,
Shared: false,
External: n.External,
NetType: int(n.NetType),
Expand Down
10 changes: 1 addition & 9 deletions server/controller/cloud/genesis/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import (
"time"

"github.com/deepflowio/deepflow/server/controller/cloud/model"
"github.com/deepflowio/deepflow/server/controller/common"

uuid "github.com/satori/go.uuid"
)

func (g *Genesis) getSubnets() ([]model.Subnet, error) {
Expand All @@ -36,11 +33,6 @@ func (g *Genesis) getSubnets() ([]model.Subnet, error) {
log.Debug("network lcuuid not found")
continue
}
vpcLcuuid := s.VPCLcuuid
if vpcLcuuid == "" {
vpcLcuuid = common.GetUUID(g.defaultVpcName, uuid.Nil)
g.defaultVpc = true
}
subnetName := s.Name
if subnetName == "" {
subnetName = "subnet_" + s.Lcuuid[:11]
Expand All @@ -49,7 +41,7 @@ func (g *Genesis) getSubnets() ([]model.Subnet, error) {
Lcuuid: s.Lcuuid,
Name: subnetName,
CIDR: s.CIDR,
VPCLcuuid: vpcLcuuid,
VPCLcuuid: s.VPCLcuuid,
NetworkLcuuid: s.NetworkLcuuid,
}
subnets = append(subnets, subnet)
Expand Down
10 changes: 1 addition & 9 deletions server/controller/cloud/genesis/vinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import (
"time"

"github.com/deepflowio/deepflow/server/controller/cloud/model"
"github.com/deepflowio/deepflow/server/controller/common"

uuid "github.com/satori/go.uuid"
)

func (g *Genesis) getVinterfaces() ([]model.VInterface, error) {
Expand All @@ -37,16 +34,11 @@ func (g *Genesis) getVinterfaces() ([]model.VInterface, error) {
log.Debug("device lcuuid or network lcuuid not found")
continue
}
vpcLcuuid := v.VPCLcuuid
if vpcLcuuid == "" {
vpcLcuuid = common.GetUUID(g.defaultVpcName, uuid.Nil)
g.defaultVpc = true
}
vinterface := model.VInterface{
Lcuuid: v.Lcuuid,
Type: int(v.Type),
Mac: v.Mac,
VPCLcuuid: vpcLcuuid,
VPCLcuuid: v.VPCLcuuid,
RegionLcuuid: g.regionUuid,
DeviceType: int(v.DeviceType),
DeviceLcuuid: v.DeviceLcuuid,
Expand Down
9 changes: 1 addition & 8 deletions server/controller/cloud/genesis/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (

"github.com/deepflowio/deepflow/server/controller/cloud/model"
"github.com/deepflowio/deepflow/server/controller/common"

uuid "github.com/satori/go.uuid"
)

func (g *Genesis) getVMs() ([]model.VM, error) {
Expand All @@ -33,11 +31,6 @@ func (g *Genesis) getVMs() ([]model.VM, error) {
g.cloudStatsd.RefreshAPIMoniter("vms", len(vmsData), time.Time{})

for _, v := range vmsData {
vpcLcuuid := v.VPCLcuuid
if vpcLcuuid == "" {
vpcLcuuid = common.GetUUID(g.defaultVpcName, uuid.Nil)
g.defaultVpc = true
}
launchServer := v.LaunchServer
if launchServer == "127.0.0.1" {
launchServer = ""
Expand All @@ -47,7 +40,7 @@ func (g *Genesis) getVMs() ([]model.VM, error) {
Name: v.Name,
Label: v.Label,
HType: common.VM_HTYPE_VM_C,
VPCLcuuid: vpcLcuuid,
VPCLcuuid: v.VPCLcuuid,
State: int(v.State),
LaunchServer: launchServer,
CreatedAt: v.CreatedAt,
Expand Down
9 changes: 1 addition & 8 deletions server/controller/cloud/genesis/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import (
"time"

"github.com/deepflowio/deepflow/server/controller/cloud/model"
"github.com/deepflowio/deepflow/server/controller/common"

uuid "github.com/satori/go.uuid"
)

func (g *Genesis) getVPCs() ([]model.VPC, error) {
Expand All @@ -33,12 +30,8 @@ func (g *Genesis) getVPCs() ([]model.VPC, error) {
g.cloudStatsd.RefreshAPIMoniter("vpcs", len(vpcsData), time.Time{})

for _, v := range vpcsData {
vpcLcuuid := v.Lcuuid
if vpcLcuuid == "" {
vpcLcuuid = common.GetUUID(v.Name, uuid.Nil)
}
vpc := model.VPC{
Lcuuid: vpcLcuuid,
Lcuuid: v.Lcuuid,
Name: v.Name,
RegionLcuuid: g.regionUuid,
}
Expand Down
1 change: 1 addition & 0 deletions server/controller/genesis/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type GenesisConfig struct {
DataPersistenceInterval int `default:"60" yaml:"data_persistence_interval"`
MultiNSMode bool `default:"false" yaml:"multi_ns_mode"`
SingleVPCMode bool `default:"false" yaml:"single_vpc_mode"`
DefaultVPCName string `default:"default-public-vpc" yaml:"default_vpc_name"`
IgnoreNICRegex string `default:"^(kube-ipvs)" yaml:"ignore_nic_regex"`
VMNameField string `default:"metadata" yaml:"vm_name_field"`
}
12 changes: 8 additions & 4 deletions server/controller/genesis/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type GenesisSyncRpcUpdater struct {
multiNSMode bool
singleVPCMode bool
vmNameField string
defaultVPCName string
ignoreNICRegex *regexp.Regexp
genesisSyncDataByPeer map[uint32]GenesisSyncDataOperation
}
Expand Down Expand Up @@ -144,6 +145,7 @@ func NewGenesisSyncRpcUpdater(storage *SyncStorage, queue queue.QueueReader, cfg
multiNSMode: cfg.MultiNSMode,
singleVPCMode: cfg.SingleVPCMode,
vmNameField: cfg.VMNameField,
defaultVPCName: cfg.DefaultVPCName,
ignoreNICRegex: ignoreNICRegex,
genesisSyncDataByPeer: map[uint32]GenesisSyncDataOperation{},
}
Expand Down Expand Up @@ -374,13 +376,15 @@ func (v *GenesisSyncRpcUpdater) ParseHostAsVmPlatformInfo(info VIFRPCMessage, pe
log.Error(err.Error())
return GenesisSyncDataOperation{}
}
// check if vm is behind NAT
behindNat := peer != natIP

vpc := model.GenesisVpc{
Name: "default-public-cloud-vpc",
Lcuuid: common.GetUUID("default-public-cloud-vpc", uuid.Nil),
Name: v.defaultVPCName,
Lcuuid: common.GetUUID(v.defaultVPCName, uuid.Nil),
VtapID: vtapID,
}
// check if vm is behind NAT
behindNat := peer != natIP
log.Infof("host (%s) nat ip is (%s) peer ip is (%s), behind nat: (%t), single vpc mode: (%t)", hostName, natIP, peer, behindNat, v.singleVPCMode)
if behindNat && !v.singleVPCMode {
vpc = model.GenesisVpc{
Name: "VPC-" + peer,
Expand Down
5 changes: 3 additions & 2 deletions server/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ controller:
aliyun_region_name: cn-beijing
# AWS API获取区域列表时,需要指定一个区域,并通过这个区域区分国际版和国内版
aws_region_name: cn-north-1
# 采集器同步默认vpc名称
genesis_default_vpc: default_vpc
# 配置宿主机IP文件
hostname_to_ip_file: /etc/hostname_to_ip.csv
# 开启debug模式,支持debug云平台API/SDK原始数据
Expand Down Expand Up @@ -269,6 +267,9 @@ controller:
ipv4_cidr_max_mask: 24
ipv6_cidr_max_mask: 64

# 采集器同步默认vpc名称
default_vpc_name: default-public-vpc

# 采集器上报数据处理的队列长度
queue_length: 1000

Expand Down

0 comments on commit a5ea2c2

Please sign in to comment.