@@ -104,12 +104,7 @@ func (s *NSXServiceAccountService) SetUpStore() {
104104}
105105
106106func (s * NSXServiceAccountService ) CreateOrUpdateNSXServiceAccount (ctx context.Context , obj * v1alpha1.NSXServiceAccount ) error {
107- var clusterName string
108- if obj .Status .ClusterName != "" {
109- clusterName = obj .Status .ClusterName
110- } else {
111- clusterName = s .getClusterName (obj .Namespace , obj .Name )
112- }
107+ clusterName := s .getClusterName (obj )
113108 normalizedClusterName := util .NormalizeId (clusterName )
114109 // TODO: Use WCPConfig.NSXTProject as project when WCPConfig.EnableWCPVPCNetwork is true
115110 project := s .NSXConfig .CoeConfig .Cluster
@@ -350,12 +345,7 @@ func (s *NSXServiceAccountService) DeleteNSXServiceAccount(ctx context.Context,
350345 isDeleteSecret = true
351346 }
352347
353- var clusterName string
354- if nsxsa .Status .ClusterName != "" {
355- clusterName = nsxsa .Status .ClusterName
356- } else {
357- clusterName = s .getClusterName (namespacedName .Namespace , namespacedName .Name )
358- }
348+ clusterName := s .getClusterName (nsxsa )
359349 normalizedClusterName := util .NormalizeId (clusterName )
360350 // delete Secret
361351 if isDeleteSecret {
@@ -410,7 +400,7 @@ func (s *NSXServiceAccountService) DeleteNSXServiceAccount(ctx context.Context,
410400func (s * NSXServiceAccountService ) ValidateAndUpdateRealizedNSXServiceAccount (ctx context.Context , obj * v1alpha1.NSXServiceAccount , ca []byte ,
411401 nsxRestoreStatus * v1alpha1.NSXRestoreStatus ) error {
412402
413- clusterName := obj . Status . ClusterName
403+ clusterName := s . getClusterName ( obj )
414404 normalizedClusterName := util .NormalizeId (clusterName )
415405 secretName := obj .Name + SecretSuffix
416406 secretNamespace := obj .Namespace
@@ -604,8 +594,11 @@ func (s *NSXServiceAccountService) GetNSXServiceAccountNameByUID(uid string) (na
604594 return
605595}
606596
607- func (s * NSXServiceAccountService ) getClusterName (namespace , name string ) string {
608- return fmt .Sprintf ("%s_%s_%s" , s .NSXConfig .CoeConfig .Cluster , namespace , name )
597+ func (s * NSXServiceAccountService ) getClusterName (obj * v1alpha1.NSXServiceAccount ) string {
598+ if obj .Status .ClusterName != "" {
599+ return obj .Status .ClusterName
600+ }
601+ return fmt .Sprintf ("%s_%s_%s" , s .NSXConfig .CoeConfig .Cluster , obj .Namespace , obj .Name )
609602}
610603
611604func GenerateNSXServiceAccountConditions (existingConditions []metav1.Condition , generation int64 , realizedStatus metav1.ConditionStatus , realizedReason string , message string ) []metav1.Condition {
0 commit comments