Skip to content

Commit

Permalink
Merge pull request #75 from kubescape/notfind
Browse files Browse the repository at this point in the history
stop watching on not found resources
  • Loading branch information
matthyx authored Mar 27, 2024
2 parents f9c9c90 + e108c6f commit d965ba1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions adapters/incluster/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/kubescape/synchronizer/config"
"github.com/kubescape/synchronizer/domain"
"github.com/kubescape/synchronizer/utils"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -181,9 +182,14 @@ func (c *Client) Stop(_ context.Context) error {
}

func (c *Client) watchRetry(ctx context.Context, watchOpts metav1.ListOptions, eventQueue *utils.CooldownQueue) {
exitFatal := true
if err := backoff.RetryNotify(func() error {
watcher, err := c.client.Resource(c.res).Namespace("").Watch(context.Background(), watchOpts)
if err != nil {
if k8sErrors.ReasonForError(err) == metav1.StatusReasonNotFound {
exitFatal = false
return backoff.Permanent(err)
}
return fmt.Errorf("client resource: %w", err)
}
logger.L().Info("starting watch", helpers.String("resource", c.res.Resource))
Expand Down Expand Up @@ -218,8 +224,11 @@ func (c *Client) watchRetry(ctx context.Context, watchOpts metav1.ListOptions, e
helpers.String("retry in", d.String()))
}
}); err != nil {
logger.L().Ctx(ctx).Fatal("giving up watch", helpers.Error(err),
helpers.String("resource", c.res.Resource))
logger.L().Ctx(ctx).Error("giving up watch", helpers.Error(err),
helpers.String("resource", c.res.String()))
if exitFatal {
os.Exit(1)
}
}
}

Expand Down

0 comments on commit d965ba1

Please sign in to comment.