Closed naitikdani closed 5 years ago
You need to use equals
instead of ==
to compare complex objects. That said, there seems to be a bug in the code generation library that we're using and the generated equals
method doesn't work properly either. See https://github.com/sundrio/sundrio/issues/142.
@metacosm, thanks for the update. When do you think the fix will be available?
No idea yet.
@naitikdani the initial issue that was found has been addressed in the underlying library. However, we're trying to get some more improvements that would make the API easier to use for your use case at the time. Hopefully, this will get done this week.
@naitikdani to be more precise, the approach that you use wouldn't work even with the fix. The predicate needs to be something more like: h -> h.hasMatchingMatch(m -> m.hasHeaders() && m.getHeaders().equals(matchMap)) && h.hasMatchingRoute(r -> r.buildDestination().getHost().equals("service-coke"))
. Note that this predicate will still fail without https://github.com/sundrio/sundrio/pull/144.
@naitikdani I will release a new beta version as soon as a new sundrio release is available.
This should be addressed in https://github.com/snowdrop/istio-java-api/releases/tag/1.1.0-Beta5. Note that you can now do: istioClient.virtualService().withName("reviews-route") .edit().editSpec() .removeMatchingFromHttp(h -> h.hasMatchingMatch(m -> m.hasHeaders() && m.getHeaders().equals(matchMap)) && h.hasMatchingRoute(r -> r.buildDestination().getHost().equals("service-coke"))) .endSpec().done()
. Let us know how it works for you!
Thanks @metacosm your fix works.
@metacosm , editMatchingHttp() is throwing the following error when trying to remove a specific match from virtualservice yaml file.
java.lang.RuntimeException: Can't edit matching http. No match found. at me.snowdrop.istio.api.networking.v1alpha3.VirtualServiceSpecFluentImpl.editMatchingHttp(VirtualServiceSpecFluentImpl.java
Here is the sample of yaml file and the code:
In the above yaml file I am trying to remove match with headers "coke" and destionation host as "service-coke":
Am I doing it the wrong way? Please let me know. Thanks for your help.