mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix check depreciated api issue (#4243)
This commit is contained in:
parent
23a1df0d7b
commit
530e38a6f4
2 changed files with 14 additions and 10 deletions
|
@ -70,10 +70,10 @@ func (c serverPreferredResources) GetGVRFromKind(kind string) (schema.GroupVersi
|
|||
if kind == "" {
|
||||
return schema.GroupVersionResource{}, nil
|
||||
}
|
||||
|
||||
_, gvr, err := c.FindResource("", kind)
|
||||
_, k := kubeutils.GetKindFromGVK(kind)
|
||||
_, gvr, err := c.FindResource("", k)
|
||||
if err != nil {
|
||||
logger.Info("schema not found", "kind", kind)
|
||||
logger.Info("schema not found", "kind", k)
|
||||
return schema.GroupVersionResource{}, err
|
||||
}
|
||||
|
||||
|
@ -118,9 +118,9 @@ func (c serverPreferredResources) findResource(apiVersion string, kind string) (
|
|||
var serverResources []*metav1.APIResourceList
|
||||
var err error
|
||||
if apiVersion == "" {
|
||||
serverResources, err = discovery.ServerPreferredResources(c.DiscoveryInterface())
|
||||
serverResources, err = c.cachedClient.ServerPreferredResources()
|
||||
} else {
|
||||
_, serverResources, err = discovery.ServerGroupsAndResources(c.DiscoveryInterface())
|
||||
_, serverResources, err = c.cachedClient.ServerGroupsAndResources()
|
||||
}
|
||||
|
||||
if err != nil && !strings.Contains(err.Error(), "Got empty response for") {
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||
"github.com/kyverno/kyverno/pkg/config"
|
||||
"github.com/kyverno/kyverno/pkg/utils"
|
||||
kubeutils "github.com/kyverno/kyverno/pkg/utils/kube"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
|
@ -43,9 +44,10 @@ func MergeResources(a, b map[string]unstructured.Unstructured) {
|
|||
}
|
||||
|
||||
func (pc *PolicyController) getResourceList(kind, namespace string, labelSelector *metav1.LabelSelector, log logr.Logger) *unstructured.UnstructuredList {
|
||||
resourceList, err := pc.client.ListResource("", kind, namespace, labelSelector)
|
||||
_, k := kubeutils.GetKindFromGVK(kind)
|
||||
resourceList, err := pc.client.ListResource("", k, namespace, labelSelector)
|
||||
if err != nil {
|
||||
log.Error(err, "failed to list resources", "kind", kind, "namespace", namespace)
|
||||
log.Error(err, "failed to list resources", "kind", k, "namespace", namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -64,9 +66,11 @@ func (pc *PolicyController) getResourcesPerNamespace(kind string, namespace stri
|
|||
}
|
||||
|
||||
list := pc.getResourceList(kind, namespace, rule.MatchResources.Selector, log)
|
||||
for _, r := range list.Items {
|
||||
if pc.match(r, rule) {
|
||||
resourceMap[string(r.GetUID())] = r
|
||||
if list != nil {
|
||||
for _, r := range list.Items {
|
||||
if pc.match(r, rule) {
|
||||
resourceMap[string(r.GetUID())] = r
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue