mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 07:26:55 +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) {
|
func (c serverResources) FindResources(group, version, kind, subresource string) (map[TopLevelApiDescription]metav1.APIResource, error) {
|
||||||
resources, err := c.findResources(group, version, kind, subresource)
|
resources, err := c.findResources(group, version, kind, subresource)
|
||||||
if err != nil {
|
// if no resource was found, we have to force cache invalidation
|
||||||
if !c.cachedClient.Fresh() {
|
if err != nil || len(resources) == 0 {
|
||||||
|
if !c.cachedClient.Fresh() || len(resources) == 0 {
|
||||||
c.cachedClient.Invalidate()
|
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
|
return resources, err
|
||||||
|
|
|
@ -2,6 +2,7 @@ package adapters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/pkg/auth"
|
"github.com/kyverno/kyverno/pkg/auth"
|
||||||
|
@ -59,6 +60,9 @@ func (a *dclientAdapter) IsNamespaced(group, version, kind string) (bool, error)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
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 {
|
for _, apiResource := range gvrss {
|
||||||
return apiResource.Namespaced, nil
|
return apiResource.Namespaced, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ func collectParams(ctx context.Context, client engineapi.Client, paramKind *admi
|
||||||
var paramsNamespace string
|
var paramsNamespace string
|
||||||
isNamespaced, err := client.IsNamespaced(gv.Group, gv.Version, kind)
|
isNamespaced, err := client.IsNamespaced(gv.Group, gv.Version, kind)
|
||||||
if err != nil {
|
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
|
// check if `paramKind` is namespace-scoped
|
||||||
|
|
Loading…
Add table
Reference in a new issue