@@ -63,16 +63,20 @@ type NSXServiceAccountService struct {
6363 common.Service
6464 PrincipalIdentityStore * PrincipalIdentityStore
6565 ClusterControlPlaneStore * ClusterControlPlaneStore
66+ VPCService common.VPCServiceProvider
6667}
6768
6869// InitializeNSXServiceAccount sync NSX resources
69- func InitializeNSXServiceAccount (service common.Service ) (* NSXServiceAccountService , error ) {
70+ func InitializeNSXServiceAccount (service common.Service , vpcService common. VPCServiceProvider ) (* NSXServiceAccountService , error ) {
7071 wg := sync.WaitGroup {}
7172 wgDone := make (chan bool )
7273 fatalErrors := make (chan error )
7374
7475 wg .Add (2 )
75- nsxServiceAccountService := & NSXServiceAccountService {Service : service }
76+ nsxServiceAccountService := & NSXServiceAccountService {
77+ Service : service ,
78+ VPCService : vpcService ,
79+ }
7680
7781 nsxServiceAccountService .SetUpStore ()
7882 go nsxServiceAccountService .InitializeResourceStore (& wg , fatalErrors , common .ResourceTypePrincipalIdentity , nil , nsxServiceAccountService .PrincipalIdentityStore )
@@ -106,10 +110,17 @@ func (s *NSXServiceAccountService) SetUpStore() {
106110func (s * NSXServiceAccountService ) CreateOrUpdateNSXServiceAccount (ctx context.Context , obj * v1alpha1.NSXServiceAccount ) error {
107111 clusterName := s .getClusterName (obj .Namespace , obj .Name )
108112 normalizedClusterName := util .NormalizeId (clusterName )
109- // TODO: Use WCPConfig.NSXTProject as project when WCPConfig.EnableWCPVPCNetwork is true
110- project := s .NSXConfig .CoeConfig .Cluster
111- vpcName := obj .Namespace + "-default-vpc"
112- vpcPath := fmt .Sprintf ("/orgs/default/projects/%s/vpcs/%s" , util .NormalizeId (project ), vpcName )
113+ var vpcPath string
114+ if obj .Status .VPCPath != "" {
115+ vpcPath = obj .Status .VPCPath
116+ } else {
117+ vpcInfo := s .VPCService .ListVPCInfo (obj .Namespace )
118+ if len (vpcInfo ) > 0 {
119+ vpcPath = vpcInfo [0 ].GetVPCPath ()
120+ } else {
121+ return fmt .Errorf ("failed to listVPCInfo for namespace %s" , obj .Namespace )
122+ }
123+ }
113124
114125 // get proxy
115126 proxyEndpoints , err := s .getProxyEndpoints (ctx )
0 commit comments