You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
codegen: generate go clients for custom resource routes (#1283)
## What Changed? Why?
Previously, the SDK only generated Go clients for individual resource
kinds
(CRUD operations + kind-level custom routes). However, manifest versions
can
also define custom routes at the routes.namespaced and routes.cluster
level —
scoped to a Group/Version rather than a specific kind — and no client
was
generated for those.
This PR adds codegen support for Group/Version-level custom route
clients.
When a manifest version defines routes in routes.namespaced or
routes.cluster,
a CustomRouteClient is now generated in the version package (e.g.
pkg/generated/v1alpha1/client_gen.go) with typed methods for each route.
### Key Changes
- codegen/jennies/goclients.go: Split Generate into
generateResourceClients
(existing per-kind clients) and generateCustomRouteClients (new GV-level
clients). The new generator iterates over manifest versions and emits a
client
file if any namespaced or clustered routes are present.
- codegen/templates/client.tmpl: New template for the CustomRouteClient
struct, with typed *Request/*Response wrapper methods for namespaced and
clustered routes. Uses NewCustomRouteClientFromGenerator to construct
the
client from a resource.ClientGenerator.
- resource/client.go: Added CustomRouteClient interface
(NamespacedRequest /
ClusteredRequest) and extended ClientGenerator with
GetCustomRouteClient(schema.GroupVersion, string).
- k8s/custom_route_client.go: Concrete CustomRouteClient implementation
backed
by the existing groupVersionClient.
- k8s/client_registry.go: Wired GetCustomRouteClient into the registry
so
callers can obtain a CustomRouteClient for any registered GV.
Addresses Issue #1277
### How was it tested?
- Codegen golden file tests
- Local generation against example apiserver kinds
- Manual client setup and live requests to the example apiserver
// 14 -> manifest file (1), then the custom route response+query+body for reconcile (3), response body and wrapper+query+body for search in v3 (4), request, response, and wrapper for /foobar in v3 (3), +1 client per version (3)
// 15 -> manifest file (1), then the custom route response+query+body for reconcile (3), response body and wrapper+query+body for search in v3 (4), request, response, and wrapper for /foobar in v3 (3), the resource clients for v1-v3 (3), and the version-level client for v3 routes (1)
0 commit comments