Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq committed Sep 4, 2024
1 parent 1329d5f commit 92175f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/networkinfo/networkinfo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (r *NetworkInfoReconciler) Reconcile(ctx context.Context, req ctrl.Request)
VPCPath: *createdVpc.Path,
}
// AKO needs to know the AVI subnet path created by NSX
setVPCNetworkConfigurationStatusWithLBS(ctx, r.Client, ncName, state.Name, path, r.Service.GetNSXLBSPath(*createdVpc.Id), *createdVpc.Path)
setVPCNetworkConfigurationStatusWithLBS(ctx, r.Client, ncName, state.Name, path, r.Service.GetDefaultNSXLBSPathByVPC(*createdVpc.Id), *createdVpc.Path)
updateSuccess(r, ctx, obj, r.Client, state, nc.Name, path)
} else {
if controllerutil.ContainsFinalizer(obj, commonservice.NetworkInfoFinalizerName) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/controllers/networkinfo/networkinfo_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestNetworkInfoReconciler_Reconcile(t *testing.T) {
Values: gomonkey.Params{model.VpcConnectivityProfile{ExternalIpBlocks: []string{"fake-ip-block"}}, nil},
Times: 1,
}})
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetNSXLBSPath", func(_ *vpc.VPCService, _ string) string {
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetDefaultNSXLBSPathByVPC", func(_ *vpc.VPCService, _ string) string {
return "lbs-path"

})
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestNetworkInfoReconciler_Reconcile(t *testing.T) {
Values: gomonkey.Params{model.VpcConnectivityProfile{ExternalIpBlocks: []string{"fake-ip-block"}}, nil},
Times: 1,
}})
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetNSXLBSPath", func(_ *vpc.VPCService, _ string) string {
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetDefaultNSXLBSPathByVPC", func(_ *vpc.VPCService, _ string) string {
return "lbs-path"

})
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestNetworkInfoReconciler_Reconcile(t *testing.T) {
}, nil},
Times: 1,
}})
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetNSXLBSPath", func(_ *vpc.VPCService, _ string) string {
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetDefaultNSXLBSPathByVPC", func(_ *vpc.VPCService, _ string) string {
return "lbs-path"

})
Expand Down Expand Up @@ -392,7 +392,7 @@ func TestNetworkInfoReconciler_Reconcile(t *testing.T) {
}, nil},
Times: 1,
}})
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetNSXLBSPath", func(_ *vpc.VPCService, _ string) string {
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetDefaultNSXLBSPathByVPC", func(_ *vpc.VPCService, _ string) string {
return "lbs-path"

})
Expand Down Expand Up @@ -471,7 +471,7 @@ func TestNetworkInfoReconciler_Reconcile(t *testing.T) {
}, nil},
Times: 1,
}})
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetNSXLBSPath", func(_ *vpc.VPCService, _ string) string {
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetDefaultNSXLBSPathByVPC", func(_ *vpc.VPCService, _ string) string {
return "lbs-path"

})
Expand Down Expand Up @@ -547,7 +547,7 @@ func TestNetworkInfoReconciler_Reconcile(t *testing.T) {
t.Log("setVPCNetworkConfigurationStatusWithNoExternalIPBlock")
})

