Skip to content

Commit

Permalink
Fix GTP sorting and matching (#213)
Browse files Browse the repository at this point in the history
* Fix gtp matching typo

* Fix to sort GTPs and add logs
  • Loading branch information
aattuluri committed May 5, 2022
1 parent f3f8571 commit cdb13f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion admiral/pkg/clusters/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func handleDestinationRuleEvent(obj *v1alpha3.DestinationRule, dh *DestinationRu

basicSEName := getIstioResourceName(host, "-se")

seName := getIstioResourceName(obj.Name, "-se")
seName := getIstioResourceName(host, "-se")

allDependentClusters := make(map[string]string)

Expand Down
16 changes: 12 additions & 4 deletions admiral/pkg/clusters/serviceentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ func modifyServiceEntryForNewServiceOrPod(event admiral.EventType, env string, s
}

gtpsInNamespace := rc.GlobalTraffic.Cache.Get(gtpKey, namespace)
if len(gtps) > 0 {
if len(gtpsInNamespace) > 0 {
if log.IsLevelEnabled(log.DebugLevel) {
log.Debugf("GTPs found for identity=%s in env=%s namespace=%s gtp=%v", sourceIdentity, env, namespace, gtps)
}
gtps[rc.ClusterID] = gtpsInNamespace
} else {
log.Debugf("No GTPs found for identity=%s in env=%s namespace=%s with key=%s", sourceIdentity, env, namespace, gtpKey)
}

remoteRegistry.AdmiralCache.IdentityClusterCache.Put(sourceIdentity, rc.ClusterID, rc.ClusterID)
Expand Down Expand Up @@ -239,14 +244,17 @@ func updateGlobalGtpCache(cache *AdmiralCache, identity, env string, gtps map[st
gtpsOrdered = append(gtpsOrdered, gtpsInCluster...)
}
if len(gtpsOrdered) == 0 {
log.Debugf("No GTPs found for identity=%s in env=%s. Deleting global cache entries if any", identity, env)
cache.GlobalTrafficCache.Delete(env, identity)
return
} else if len(gtpsOrdered) > 1 {
log.Debugf("More than one GTP found for identity=%s in env=%s.", identity, env)
//sort by creation time with most recent at the beginning
sort.Slice(gtpsOrdered, func(i, j int) bool {
iTime := gtpsOrdered[i].CreationTimestamp.Nanosecond()
jTime := gtpsOrdered[j].CreationTimestamp.Nanosecond()
return iTime > jTime
iTime := gtpsOrdered[i].CreationTimestamp
jTime := gtpsOrdered[j].CreationTimestamp
log.Debugf("GTP sorting identity=%s env=%s name1=%s creationTime1=%v name2=%s creationTime2=%v", identity, env, gtpsOrdered[i].Name, iTime, gtpsOrdered[j].Name, jTime)
return iTime.After(jTime.Time)
})
}

Expand Down
3 changes: 3 additions & 0 deletions admiral/pkg/controller/admiral/globaltraffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func (p *gtpCache) Put(obj *v1.GlobalTrafficPolicy) {

namespacesWithGtps[obj.Namespace] = namespaceGtps
p.cache[key] = namespacesWithGtps
if logrus.IsLevelEnabled(logrus.DebugLevel) {
logrus.Debugf("GTP cache for key=%s gtp=%v", key, namespacesWithGtps)
}
}

func (p *gtpCache) Delete(obj *v1.GlobalTrafficPolicy) {
Expand Down

0 comments on commit cdb13f5

Please sign in to comment.