Skip to content

Commit

Permalink
fix: add externalobservation in handler interface
Browse files Browse the repository at this point in the history
  • Loading branch information
matteogastaldello committed Oct 31, 2024
1 parent e9475f3 commit 988044b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
// if it's called again with the same parameters or Delete call should not
// return error if there is an ongoing deletion or resource does not exist.
type ExternalClient interface {
Observe(ctx context.Context, mg *unstructured.Unstructured) (bool, error)
Observe(ctx context.Context, mg *unstructured.Unstructured) (ExternalObservation, error)
Create(ctx context.Context, mg *unstructured.Unstructured) error
Update(ctx context.Context, mg *unstructured.Unstructured) error
Delete(ctx context.Context, mg *unstructured.Unstructured) error
Expand Down
7 changes: 5 additions & 2 deletions pkg/controller/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *Controller) handleObserve(ctx context.Context, ref objectref.ObjectRef)
return nil
}

exists, actionErr := c.externalClient.Observe(ctx, el)
observation, actionErr := c.externalClient.Observe(ctx, el)
if actionErr != nil {
if apierrors.IsNotFound(actionErr) {
return c.externalClient.Update(ctx, el)
Expand All @@ -167,9 +167,12 @@ func (c *Controller) handleObserve(ctx context.Context, ref objectref.ObjectRef)
c.logger.Debug("Observe: updating status", "error", err)
return err
}
return actionErr
}
if !exists {
if !observation.ResourceExists {
return c.externalClient.Create(ctx, el)
} else if observation.ResourceExists && !observation.ResourceUpToDate {
return c.externalClient.Update(ctx, el)
}

return nil
Expand Down

0 comments on commit 988044b

Please sign in to comment.