mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
fix: watch error in resource controller (#4751)
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
parent
5a3532da91
commit
7fa796e24a
1 changed files with 38 additions and 29 deletions
|
@ -139,7 +139,10 @@ func (c *controller) updateDynamicWatchers() error {
|
||||||
delete(c.dynamicWatchers, gvr)
|
delete(c.dynamicWatchers, gvr)
|
||||||
} else {
|
} else {
|
||||||
logger.Info("start watcher ...", "gvr", gvr)
|
logger.Info("start watcher ...", "gvr", gvr)
|
||||||
watchInterface, _ := c.client.GetDynamicInterface().Resource(gvr).Watch(context.TODO(), metav1.ListOptions{})
|
watchInterface, err := c.client.GetDynamicInterface().Resource(gvr).Watch(context.TODO(), metav1.ListOptions{})
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err, "failed to create watcher", "gvr", gvr)
|
||||||
|
} else {
|
||||||
w := &watcher{
|
w := &watcher{
|
||||||
watcher: watchInterface,
|
watcher: watchInterface,
|
||||||
gvk: gvr.GroupVersion().WithKind(kind),
|
gvk: gvr.GroupVersion().WithKind(kind),
|
||||||
|
@ -159,8 +162,11 @@ func (c *controller) updateDynamicWatchers() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
dynamicWatchers[gvr] = w
|
objs, err := c.client.GetDynamicInterface().Resource(gvr).List(context.TODO(), metav1.ListOptions{})
|
||||||
objs, _ := c.client.GetDynamicInterface().Resource(gvr).List(context.TODO(), metav1.ListOptions{})
|
if err != nil {
|
||||||
|
logger.Error(err, "failed to list resources", "gvr", gvr)
|
||||||
|
watchInterface.Stop()
|
||||||
|
} else {
|
||||||
for _, obj := range objs.Items {
|
for _, obj := range objs.Items {
|
||||||
uid := obj.GetUID()
|
uid := obj.GetUID()
|
||||||
hash := reportutils.CalculateResourceHash(obj)
|
hash := reportutils.CalculateResourceHash(obj)
|
||||||
|
@ -171,6 +177,9 @@ func (c *controller) updateDynamicWatchers() error {
|
||||||
}
|
}
|
||||||
c.notify(uid, w.gvk, w.hashes[uid])
|
c.notify(uid, w.gvk, w.hashes[uid])
|
||||||
}
|
}
|
||||||
|
dynamicWatchers[gvr] = w
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// shutdown remaining watcher
|
// shutdown remaining watcher
|
||||||
|
|
Loading…
Reference in a new issue