Skip to content

kubernetes-api.internals.client/find-preferred-route behaves not as expected on multiple match #13

@lotuc

Description

@lotuc

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

  1. Search routes with find-route which only uses :kind and :action fields, this could lead to multiple match
  2. Filter out Status routes (which related to Enable 'Status' routes #6 )
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions