k8s-api
k8s-api copied to clipboard
`kubernetes-api.internals.client/find-preferred-route` behaves not as expected on multiple match
kubernetes-api.core
APIs uses internals.client/find-preferred-route
for finding the route to be called.
Now kubernetes-api.internals.client/find-preferred-route
does
- Search routes with
find-route
which only uses:kind
and:action
fields, this could lead to multiple match - Filter out
Status
routes (which related to #6 ) - For multiple matched route, choose the one route for which its version is the current preferred version. If multiple such routes meets the condition, just choose the first one.
I'm encountering that two route matches all the condition:
(require '[kubernetes-api.internals.client :refer [kind action all-namespaces-route?] :as internals.client])
(->> (internals.client/find-route k8s {:kind :Ingress
:action :patch/json-merge})
(filter (fn [x] (not (clojure.string/ends-with? (name x) "Status"))))
(map (fn [route]
(filter #(and (= (:name %) (internals.client/group-of k8s route))
(= (:version (:preferredVersion %)) (internals.client/version-of k8s route)))
(internals.client/all-versions k8s)))))
;; ->
(({:name "networking.internal.knative.dev",
:versions
[{:groupVersion "networking.internal.knative.dev/v1alpha1",
:version "v1alpha1"}],
:preferredVersion
{:groupVersion "networking.internal.knative.dev/v1alpha1",
:version "v1alpha1"}})
({:name "networking.k8s.io",
:versions [{:groupVersion "networking.k8s.io/v1", :version "v1"}],
:preferredVersion {:groupVersion "networking.k8s.io/v1", :version "v1"}}))
And it chooses "networking.internal.knative.dev"
which is not what I expected and it can not be opted out (though I can hack it around thanks to with-redefs).
It would be great if route search & preferring option can be customized.