Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions admiral/pkg/clusters/destinationrule_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,19 @@ func getDestinationRule(se *networkingV1Alpha3.ServiceEntry,
if isSEMultiRegion(se) {
dr.TrafficPolicy.LoadBalancer.LocalityLbSetting, err = getLocalityLBSettings(locality)
if err == nil {
ctxLogger.Infof(common.CtxLogFormat,
"doDRUpdateForInClusterRouting", "", "", "",
fmt.Sprintf("dr pinning successful for host %s", se.Hosts[0]))
return dr
} else {
ctxLogger.Errorf(common.CtxLogFormat,
"doDRUpdateForInClusterRouting", "", "", "",
fmt.Sprintf("error getting locality LB settings: %v", err))
}
} else {
ctxLogger.Infof(common.CtxLogFormat,
"doDRUpdateForInClusterRouting", "", "", "",
fmt.Sprintf("Skipping DR pinning as ServiceEntry is not multi-region for host: %s", se.Hosts[0]))
}
}

Expand Down
17 changes: 15 additions & 2 deletions admiral/pkg/clusters/serviceentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,10 @@ func IsCartographerVSDisabled(
// It returns true if the in-cluster virtual service exists
// and its exportTo does not contain the sync namespace, otherwise false.
// The VSName is constructed using the service entry host name
func hasInClusterVSWithValidExportToNS(se *networking.ServiceEntry, rc *RemoteController) (bool, error) {
func hasInClusterVSWithValidExportToNS(
ctxLogger *logrus.Entry,
se *networking.ServiceEntry,
rc *RemoteController) (bool, error) {
if rc == nil {
return false, fmt.Errorf("remoteController is nil")
}
Expand All @@ -1967,7 +1970,14 @@ func hasInClusterVSWithValidExportToNS(se *networking.ServiceEntry, rc *RemoteCo
if rc.VirtualServiceController.VirtualServiceCache == nil {
return false, fmt.Errorf("VirtualServiceCache is nil in VirtualServiceController")
}
vsName := fmt.Sprintf("%s-%s", se.Hosts[0], common.InclusterVSNameSuffix)
seHost := se.Hosts[0]
if strings.HasPrefix(seHost, canaryPrefix) {
seHost = strings.ReplaceAll(seHost, canaryPrefix+".", "")
}
if strings.HasPrefix(seHost, previewPrefix) {
seHost = strings.ReplaceAll(seHost, previewPrefix+".", "")
}
vsName := fmt.Sprintf("%s-%s", seHost, common.InclusterVSNameSuffix)
cachedVS := rc.VirtualServiceController.VirtualServiceCache.Get(vsName)
if cachedVS == nil {
return false, fmt.Errorf("virtualService %s not found in cache", vsName)
Expand All @@ -1977,6 +1987,9 @@ func hasInClusterVSWithValidExportToNS(se *networking.ServiceEntry, rc *RemoteCo
return false, nil
}
}
ctxLogger.Infof(common.CtxLogFormat, "hasInClusterVSWithValidExportToNS",
"", "", rc.ClusterID,
fmt.Sprintf("in-cluster VS %s has valid exportTo namespaces", vsName))
return true, nil
}

Expand Down
34 changes: 33 additions & 1 deletion admiral/pkg/clusters/serviceentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10334,6 +10334,36 @@ func TestHasInClusterVSWithValidExportToNS(t *testing.T) {
},
expected: true,
},
{
name: "Given an SE with canary host" +
"When hasInClusterVSWithValidExportToNS is called" +
"And the in-cluster VS has valid NS" +
"Then it should return true",
remoteCtrl: &RemoteController{
VirtualServiceController: &istio.VirtualServiceController{
VirtualServiceCache: virtualServiceCache,
},
},
serviceEntry: &istioNetworkingV1Alpha3.ServiceEntry{
Hosts: []string{"canary.foo.testns.global"},
},
expected: true,
},
{
name: "Given an SE with preview host" +
"When hasInClusterVSWithValidExportToNS is called" +
"And the in-cluster VS has valid NS" +
"Then it should return true",
remoteCtrl: &RemoteController{
VirtualServiceController: &istio.VirtualServiceController{
VirtualServiceCache: virtualServiceCache,
},
},
serviceEntry: &istioNetworkingV1Alpha3.ServiceEntry{
Hosts: []string{"preview.foo.testns.global"},
},
expected: true,
},
{
name: "Given an SE with valid hosts" +
"When hasInClusterVSWithValidExportToNS is called" +
Expand All @@ -10351,9 +10381,11 @@ func TestHasInClusterVSWithValidExportToNS(t *testing.T) {
},
}

var ctxLogger = logrus.WithFields(logrus.Fields{})

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result, err := hasInClusterVSWithValidExportToNS(tc.serviceEntry, tc.remoteCtrl)
result, err := hasInClusterVSWithValidExportToNS(ctxLogger, tc.serviceEntry, tc.remoteCtrl)
if tc.expectedError != nil {
assert.NotNil(t, err)
assert.Equal(t, tc.expectedError.Error(), err.Error())
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/clusters/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ func getSortedDependentNamespaces(
namespaceSlice = []string{"*"}
ctxLogger.Infof("exceeded max namespaces for cname=%s in cluster=%s", cname, clusterId)
}
sort.Strings(namespaceSlice)
}
}
sort.Strings(namespaceSlice)
// this is to avoid duplication in namespaceSlice e.g. dynamicrouting deployment present in istio-system can be a dependent of blackhole on blackhole's source cluster
var dedupNamespaceSlice []string
for i := 0; i < len(namespaceSlice); i++ {
Expand Down
29 changes: 20 additions & 9 deletions admiral/pkg/clusters/virtualservice_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,7 @@ func performDRPinning(ctx context.Context,
newDR := cachedDR.DeepCopy()

if newDR.Spec.TrafficPolicy == nil ||
newDR.Spec.TrafficPolicy.LoadBalancer == nil ||
newDR.Spec.TrafficPolicy.LoadBalancer.LocalityLbSetting == nil {
newDR.Spec.TrafficPolicy.LoadBalancer == nil {
errs = append(errs, fmt.Errorf(
"skipped pinning DR to remote region as TrafficPolicy or LoadBalancer or LocalityLbSetting is nil for DR %s in cluster %s",
drName, sourceCluster))
Expand Down Expand Up @@ -2442,14 +2441,15 @@ func adjustWeights(
return nil, fmt.Errorf("slice of HTTPRouteDestination is nil")
}
adjustedRDs := make([]*networkingV1Alpha3.HTTPRouteDestination, 0)
if len(routeDestinations) == 1 {
newRD := routeDestinations[0].DeepCopy()
newRD.Weight = weight
adjustedRDs = append(adjustedRDs, newRD)
return adjustedRDs, nil
}
for _, rd := range routeDestinations {
newRD := rd.DeepCopy()
if rd.Weight != 0 {
newRD.Weight = int32((float32(rd.Weight) / 100) * float32(weight))
adjustedRDs = append(adjustedRDs, newRD)
continue
}
newRD.Weight = weight
newRD.Weight = int32((float32(rd.Weight) / 100) * float32(weight))
adjustedRDs = append(adjustedRDs, newRD)
}
return adjustedRDs, nil
Expand Down Expand Up @@ -2528,6 +2528,9 @@ func DoVSRoutingInClusterForClusterAndIdentity(
ctxLogger.Infof(common.CtxLogFormat, "DoVSRoutingInClusterForClusterAndIdentity",
identity, "", cluster, "identity has a custom VS in its namespace")
return false
} else {
ctxLogger.Infof(common.CtxLogFormat, "DoVSRoutingInClusterForClusterAndIdentity",
identity, "", cluster, "identity does not have a custom VS in its namespace")
}

// This should be set to true if we need to check if .mesh DR should be pinned to remote
Expand All @@ -2552,6 +2555,9 @@ func DoVSRoutingInClusterForClusterAndIdentity(
ctxLogger.Infof(common.CtxLogFormat, "DoVSRoutingInClusterForClusterAndIdentity",
identity, "", cluster, fmt.Sprintf("isCartographerVSDisabled=%v", isCartographerVSDisabled))
return false
} else {
ctxLogger.Infof(common.CtxLogFormat, "DoVSRoutingInClusterForClusterAndIdentity",
identity, "", cluster, fmt.Sprintf("isCartographerVSDisabled=%v", isCartographerVSDisabled))
}
}

Expand Down Expand Up @@ -2596,7 +2602,8 @@ func DoDRUpdateForInClusterVSRouting(
}
if isSourceCluster {
// Check if the incluster VS has valid exportTo namespaces (not sync namespace)
hasValidInClusterVS, err := hasInClusterVSWithValidExportToNS(se, remoteRegistry.GetRemoteController(cluster))
hasValidInClusterVS, err := hasInClusterVSWithValidExportToNS(
ctxLogger, se, remoteRegistry.GetRemoteController(cluster))
if err != nil {
ctxLogger.Warnf(common.CtxLogFormat, "DoDRUpdateForInClusterVSRouting",
identity, "", cluster, fmt.Sprintf("error checking for valid in-cluster VS %v", err))
Expand All @@ -2606,6 +2613,10 @@ func DoDRUpdateForInClusterVSRouting(
ctxLogger.Infof(common.CtxLogFormat, "DoDRUpdateForInClusterVSRouting",
identity, "", cluster, "skipping DR update as incluter VS does not have valid exportTo namespaces")
return false
} else {
ctxLogger.Infof(common.CtxLogFormat, "DoDRUpdateForInClusterVSRouting",
identity, "", cluster,
fmt.Sprintf("in-cluster VS has valid exportTo namespaces for identity %s and env %s", identity, env))
}
if DoVSRoutingInClusterForClusterAndIdentity(
ctx, ctxLogger, env, cluster, identity, remoteRegistry, performCartographerVSCheck) {
Expand Down
Loading