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

🐛 fix unspecified KindsFor version #2346

Merged
merged 6 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions pkg/client/apiutil/restmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ func (m *mapper) getMapper() meta.RESTMapper {
// addKnownGroupAndReload reloads the mapper with updated information about missing API group.
// versions can be specified for partial updates, for instance for v1beta1 version only.
func (m *mapper) addKnownGroupAndReload(groupName string, versions ...string) error {
// versions will here be [""] if the forwarded Version value of
// GroupVersionResource (in calling method) was not specified.
if len(versions) == 1 && versions[0] == "" {
versions = []string{}
tenstad marked this conversation as resolved.
Show resolved Hide resolved
}

// If no specific versions are set by user, we will scan all available ones for the API group.
// This operation requires 2 requests: /api and /apis, but only once. For all subsequent calls
// this data will be taken from cache.
Expand Down
22 changes: 22 additions & 0 deletions pkg/client/apiutil/restmapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@ func TestLazyRestMapperProvider(t *testing.T) {
g.Expect(crt.GetRequestCount()).To(gmg.Equal(4))
})

t.Run("LazyRESTMapper KindsFor should work correctly with empty versions list", func(t *testing.T) {
tenstad marked this conversation as resolved.
Show resolved Hide resolved
g := gmg.NewWithT(t)

httpClient, err := rest.HTTPClientFor(restCfg)
g.Expect(err).NotTo(gmg.HaveOccurred())

crt := newCountingRoundTripper(httpClient.Transport)
httpClient.Transport = crt

lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, httpClient)
g.Expect(err).NotTo(gmg.HaveOccurred())

g.Expect(crt.GetRequestCount()).To(gmg.Equal(0))

kinds, err := lazyRestMapper.KindsFor(schema.GroupVersionResource{Group: "autoscaling", Resource: "horizontalpodautoscaler"})
g.Expect(err).NotTo(gmg.HaveOccurred())
g.Expect(len(kinds)).To(gmg.Equal(2))
tenstad marked this conversation as resolved.
Show resolved Hide resolved
g.Expect(kinds[0].Kind).To(gmg.Equal("HorizontalPodAutoscaler"))
g.Expect(kinds[1].Kind).To(gmg.Equal("HorizontalPodAutoscaler"))
g.Expect(crt.GetRequestCount()).To(gmg.Equal(4))
})
tenstad marked this conversation as resolved.
Show resolved Hide resolved

t.Run("LazyRESTMapper should work correctly with multiple API group versions", func(t *testing.T) {
g := gmg.NewWithT(t)

Expand Down