diff --git a/tests/istio/gateway-virtualservice.yaml b/tests/istio/gateway-virtualservice.yaml new file mode 100644 index 0000000000..12202b6527 --- /dev/null +++ b/tests/istio/gateway-virtualservice.yaml @@ -0,0 +1,29 @@ +apiVersion: networking.istio.io/v1alpha3 +kind: Gateway +metadata: + name: skydive-test-gateway-virtualservice +spec: + selector: + istio: ingressgateway + servers: + - port: + number: 80 + name: http + protocol: HTTP + hosts: + - "*" +--- +apiVersion: networking.istio.io/v1alpha3 +kind: VirtualService +metadata: + name: skydive-test-gateway-virtualservice +spec: + hosts: + - reviews.prod.svc.cluster.local + gateways: + - skydive-test-gateway-virtualservice + http: + - route: + - destination: + host: reviews.prod.svc.cluster.local + subset: v1 diff --git a/tests/istio_test.go b/tests/istio_test.go index 413a63a6fb..d4605387e0 100644 --- a/tests/istio_test.go +++ b/tests/istio_test.go @@ -104,6 +104,32 @@ func TestIstioDestinationRuleServiceScenario(t *testing.T) { ) } +func TestIstioGatewayVirtualServiceScenario(t *testing.T) { + file := "gateway-virtualservice" + name := objName + "-" + file + testRunner( + t, + setupFromConfigFile(istio.Manager, file), + tearDownFromConfigFile(istio.Manager, file), + []CheckFunction{ + func(c *CheckContext) error { + gateway, err := checkNodeCreation(t, c, istio.Manager, "gateway", name) + if err != nil { + return err + } + virtualservice, err := checkNodeCreation(t, c, istio.Manager, "virtualservice", name) + if err != nil { + return err + } + if err = checkEdge(t, c, gateway, virtualservice, "gateway"); err != nil { + return err + } + return nil + }, + }, + ) +} + func TestBookInfoScenario(t *testing.T) { bookinfo := "WITH_ISTIO=true ./bookinfo/bookinfo.sh" testRunner( diff --git a/topology/probes/istio/gateway.go b/topology/probes/istio/gateway.go index ee9309e13a..285e946f6d 100644 --- a/topology/probes/istio/gateway.go +++ b/topology/probes/istio/gateway.go @@ -22,6 +22,7 @@ import ( kiali "github.com/kiali/kiali/kubernetes" "github.com/skydive-project/skydive/graffiti/graph" + "github.com/skydive-project/skydive/probe" "github.com/skydive-project/skydive/topology/probes/k8s" ) @@ -44,3 +45,21 @@ func (h *gatewayHandler) Dump(obj interface{}) string { func newGatewayProbe(client interface{}, g *graph.Graph) k8s.Subprobe { return k8s.NewResourceCache(client.(*kiali.IstioClient).GetIstioNetworkingApi(), &kiali.Gateway{}, "gateways", g, &gatewayHandler{}) } + +func gatewayVirtualServiceAreLinked(a, b interface{}) bool { + gateway := a.(*kiali.Gateway) + vs := b.(*kiali.VirtualService) + if gateways, ok := vs.Spec["gateways"]; ok { + gatewaysList := gateways.([]interface{}) + for _, g := range gatewaysList { + if g.(string) == gateway.Name { + return true + } + } + } + return false +} + +func newGatewayVirtualServiceLinker(g *graph.Graph) probe.Probe { + return k8s.NewABLinker(g, Manager, "gateway", Manager, "virtualservice", gatewayVirtualServiceAreLinked) +} diff --git a/topology/probes/istio/istio.go b/topology/probes/istio/istio.go index 0114bd49b8..da195c1a22 100644 --- a/topology/probes/istio/istio.go +++ b/topology/probes/istio/istio.go @@ -61,6 +61,7 @@ func NewIstioProbe(g *graph.Graph) (*k8s.Probe, error) { linkerHandlers := []k8s.LinkHandler{ newVirtualServicePodLinker, newDestinationRuleServiceLinker, + newGatewayVirtualServiceLinker, } linkers := k8s.InitLinkers(linkerHandlers, g)