mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
fix: cache invalidation in FindResources (#8316)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
10dacd5292
commit
5beaec677f
3 changed files with 15 additions and 4 deletions
|
@ -163,10 +163,17 @@ func (c serverResources) FindResource(groupVersion string, kind string) (apiReso
|
|||
|
||||
func (c serverResources) FindResources(group, version, kind, subresource string) (map[TopLevelApiDescription]metav1.APIResource, error) {
|
||||
resources, err := c.findResources(group, version, kind, subresource)
|
||||
if err != nil {
|
||||
if !c.cachedClient.Fresh() {
|
||||
// if no resource was found, we have to force cache invalidation
|
||||
if err != nil || len(resources) == 0 {
|
||||
if !c.cachedClient.Fresh() || len(resources) == 0 {
|
||||
c.cachedClient.Invalidate()
|
||||
return c.findResources(group, version, kind, subresource)
|
||||
resources, err := c.findResources(group, version, kind, subresource)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if len(resources) == 0 {
|
||||
return nil, fmt.Errorf("failed to find resource (%s/%s/%s/%s)", group, version, kind, subresource)
|
||||
}
|
||||
return resources, err
|
||||
}
|
||||
}
|
||||
return resources, err
|
||||
|
|
|
@ -2,6 +2,7 @@ package adapters
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/kyverno/kyverno/pkg/auth"
|
||||
|
@ -59,6 +60,9 @@ func (a *dclientAdapter) IsNamespaced(group, version, kind string) (bool, error)
|
|||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(gvrss) != 1 {
|
||||
return false, fmt.Errorf("function IsNamespaced expects only one resource, got (%d)", len(gvrss))
|
||||
}
|
||||
for _, apiResource := range gvrss {
|
||||
return apiResource.Namespaced, nil
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ func collectParams(ctx context.Context, client engineapi.Client, paramKind *admi
|
|||
var paramsNamespace string
|
||||
isNamespaced, err := client.IsNamespaced(gv.Group, gv.Version, kind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to check if resource is namespaced or not (%w)", err)
|
||||
}
|
||||
|
||||
// check if `paramKind` is namespace-scoped
|
||||
|
|
Loading…
Reference in a new issue