Skip to content

Commit

Permalink
Merge pull request #1674 from tomerlange/istio-gateway
Browse files Browse the repository at this point in the history
Istio: add gateway-virtualservice link
  • Loading branch information
hunchback authored Mar 5, 2019
2 parents c0dfd6e + 1069b41 commit 6830dcb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/istio/gateway-virtualservice.yaml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions tests/istio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 19 additions & 0 deletions topology/probes/istio/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
1 change: 1 addition & 0 deletions topology/probes/istio/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func NewIstioProbe(g *graph.Graph) (*k8s.Probe, error) {
linkerHandlers := []k8s.LinkHandler{
newVirtualServicePodLinker,
newDestinationRuleServiceLinker,
newGatewayVirtualServiceLinker,
}

linkers := k8s.InitLinkers(linkerHandlers, g)
Expand Down

0 comments on commit 6830dcb

Please sign in to comment.