diff --git a/admiral/pkg/clusters/handler.go b/admiral/pkg/clusters/handler.go index 454235c6..cd8a5786 100644 --- a/admiral/pkg/clusters/handler.go +++ b/admiral/pkg/clusters/handler.go @@ -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) diff --git a/admiral/pkg/clusters/serviceentry.go b/admiral/pkg/clusters/serviceentry.go index 2a07cad3..7e29849c 100644 --- a/admiral/pkg/clusters/serviceentry.go +++ b/admiral/pkg/clusters/serviceentry.go @@ -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) @@ -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) }) } diff --git a/admiral/pkg/controller/admiral/globaltraffic.go b/admiral/pkg/controller/admiral/globaltraffic.go index 61760266..d7c88d0a 100644 --- a/admiral/pkg/controller/admiral/globaltraffic.go +++ b/admiral/pkg/controller/admiral/globaltraffic.go @@ -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) {