fix cached rest mapper

Signed-off-by: Poor12 <shentiecheng@huawei.com>
This commit is contained in:
Poor12 2023-06-13 15:04:41 +08:00
parent 9cb88f77ed
commit c84ccf61c1
1 changed files with 2 additions and 7 deletions

View File

@ -1,7 +1,6 @@
package restmapper
import (
"fmt"
"sync"
"k8s.io/apimachinery/pkg/api/meta"
@ -53,16 +52,12 @@ func (g *cachedRESTMapper) ResourceSingularizer(resource string) (singular strin
}
func (g *cachedRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error) {
// in case of multi-versions, cachedRESTMapper don't know which is the preferred version,
// in case of multi-versions or no versions, cachedRESTMapper don't know which is the preferred version,
// so just bypass the cache and consult the underlying mapper.
if len(versions) > 1 {
if len(versions) != 1 {
return g.restMapper.RESTMapping(gk, versions...)
}
if len(versions) == 0 {
return nil, fmt.Errorf("expected at least one version")
}
gvk := gk.WithVersion(versions[0])
value, ok := g.gvkToGVR.Load(gvk)
if ok { // hit cache, just return