Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gtp matching typo #213

Merged
merged 2 commits into from
May 5, 2022
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
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