Repository: vmware-tanzu/tanzu-framework (language: go)

Issue:
Tanzu validation failed when there are duplicated NSX ALB resource names in different NSX ALB clouds
**Bug description**

When configuring NSX ALB with multiple clouds and creating the **same type and same name** AVI resources in the different clouds, then creating mgmt cluster to connect to the NSX ALB mentioned above, it will fail on the validation stage and throw out the following error:

```bash
More than one object of type serviceenginegroup with name Default-Group is found
```

**Affected product area (please put an X in all that apply)**

- ( ) APIs
- ( ) Addons
- (x) CLI
- ( ) Docs
- ( ) IAM
- ( ) Installation
- ( ) Plugin
- ( ) Security
- ( ) Test and Release
- ( ) User Experience
- ( ) Developer Experience

**Expected behavior**

The validation should pass even if I have AVI resources with duplicated name as long as those resources are not in the same cloud.

**Steps to reproduce the bug**

1. create multiple clouds in NSX ALB controller
2. create SEG or network in different clouds with same name
3. create a management cluster and configure it to connect to this NSX ALB controller.
4. tanzu cli throw following error:

```bash
More than one object of type serviceenginegroup with name Default-Group is found
```


**Version** (include the SHA if the version is not obvious)

v0.25.0

**Environment where the bug was observed (cloud, OS, etc)**

- vSphere

**Relevant Debug Output (Logs, manifests, etc)**



Discussion / hints:

Fix patch:
diff --git a/tkg/client/validate.go b/tkg/client/validate.go
index 38d8453e32..b8613819a3 100644
--- a/tkg/client/validate.go
+++ b/tkg/client/validate.go
@@ -1966,7 +1966,7 @@ func (c *TkgClient) ValidateAviServiceEngineGroup(aviClient avi.Client) error {
 	if err != nil {
 		return err
 	}
-	if _, err = aviClient.GetServiceEngineGroupByName(aviServiceEngineGroup); err != nil {
+	if _, err = aviClient.GetServiceEngineGroupByName(aviServiceEngineGroup); err != nil && !isAviResourceDuplicatedNameError(err) {
 		return err
 	}
 	return nil
@@ -1977,7 +1977,7 @@ func (c *TkgClient) ValidateAviManagementClusterServiceEngineGroup(aviClient avi
 	aviManagementClusterSEG, _ := c.TKGConfigReaderWriter().Get(constants.ConfigVariableAviManagementClusterServiceEngineGroup)
 	// this field is optional, only validates if it has value
 	if aviManagementClusterSEG != "" {
-		if _, err := aviClient.GetServiceEngineGroupByName(aviManagementClusterSEG); err != nil {
+		if _, err := aviClient.GetServiceEngineGroupByName(aviManagementClusterSEG); err != nil && !isAviResourceDuplicatedNameError(err) {
 			return err
 		}
 	}
@@ -2042,7 +2042,7 @@ func (c *TkgClient) ValidateAviManagementClusterControlPlaneNetwork(aviClient av
 // ValidateAviNetwork validates if the network can be found in AVI controller or not and the subnet CIDR format is correct or not
 func (c *TkgClient) ValidateAviNetwork(networkName, networkCIDR string, aviClient avi.Client) error {
 	_, err := aviClient.GetVipNetworkByName(networkName)
-	if err != nil {
+	if err != nil && !isAviResourceDuplicatedNameError(err) {
 		return err
 	}
 	_, _, err = net.ParseCIDR(networkCIDR)
@@ -2122,6 +2122,10 @@ func (c *TkgClient) checkIPFamilyFeatureFlags(ipFamily, clusterRole string) erro
 	return nil
 }
 
+func isAviResourceDuplicatedNameError(err error) bool {
+	return strings.Contains(err.Error(), "More than one object of type ")
+}
+
 func dualStackFeatureFlagError(ipFamily, featureFlag string) error {
 	return fmt.Errorf("option TKG_IP_FAMILY is set to %q, but dualstack support is not enabled (because it is under development). To enable dualstack, set %s to \"true\"", ipFamily, featureFlag)
 }


Test patch: