Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add event handler to Applier/Destroyer #1199

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

karlkfi
Copy link
Contributor

@karlkfi karlkfi commented Apr 26, 2024

Use an injected event handler function to avoid needing to cache errors in the supervisor. Instead, cache errors in the Updater, which already has a lock for this.

This event handler simplifies the Applier/Destroyer API and makes it easy to add more events in the future, like for inventory updates.

Dependencies:

Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from karlkfi. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

// This method may be called while Destroy is running, to get the set of
// errors encountered so far.
Errors() status.MultiError
Apply(ctx context.Context, eventHandler func(Event), desiredResources []client.Object) (ObjectStatusMap, *stats.SyncStats)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned values are only used for logging. What about logging inside the inner functions without returning anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what it was doing before, but returning them lets us test them.

validationErrs status.MultiError
applyErrs status.MultiError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the change. The applyErrs now is only specific to the apply process, and doesn't not require cleaning up in the destroy time.


// Return a copy to avoid persisting caller modifications
return status.Append(nil, a.errs)
func (a *supervisor) sendErrorEvent(err error, eventHandler func(Event)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sendErrorEvent function doesn't need to be a member of the supervisor.

// This method may be called while Destroy is running, to get the set of
// errors encountered so far.
Errors() status.MultiError
Apply(ctx context.Context, eventHandler func(Event), desiredResources []client.Object) (ObjectStatusMap, *stats.SyncStats)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about renaming eventHandler to errorEventHandler or errorHandler to distinguish it from supervisorEventHandler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan on adding inventory events to it, errors are just the first pass.

But yes, having two event handlers in the same file is a bit confusing. Open to other suggestions though.

I was thinking maybe the supervisorEventHandler could be merged with the supervisor, but the supervisorEventHandler has a destroy flag I don't really want to pass to all the methods individually.

@karlkfi
Copy link
Contributor Author

karlkfi commented May 3, 2024

/retest

- Resources' DeclaredUnstructureds, DeclaredObjects, DeclaredGVKs,
  and getObjectSet were previously iterating over a Go map, causing the
  output to be randomly ordered. This change replaces the map with an
  OrderedMap that can be iterated in insert order. This makes it
  easier to test classes that use declared.Resources, including
  Applier.Apply and parse.parseAndUpdate.
- Add fakes for Applier, Remediator, and ConfigParser
- Add test validation for Apply, Remediate, and Parse inputs and outputs
- Fix fake.RootSync/RepoSync to avoid populating the status. These
  return a FileObject, which never have a status when created by the
  parser.
- Fix filesystem.AsCoreObjects to return nil when empty
- Replace kpt.dev/configsync/pkg/util/ordered with
  github.com/elliotchance/orderedmap/v2 which supports generics and
  actually has unit tests.
Use an injected event handler function to avoid needing to cache
errors in the supervisor. Instead, cache errors in the Updater,
which already has a lock for this.

This event handler simplifies the Applier/Destroyer API and makes
it easy to add more events in the future, like for inventory updates.
Copy link

@karlkfi: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
kpt-config-sync-presubmit-e2e-multi-repo-test-group2 0d2c829 link true /test kpt-config-sync-presubmit-e2e-multi-repo-test-group2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants