@@ -104,7 +104,7 @@ func (s *NSXServiceAccountService) SetUpStore() {
104104}
105105
106106func (s * NSXServiceAccountService ) CreateOrUpdateNSXServiceAccount (ctx context.Context , obj * v1alpha1.NSXServiceAccount ) error {
107- clusterName := s .getClusterName (obj .Namespace , obj .Name )
107+ clusterName := s .getClusterName (obj .Status . ClusterName , obj . Namespace , obj .Name )
108108 normalizedClusterName := util .NormalizeId (clusterName )
109109 // TODO: Use WCPConfig.NSXTProject as project when WCPConfig.EnableWCPVPCNetwork is true
110110 project := s .NSXConfig .CoeConfig .Cluster
@@ -345,7 +345,7 @@ func (s *NSXServiceAccountService) DeleteNSXServiceAccount(ctx context.Context,
345345 isDeleteSecret = true
346346 }
347347
348- clusterName := s .getClusterName (namespacedName .Namespace , namespacedName .Name )
348+ clusterName := s .getClusterName (nsxsa . Status . ClusterName , namespacedName .Namespace , namespacedName .Name )
349349 normalizedClusterName := util .NormalizeId (clusterName )
350350 // delete Secret
351351 if isDeleteSecret {
@@ -400,7 +400,7 @@ func (s *NSXServiceAccountService) DeleteNSXServiceAccount(ctx context.Context,
400400func (s * NSXServiceAccountService ) ValidateAndUpdateRealizedNSXServiceAccount (ctx context.Context , obj * v1alpha1.NSXServiceAccount , ca []byte ,
401401 nsxRestoreStatus * v1alpha1.NSXRestoreStatus ) error {
402402
403- clusterName := s .getClusterName (obj .Namespace , obj .Name )
403+ clusterName := s .getClusterName (obj .Status . ClusterName , obj . Namespace , obj .Name )
404404 normalizedClusterName := util .NormalizeId (clusterName )
405405 secretName := obj .Name + SecretSuffix
406406 secretNamespace := obj .Namespace
@@ -594,8 +594,11 @@ func (s *NSXServiceAccountService) GetNSXServiceAccountNameByUID(uid string) (na
594594 return
595595}
596596
597- func (s * NSXServiceAccountService ) getClusterName (namespace , name string ) string {
598- return fmt .Sprintf ("%s-%s-%s" , s .NSXConfig .CoeConfig .Cluster , namespace , name )
597+ func (s * NSXServiceAccountService ) getClusterName (clusterName , namespace , name string ) string {
598+ if clusterName != "" {
599+ return clusterName
600+ }
601+ return fmt .Sprintf ("%s_%s_%s" , s .NSXConfig .CoeConfig .Cluster , namespace , name )
599602}
600603
601604func GenerateNSXServiceAccountConditions (existingConditions []metav1.Condition , generation int64 , realizedStatus metav1.ConditionStatus , realizedReason string , message string ) []metav1.Condition {
0 commit comments