@@ -539,7 +539,8 @@ func generateVirtualServiceForIncluster(
539539 virtualService .Spec .ExportTo = []string {common .GetSyncNamespace ()}
540540 vsRoutingInclusterEnabledForClusterAndIdentity := false
541541 if common .EnableExportTo (vsName ) &&
542- DoVSRoutingInClusterForClusterAndIdentity (ctx , ctxLogger , env , sourceCluster , sourceIdentity , remoteRegistry ) {
542+ DoVSRoutingInClusterForClusterAndIdentity (
543+ ctx , ctxLogger , env , sourceCluster , sourceIdentity , remoteRegistry , false ) {
543544 vsRoutingInclusterEnabledForClusterAndIdentity = true
544545 virtualService .Spec .ExportTo = getSortedDependentNamespaces (
545546 remoteRegistry .AdmiralCache , vsName , sourceCluster , ctxLogger , true )
@@ -847,7 +848,10 @@ func shouldPerformDRPinning(
847848 return false
848849 }
849850
850- if ! DoVSRoutingInClusterForClusterAndIdentity (ctx , ctxLogger , env , sourceCluster , sourceIdentity , remoteRegistry ) {
851+ // performCartographerVSCheck param is set to true since it is needed to make a decision
852+ // if DR pinning should be performed
853+ if ! DoVSRoutingInClusterForClusterAndIdentity (
854+ ctx , ctxLogger , env , sourceCluster , sourceIdentity , remoteRegistry , true ) {
851855 ctxLogger .Infof (common .CtxLogFormat , "shouldPerformDRPinning" ,
852856 vsName , common .NamespaceIstioSystem , sourceCluster ,
853857 fmt .Sprintf ("DoVSRoutingInClusterForClusterAndIdentity=false for cluster %s and identity %s" , sourceCluster , sourceIdentity ))
@@ -1742,26 +1746,27 @@ func addUpdateInClusterDestinationRule(
17421746 }
17431747
17441748 for sourceCluster , drHosts := range sourceClusterToDRHosts {
1745- if ! DoVSRoutingInClusterForClusterAndIdentity (ctx , ctxLogger , env , sourceCluster , sourceIdentity , remoteRegistry ) {
1746- ctxLogger .Infof (common .CtxLogFormat , "VSBasedRoutingInCluster" ,
1747- "" , "" , sourceCluster ,
1748- fmt .Sprintf ("Writing phase: addUpdateInClusterDestinationRule: VS based routing in-cluster disabled for cluster %s and identity %s" , sourceCluster , sourceIdentity ))
1749- continue
1750- }
1751-
1752- ctxLogger .Info (common .CtxLogFormat , "VSBasedRoutingInCluster" ,
1753- "" , "" , sourceCluster ,
1754- fmt .Sprintf ("Writing phase: addUpdateInClusterDestinationRule: VS based routing in-cluster enabled for cluster %s and identity %s" , sourceCluster , sourceIdentity ))
1755-
17561749 san := fmt .Sprintf ("%s%s/%s" , common .SpiffePrefix , common .GetSANPrefix (), sourceIdentity )
17571750
17581751 clientTLSSettings := & networkingV1Alpha3.ClientTLSSettings {
17591752 Mode : networkingV1Alpha3 .ClientTLSSettings_ISTIO_MUTUAL ,
17601753 SubjectAltNames : []string {san },
17611754 }
17621755
1763- exportToNamespaces := getSortedDependentNamespaces (
1764- remoteRegistry .AdmiralCache , cname , sourceCluster , ctxLogger , true )
1756+ exportToNamespaces := []string {common .GetSyncNamespace ()}
1757+ if common .EnableExportTo (cname ) &&
1758+ DoVSRoutingInClusterForClusterAndIdentity (
1759+ ctx , ctxLogger , env , sourceCluster , sourceIdentity , remoteRegistry , false ) {
1760+ exportToNamespaces = getSortedDependentNamespaces (
1761+ remoteRegistry .AdmiralCache , cname , sourceCluster , ctxLogger , true )
1762+ ctxLogger .Info (common .CtxLogFormat , "VSBasedRoutingInCluster" ,
1763+ "" , "" , sourceCluster ,
1764+ fmt .Sprintf ("Writing phase: addUpdateInClusterDestinationRule: VS based routing in-cluster enabled for cluster %s and identity %s" , sourceCluster , sourceIdentity ))
1765+ } else {
1766+ ctxLogger .Infof (common .CtxLogFormat , "VSBasedRoutingInCluster" ,
1767+ "" , "" , sourceCluster ,
1768+ fmt .Sprintf ("Writing phase: addUpdateInClusterDestinationRule: VS based routing in-cluster disabled for cluster %s and identity %s" , sourceCluster , sourceIdentity ))
1769+ }
17651770
17661771 err := addUpdateRoutingDestinationRule (
17671772 ctx , ctxLogger , remoteRegistry , drHosts , sourceCluster ,
@@ -2331,13 +2336,16 @@ func mergeHosts(hosts1 []string, hosts2 []string) []string {
23312336// or for a specific cluster and identity.
23322337// It also checks if there is a custom Virtual Service in the identity's namespace
23332338// and if the Cartographer Virtual Service is disabled for the given cluster and identity.
2339+ // performCartographerVSCheck is a flag to indicate whether to perform the Cartographer VS check as this check
2340+ // is only needed to verify if .mesh DR pinning should be performed.
23342341func DoVSRoutingInClusterForClusterAndIdentity (
23352342 ctx context.Context ,
23362343 ctxLogger * log.Entry ,
23372344 env ,
23382345 cluster ,
23392346 identity string ,
2340- remoteRegistry * RemoteRegistry ) bool {
2347+ remoteRegistry * RemoteRegistry ,
2348+ performCartographerVSCheck bool ) bool {
23412349
23422350 // Check if the feature is enabled globally
23432351 if ! common .GetEnableVSRoutingInCluster () {
@@ -2380,24 +2388,29 @@ func DoVSRoutingInClusterForClusterAndIdentity(
23802388 return false
23812389 }
23822390
2383- // Check if the Cartographer Virtual Service is disabled
2384- // We will disable this feature if the Cartographer VS does not have dot in exportTo
2385- rc := remoteRegistry .GetRemoteController (cluster )
2386- if rc == nil {
2387- ctxLogger .Warnf (common .CtxLogFormat , "DoVSRoutingInClusterForClusterAndIdentity" ,
2388- identity , "" , cluster , "remote controller is nil" )
2389- return false
2390- }
2391- isCartographerVSDisabled , err := IsCartographerVSDisabled (ctx , ctxLogger , rc , env , identity , getCustomVirtualService )
2392- if err != nil {
2393- ctxLogger .Warnf (common .CtxLogFormat , "DoVSRoutingInClusterForClusterAndIdentity" ,
2394- identity , "" , cluster , fmt .Sprintf ("failed IsCartographerVSDisabled check due to error %v" , err ))
2395- return false
2396- }
2397- if ! isCartographerVSDisabled {
2398- ctxLogger .Infof (common .CtxLogFormat , "DoVSRoutingInClusterForClusterAndIdentity" ,
2399- identity , "" , cluster , fmt .Sprintf ("isCartographerVSDisabled=%v" , isCartographerVSDisabled ))
2400- return false
2391+ // This should be set to true if we need to check if .mesh DR should be pinned to remote
2392+ // region or not. For the DR to be pinned, the cartographer VS should have exportTo set to
2393+ // dot
2394+ if performCartographerVSCheck {
2395+ // Check if the Cartographer Virtual Service is disabled
2396+ // We will disable this feature if the Cartographer VS does not have dot in exportTo
2397+ rc := remoteRegistry .GetRemoteController (cluster )
2398+ if rc == nil {
2399+ ctxLogger .Warnf (common .CtxLogFormat , "DoVSRoutingInClusterForClusterAndIdentity" ,
2400+ identity , "" , cluster , "remote controller is nil" )
2401+ return false
2402+ }
2403+ isCartographerVSDisabled , err := IsCartographerVSDisabled (ctx , ctxLogger , rc , env , identity , getCustomVirtualService )
2404+ if err != nil {
2405+ ctxLogger .Warnf (common .CtxLogFormat , "DoVSRoutingInClusterForClusterAndIdentity" ,
2406+ identity , "" , cluster , fmt .Sprintf ("failed IsCartographerVSDisabled check due to error %v" , err ))
2407+ return false
2408+ }
2409+ if ! isCartographerVSDisabled {
2410+ ctxLogger .Infof (common .CtxLogFormat , "DoVSRoutingInClusterForClusterAndIdentity" ,
2411+ identity , "" , cluster , fmt .Sprintf ("isCartographerVSDisabled=%v" , isCartographerVSDisabled ))
2412+ return false
2413+ }
24012414 }
24022415
24032416 return true
@@ -2431,7 +2444,8 @@ func DoDRUpdateForInClusterVSRouting(
24312444 identity string ,
24322445 isSourceCluster bool ,
24332446 remoteRegistry * RemoteRegistry ,
2434- se * networkingV1Alpha3.ServiceEntry ) bool {
2447+ se * networkingV1Alpha3.ServiceEntry ,
2448+ performCartographerVSCheck bool ) bool {
24352449
24362450 if remoteRegistry == nil {
24372451 ctxLogger .Warnf (common .CtxLogFormat , "DoDRUpdateForInClusterVSRouting" ,
@@ -2451,7 +2465,7 @@ func DoDRUpdateForInClusterVSRouting(
24512465 return false
24522466 }
24532467 if isSourceCluster &&
2454- DoVSRoutingInClusterForClusterAndIdentity (ctx , ctxLogger , env , cluster , identity , remoteRegistry ) {
2468+ DoVSRoutingInClusterForClusterAndIdentity (ctx , ctxLogger , env , cluster , identity , remoteRegistry , performCartographerVSCheck ) {
24552469 return true
24562470 }
24572471 return false
0 commit comments