patches.ApplyMethod(reflect.TypeOf(r.Service), "GetNSXLBSPath", func(_ *vpc.VPCService, _ string) string {
patches.ApplyMethod(reflect.TypeOf(r.Service), "GetDefaultNSXLBSPathByVPC", func(_ *vpc.VPCService, _ string) string {
return "lbs-path"

})
Expand Down
24 changes: 12 additions & 12 deletions pkg/nsx/services/vpc/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,9 @@ func (s *VPCService) Cleanup(ctx context.Context) error {
return nil
}

func (service *VPCService) ListVPCInfo(ns string) []common.VPCResourceInfo {
func (s *VPCService) ListVPCInfo(ns string) []common.VPCResourceInfo {
var VPCInfoList []common.VPCResourceInfo
nc := service.GetVPCNetworkConfigByNamespace(ns)
nc := s.GetVPCNetworkConfigByNamespace(ns)
// Return the pre-created VPC resource info if it is set in VPCNetworkConfiguration.
if nc != nil && IsPreCreatedVPC(*nc) {
vpcResourceInfo, err := common.ParseVPCResourcePath(nc.VPCPath)
Expand All @@ -985,7 +985,7 @@ func (service *VPCService) ListVPCInfo(ns string) []common.VPCResourceInfo {
}

// List VPCs from local store.
vpcs := service.GetVPCsByNamespace(ns) // Transparently call the VPCService.GetVPCsByNamespace method
vpcs := s.GetVPCsByNamespace(ns) // Transparently call the VPCService.GetVPCsByNamespace method
for _, v := range vpcs {
vpcResourceInfo, err := common.ParseVPCResourcePath(*v.Path)
if err != nil {
Expand All @@ -997,7 +997,7 @@ func (service *VPCService) ListVPCInfo(ns string) []common.VPCResourceInfo {
return VPCInfoList
}

func (s *VPCService) GetNSXLBSPath(vpcID string) string {
func (s *VPCService) GetDefaultNSXLBSPathByVPC(vpcID string) string {
vpcLBS := s.LbsStore.GetByKey(vpcID)
if vpcLBS == nil {
return ""
Expand All @@ -1010,21 +1010,21 @@ func GetAlbEndpoint(cluster *nsx.Cluster) error {
return err
}

func (vpcService *VPCService) NSXLBEnabled() bool {
func (s *VPCService) NSXLBEnabled() bool {
lbProviderMutex.Lock()
defer lbProviderMutex.Unlock()

if lbProvider == "" {
lbProvider = vpcService.getLBProvider()
lbProvider = s.getLBProvider()
}
return lbProvider == LBProviderNSX
}

func (vpcService *VPCService) getLBProvider() string {
func (s *VPCService) getLBProvider() string {
// if no Alb endpoint found, return nsx-lb
// if found, and nsx lbs found, return nsx-lb
// else return avi
if !vpcService.Service.NSXConfig.UseAVILoadBalancer {
if !s.Service.NSXConfig.UseAVILoadBalancer {
return LBProviderNSX
}
albEndpointFound := false
Expand All @@ -1038,26 +1038,26 @@ func (vpcService *VPCService) getLBProvider() string {
return false
}
}, func() error {
return GetAlbEndpoint(vpcService.Service.NSXClient.Cluster)
return GetAlbEndpoint(s.Service.NSXClient.Cluster)
}); err == nil {
albEndpointFound = true
}
if !albEndpointFound {
return LBProviderNSX
}
if len(vpcService.LbsStore.List()) > 0 {
if len(s.LbsStore.List()) > 0 {
return LBProviderNSX
}
return LBProviderAVI
}

func (service *VPCService) GetVPCFromNSXByPath(vpcPath string) (*model.Vpc, error) {
func (s *VPCService) GetVPCFromNSXByPath(vpcPath string) (*model.Vpc, error) {
vpcResInfo, err := common.ParseVPCResourcePath(vpcPath)
if err != nil {
log.Error(err, "failed to parse VPCResourceInfo from the given VPC path", "VPC", vpcPath)
return nil, err
}
vpc, err := service.NSXClient.VPCClient.Get(vpcResInfo.OrgID, vpcResInfo.ProjectID, vpcResInfo.VPCID)
vpc, err := s.NSXClient.VPCClient.Get(vpcResInfo.OrgID, vpcResInfo.ProjectID, vpcResInfo.VPCID)
err = nsxutil.NSXApiError(err)
if err != nil {
log.Error(err, "failed to read VPC object from NSX", "VPC", vpcPath)
Expand Down

0 comments on commit 92175f2

Please sign in to comment.