mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-04 16:40:21 +00:00
restmapper: re-try shortcut expander after not-found error
Kubernetes-commit: f7d1eb7726fa511b6439b7f8162138742ac639ab
This commit is contained in:
committed by
Kubernetes Publisher
parent
cf13620092
commit
e2598a43a3
@@ -43,7 +43,18 @@ func NewShortcutExpander(delegate meta.RESTMapper, client discovery.DiscoveryInt
|
||||
|
||||
// KindFor fulfills meta.RESTMapper
|
||||
func (e shortcutExpander) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error) {
|
||||
return e.RESTMapper.KindFor(e.expandResourceShortcut(resource))
|
||||
// expandResourceShortcut works with current API resources as read from discovery cache.
|
||||
// In case of new CRDs this means we potentially don't have current state of discovery.
|
||||
// In the current wiring in k8s.io/cli-runtime/pkg/genericclioptions/config_flags.go#toRESTMapper,
|
||||
// we are using DeferredDiscoveryRESTMapper which on KindFor failure will clear the
|
||||
// cache and fetch all data from a cluster (see vendor/k8s.io/client-go/restmapper/discovery.go#KindFor).
|
||||
// Thus another call to expandResourceShortcut, after a NoMatchError should successfully
|
||||
// read Kind to the user or an error.
|
||||
gvk, err := e.RESTMapper.KindFor(e.expandResourceShortcut(resource))
|
||||
if meta.IsNoMatchError(err) {
|
||||
return e.RESTMapper.KindFor(e.expandResourceShortcut(resource))
|
||||
}
|
||||
return gvk, err
|
||||
}
|
||||
|
||||
// KindsFor fulfills meta.RESTMapper
|
||||
|
Reference in New Issue
Block a user