Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <wenqiq@vmware.com>
wenqiq committed Aug 8, 2024
1 parent 77cacc1 commit 4855c5e
Showing 5 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/networkinfo/vpcnetworkconfig_handler.go
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ var VPCNetworkConfigurationPredicate = predicate.Funcs{
func buildNetworkConfigInfo(vpcConfigCR v1alpha1.VPCNetworkConfiguration) (*commontypes.VPCNetworkConfigInfo, error) {
org, project, err := nsxtProjectPathToId(vpcConfigCR.Spec.NSXProject)
if err != nil {
log.Error(err, "failed to parse nsx-t project in network config", "Project Path", vpcConfigCR.Spec.NSXProject)
log.Error(err, "failed to parse NSX project in network config", "Project Path", vpcConfigCR.Spec.NSXProject)
return nil, err
}

8 changes: 4 additions & 4 deletions pkg/nsx/services/vpc/builder.go
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ func buildPrivateIpBlock(networkInfo *v1alpha1.NetworkInfo, nsObj *v1.Namespace,
return block
}

func buildNSXVPC(obj *v1alpha1.NetworkInfo, nsObj *v1.Namespace, nc common.VPCNetworkConfigInfo, cluster string, pathMap map[string]string,
func buildNSXVPC(obj *v1alpha1.NetworkInfo, nsObj *v1.Namespace, nc common.VPCNetworkConfigInfo, cluster string,
nsxVPC *model.Vpc, useAVILB bool) (*model.Vpc,
error) {
vpc := &model.Vpc{}
@@ -80,9 +80,9 @@ func buildNSXVPC(obj *v1alpha1.NetworkInfo, nsObj *v1.Namespace, nc common.VPCNe
vpc.VpcConnectivityProfile = &nc.VPCConnectivityProfile
}

// TODO: add PrivateIps and remove PrivateIpv4Blocks once the NSX VPC API support private_ips field.
// vpc.PrivateIps = nc.PrivateIPs
vpc.PrivateIpv4Blocks = util.GetMapValues(pathMap)
if nc.PrivateIPs != nil {
vpc.PrivateIps = nc.PrivateIPs
}
if nc.ShortID != "" {
vpc.ShortId = &nc.ShortID
}
6 changes: 1 addition & 5 deletions pkg/nsx/services/vpc/builder_test.go
Original file line number Diff line number Diff line change
@@ -95,7 +95,6 @@ func TestBuildNSXVPC(t *testing.T) {
for _, tc := range []struct {
name string
existingVPC *model.Vpc
pathMap map[string]string
useAVILB bool
expVPC *model.Vpc
}{
@@ -111,7 +110,6 @@ func TestBuildNSXVPC(t *testing.T) {
existingVPC: &model.Vpc{
PrivateIpv4Blocks: []string{},
},
pathMap: map[string]string{"vpc1": "192.168.3.0/24"},
useAVILB: false,
expVPC: &model.Vpc{
PrivateIpv4Blocks: []string{"192.168.3.0/24"},
@@ -120,7 +118,6 @@ func TestBuildNSXVPC(t *testing.T) {
},
{
name: "create new VPC with AVI load balancer enabled",
pathMap: map[string]string{"vpc1": "192.168.3.0/24"},
useAVILB: true,
expVPC: &model.Vpc{
Id: common.String("ns1-netinfouid1"),
@@ -139,7 +136,6 @@ func TestBuildNSXVPC(t *testing.T) {
},
{
name: "create new VPC with AVI load balancer disabled",
pathMap: map[string]string{"vpc1": "192.168.3.0/24"},
useAVILB: false,
expVPC: &model.Vpc{
Id: common.String("ns1-netinfouid1"),
@@ -157,7 +153,7 @@ func TestBuildNSXVPC(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
got, err := buildNSXVPC(netInfoObj, nsObj, nc, clusterStr, tc.pathMap, tc.existingVPC, tc.useAVILB)
got, err := buildNSXVPC(netInfoObj, nsObj, nc, clusterStr, tc.existingVPC, tc.useAVILB)
assert.Nil(t, err)
assert.Equal(t, tc.expVPC, got)
})
2 changes: 1 addition & 1 deletion pkg/nsx/services/vpc/compare.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
// currently we only support appending public/private cidrs
// so only comparing list size is enough to identify if vcp changed
func IsVPCChanged(nc common.VPCNetworkConfigInfo, vpc *model.Vpc) bool {
if len(nc.PrivateIPs) != len(vpc.PrivateIpv4Blocks) {
if len(nc.PrivateIPs) != len(vpc.PrivateIps) {
return true
}

10 changes: 2 additions & 8 deletions pkg/nsx/services/vpc/vpc.go
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ func (s *VPCService) GetVPCNetworkConfigByNamespace(ns string) *common.VPCNetwor
// TBD: for now, if network config info do not contains private cidr, we consider this is
// incorrect configuration, and skip creating this VPC CR
func (s *VPCService) ValidateNetworkConfig(nc common.VPCNetworkConfigInfo) bool {
return nc.PrivateIPs != nil && len(nc.PrivateIPs) != 0
return true
}

// InitializeVPC sync NSX resources
@@ -555,12 +555,6 @@ func (s *VPCService) CreateOrUpdateVPC(obj *v1alpha1.NetworkInfo) (*model.Vpc, *

log.Info("read network config from store", "NetworkConfig", ncName)

paths, err := s.CreateOrUpdatePrivateIPBlock(obj, nsObj, nc)
if err != nil {
log.Error(err, "failed to process private ip blocks, push event back to queue")
return nil, nil, err
}

// if all private ip blocks are created, then create nsx vpc resource.
nsxVPC := &model.Vpc{}
if updateVpc {
@@ -571,7 +565,7 @@ func (s *VPCService) CreateOrUpdateVPC(obj *v1alpha1.NetworkInfo) (*model.Vpc, *
nsxVPC = nil
}

createdVpc, err := buildNSXVPC(obj, nsObj, nc, s.NSXConfig.Cluster, paths, nsxVPC, s.NSXConfig.NsxConfig.UseAVILoadBalancer)
createdVpc, err := buildNSXVPC(obj, nsObj, nc, s.NSXConfig.Cluster, nsxVPC, s.NSXConfig.NsxConfig.UseAVILoadBalancer)
if err != nil {
log.Error(err, "failed to build NSX VPC object")
return nil, nil, err

0 comments on commit 4855c5e

Please sign in to comment.