1 Star 0 Fork 2

yanyue / cloudbases.io.kiali

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
service_entry.go 2.85 KB
一键复制 编辑 原始数据 按行查看 历史
Hubery1003 提交于 2021-12-16 10:12 . first commit
package appender
import (
"time"
"github.com/kiali/kiali/business"
"github.com/kiali/kiali/graph"
"github.com/kiali/kiali/log"
)
const ServiceEntryAppenderName = "serviceEntry"
// ServiceEntryAppender is responsible for identifying service nodes that are
// Istio Service Entries.
// Name: serviceEntry
type ServiceEntryAppender struct {
AccessibleNamespaces map[string]time.Time
}
// Name implements Appender
func (a ServiceEntryAppender) Name() string {
return ServiceEntryAppenderName
}
// AppendGraph implements Appender
func (a ServiceEntryAppender) AppendGraph(trafficMap graph.TrafficMap, globalInfo *GlobalInfo, namespaceInfo *NamespaceInfo) {
if len(trafficMap) == 0 {
return
}
var err error
if globalInfo.Business == nil {
globalInfo.Business, err = business.Get()
graph.CheckError(err)
}
a.applyServiceEntries(trafficMap, globalInfo, namespaceInfo)
}
func (a ServiceEntryAppender) applyServiceEntries(trafficMap graph.TrafficMap, globalInfo *GlobalInfo, namespaceInfo *NamespaceInfo) {
for _, n := range trafficMap {
// only a service node can be a service entry
if n.NodeType != graph.NodeTypeService {
continue
}
// only a terminal node can be a service entry (no outgoing edges because the service is performed outside the mesh)
if len(n.Edges) > 0 {
continue
}
// A service node with no outgoing edges may be an egress.
// If so flag it, don't discard it (kiali-1526, see also kiali-2014).
// The flag will be passed to the UI to inhibit links to non-existent detail pages.
if location, ok := a.getServiceEntry(n.Service, globalInfo); ok {
n.Metadata["isServiceEntry"] = location
}
}
}
// getServiceEntry queries the cluster API to resolve service entries
// across all accessible namespaces in the cluster. All ServiceEntries are needed because
// Istio does not distinguish where a ServiceEntry is created when routing traffic (i.e.
// a ServiceEntry can be in any namespace and it will still work).
func (a ServiceEntryAppender) getServiceEntry(service string, globalInfo *GlobalInfo) (string, bool) {
if globalInfo.ServiceEntries == nil {
globalInfo.ServiceEntries = make(map[string]string)
for ns := range a.AccessibleNamespaces {
istioCfg, err := globalInfo.Business.IstioConfig.GetIstioConfigList(business.IstioConfigCriteria{
IncludeServiceEntries: true,
Namespace: ns,
})
graph.CheckError(err)
for _, entry := range istioCfg.ServiceEntries {
if entry.Spec.Hosts != nil {
location := "MESH_EXTERNAL"
if entry.Spec.Location == "MESH_INTERNAL" {
location = "MESH_INTERNAL"
}
for _, host := range entry.Spec.Hosts.([]interface{}) {
globalInfo.ServiceEntries[host.(string)] = location
}
}
}
}
log.Tracef("Found [%v] service entries", len(globalInfo.ServiceEntries))
}
location, ok := globalInfo.ServiceEntries[service]
return location, ok
}
1
https://gitee.com/programmer-zpz/cloudbases.io.kiali.git
git@gitee.com:programmer-zpz/cloudbases.io.kiali.git
programmer-zpz
cloudbases.io.kiali
cloudbases.io.kiali
v0.15.1

搜索帮助

53164aa7 5694891 3bd8fe86 5694891