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

chore: consolidate k8s informers code & fix Makefile mocks #7455

Merged
merged 16 commits into from
Jul 28, 2023

Conversation

carolinaecalderon
Copy link
Contributor

@carolinaecalderon carolinaecalderon commented Jul 25, 2023

Description

After removing the actor system from the k8s informers code, refactor the pod/node/event/preemption informer code to remove redundancies & consolidate (if possible) to fewer functions. (This PR would reduce that code by 40%, yay!)

Each informer defines its own "callback function", but now these callback functions are standardized to accept watch.Events (vs other struct types). This additionally standardizes the run() function.
Since each informer constructor calls on/returns different types, the newInformer()- type functions could not be combined. (The exception is with pod-Informer and preemption-Informer, both of which deal with pod lists).

Also -- this PR adds code to generate the Pod/EventInterface mocks.

Test Plan

Test in the a similar manner as #7182 and #7256.

Commentary (optional)

Checklist

  • Changes have been manually QA'd
  • User-facing API changes need the "User-facing API Change" label.
  • Release notes should be added as a separate file under docs/release-notes/.
    See Release Note for details.
  • Licenses should be included for new code which was copied and/or modified from any external code.

Ticket

DET-9686

@cla-bot cla-bot bot added the cla-signed label Jul 25, 2023
@netlify
Copy link

netlify bot commented Jul 25, 2023

Deploy Preview for determined-ui ready!

Name Link
🔨 Latest commit 0bb844b
🔍 Latest deploy log https://app.netlify.com/sites/determined-ui/deploys/64c3ddc39241290008211e69
😎 Deploy Preview https://deploy-preview-7455--determined-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@carolinaecalderon carolinaecalderon marked this pull request as ready for review July 25, 2023 01:59
@carolinaecalderon carolinaecalderon requested a review from a team as a code owner July 25, 2023 01:59
Comment on lines 137 to 150
func (i *informer) run() {
ctx, cancel := context.WithCancel(context.TODO())
i.syslog.Debugf("%s informer is starting", i.name)
for {
select {
case event := <-i.resultChan:
if event.Type == watch.Error {
i.syslog.Warnf("%s informer emitted error %+v", i.name, event)
continue
}
i.cb(event)
cancel()
case <-ctx.Done():
panic(fmt.Sprintf("%s informer stopped unexpectedly: %s", i.name, ctx.Err()))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue here -- placing the cancel() call causes informer to crash sooner than desired.
Screen Shot 2023-07-25 at 3 14 30 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted because informers crash with this implementation

Copy link

Choose a reason for hiding this comment

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

we shouldn't be calling cancel in the informer run loop.

i would've just made run() take a context like run(ctx context.Context), pass context.TODO() for now in the pods actor, and then in tests, at the top of each test

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

and use that context in the run calls in the test

Copy link

@stoksc stoksc left a comment

Choose a reason for hiding this comment

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

lgtm

@carolinaecalderon carolinaecalderon changed the title chore: consolidate k8s informers code chore: consolidate k8s informers code & fix Makefile mocks Jul 26, 2023
@carolinaecalderon carolinaecalderon force-pushed the 9686-consolidate-informers branch from 4bdfb33 to bde62bf Compare July 26, 2023 18:20
@carolinaecalderon carolinaecalderon force-pushed the 9686-consolidate-informers branch from 8b501c2 to 0bb844b Compare July 28, 2023 15:24
@carolinaecalderon carolinaecalderon merged commit 525ebfe into main Jul 28, 2023
@carolinaecalderon carolinaecalderon deleted the 9686-consolidate-informers branch July 28, 2023 20:20
@dannysauer dannysauer added this to the 0.24.0 milestone Feb 6, 2024
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.

3 participants