snowdrop / istio-java-api

A Java API to generate Istio descriptors, inspired by Fabric8's kubernetes-model.
Apache License 2.0
112 stars 33 forks source link

Lookup on http route in Virtualservice yaml is not working #68

Closed naitikdani closed 5 years ago

naitikdani commented 5 years ago

Hello @metacosm ,

I have this yaml file:

spec:
  gateways:
  - logforwarding-gateway
  hosts:
  - '*'
  http:
  - match:
    - uri:
        exact: /onboard
    route:
    - destination:
        host: provision-service
        port:
          number: 9080
  - match:
    - headers:
        tenantid:
          exact: "coke"
    route:
    - destination:
        host: service-coke
        port:
          number: 8080

I want to do a lookup on http route with route/destination/host as service-coke and port 8080.

I wrote this code and it returned false:

Destination dst = new DestinationBuilder()
                    .withHost("service-coke")
                    .withPort(new PortSelector(new NumberPort(8080))).build();

            HTTPRouteDestination routeDst = new HTTPRouteDestinationBuilder()
                    .withDestination(dst).build();
            HTTPRoute route = new HTTPRouteBuilder().withRoute(routeDst).build();

boolean entryFound = istioClient.virtualService().inNamespace(istioClient.getNamespace())
                    .withName("logforwarding-virtualservice")
                    .get().getSpec().getHttp().contains(route);

I got entryFound as false. Is this the right way to do a lookup for http route? Thanks in advance

metacosm commented 5 years ago

Hi @naitikdani,

You're trying to perform a partial match (i.e. the route you're trying to match against doesn't contain the match element that the route you created via YAML contains), which is not how List.contains works: this will only return true if the exact object exists in the list.

What you want to do instead is something like: http.stream().anyMatch(r -> r.getRoute().stream().anyMatch(d -> d.getDestination().equals(dst))).