Skip to content

Commit

Permalink
fix(syncer): handle DeletedFinalStateUnknown objects (#595)
Browse files Browse the repository at this point in the history
## What type of PR is this?

/kind bug

## What this PR does / why we need it:

If we don't handle DeletedFinalStateUnknown object, the document in ES
associated with the deleted resource will be left forever.

## Which issue(s) this PR fixes:

<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related
issues/tests in a comment and do not use `Fixes`_*
-->

Fixes #
  • Loading branch information
iamryanchia authored Sep 11, 2024
1 parent 5932cfb commit 6514721
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/syncer/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,22 @@ func (s *informerSource) parseTransformer() (clientgocache.TransformFunc, error)
return func(obj interface{}) (ret interface{}, err error) {
defer func() {
if err != nil {
s.logger.Error(err, "error in transforming object", "actualType", reflect.TypeOf(obj))
s.logger.Error(err, "error in transforming object")
}
}()

if d, ok := obj.(clientgocache.DeletedFinalStateUnknown); ok {
// Since we import ES data into informer cache at startup, the
// resource that was deleted during the restart will generate
// DeletedFinalStateUnknown.
// We unwarp the object here, so there is no need for following
// steps including event handler to care about DeletedFinalStateUnknown.
obj = d.Obj
}

u, ok := obj.(*unstructured.Unstructured)
if !ok {
return nil, fmt.Errorf("transform: object's type should be *unstructured.Unstructured")
return nil, fmt.Errorf("transform: object's type should be *unstructured.Unstructured, but received %v", reflect.TypeOf(obj))
}

templateData := struct {
Expand Down

0 comments on commit 6514721

Please sign in to comment.