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

Istio: add gateway-virtualservice link #1674

Merged
merged 1 commit into from
Mar 5, 2019
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
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