mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix: non watchable resources in report controller (#4888)
* fix: non watchable resources in report controller Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix events Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
f6cb33de95
commit
465f9d204b
1 changed files with 13 additions and 4 deletions
|
@ -11,7 +11,9 @@ import (
|
||||||
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
||||||
"github.com/kyverno/kyverno/pkg/controllers"
|
"github.com/kyverno/kyverno/pkg/controllers"
|
||||||
"github.com/kyverno/kyverno/pkg/controllers/report/utils"
|
"github.com/kyverno/kyverno/pkg/controllers/report/utils"
|
||||||
|
pkgutils "github.com/kyverno/kyverno/pkg/utils"
|
||||||
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
|
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
|
||||||
|
kubeutils "github.com/kyverno/kyverno/pkg/utils/kube"
|
||||||
reportutils "github.com/kyverno/kyverno/pkg/utils/report"
|
reportutils "github.com/kyverno/kyverno/pkg/utils/report"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
@ -126,11 +128,18 @@ func (c *controller) updateDynamicWatchers(ctx context.Context) error {
|
||||||
kinds := utils.BuildKindSet(logger, utils.RemoveNonBackgroundPolicies(logger, append(clusterPolicies, policies...)...)...)
|
kinds := utils.BuildKindSet(logger, utils.RemoveNonBackgroundPolicies(logger, append(clusterPolicies, policies...)...)...)
|
||||||
gvrs := map[string]schema.GroupVersionResource{}
|
gvrs := map[string]schema.GroupVersionResource{}
|
||||||
for _, kind := range kinds.List() {
|
for _, kind := range kinds.List() {
|
||||||
gvr, err := c.client.Discovery().GetGVRFromKind(kind)
|
apiVersion, kind := kubeutils.GetKindFromGVK(kind)
|
||||||
if err == nil {
|
apiResource, gvr, err := c.client.Discovery().FindResource(apiVersion, kind)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "failed to get gvr from kind", "kind", kind)
|
||||||
|
} else if apiVersion == "" && kind == "Event" {
|
||||||
|
logger.Info("Event cannot be an owner, skipping", "apiVersion", apiVersion, "kind", kind)
|
||||||
|
} else {
|
||||||
|
if pkgutils.ContainsString(apiResource.Verbs, "list") && pkgutils.ContainsString(apiResource.Verbs, "watch") {
|
||||||
gvrs[kind] = gvr
|
gvrs[kind] = gvr
|
||||||
} else {
|
} else {
|
||||||
logger.Error(err, "failed to get gvr from kind", "kind", kind)
|
logger.Info("list/watch not supported for kind", "kind", kind)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dynamicWatchers := map[schema.GroupVersionResource]*watcher{}
|
dynamicWatchers := map[schema.GroupVersionResource]*watcher{}
|
||||||
|
|
Loading…
Add table
Reference in a new issue