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

filewatch: use apiserver FileWatch model in EngineState #4277

Merged
merged 9 commits into from Mar 9, 2021

Conversation

milas
Copy link
Contributor

@milas milas commented Mar 5, 2021

This follows the "action-first" approach to use the apiserver model
for FileWatch and dispatch simple create/update/delete actions.

I didn't touch the git manager, so some things that are no longer
needed for normal file watching but it relies on were moved over
there.

This is actually pretty similar to the previous implementation since
file watch isn't really its own resource/concept in the current design.
It's a bit incremental of the incremental - the next step would be to
remove the diffing logic and instead just react to changes to the
FileWatchSpecs within the watch manager (which would then just
the authority on FileWatchStatus) and instead push the onus for
actually creating/updating specs to someone else.

@milas milas requested review from nicks and vkorbes March 5, 2021 00:44
This follows the "action-first" approach to use the apiserver model
for `FileWatch` and dispatch simple create/update/delete actions.
@milas milas force-pushed the milas/filewatch-api-actions branch from 5d747c9 to d71c95b Compare March 5, 2021 00:47
@milas milas changed the title filewatch: use apiserver FileWatch model filewatch: use apiserver FileWatch model in EngineState Mar 5, 2021
Copy link
Member

@nicks nicks left a comment

Choose a reason for hiding this comment

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

whew! Ya, i'm glad we tried to do these in parallel, since i'm starting to see the common themes (rather than wondering if something was particiular to Cmd)

pkg/apis/core/v1alpha1/filewatch_types.go Show resolved Hide resolved
}
w.cleanupWatch(ctx, tw)

fw := state.FileWatches[name]
Copy link
Member

Choose a reason for hiding this comment

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

ah, i hit this problem too...

the approach to this that i've been taking is that, when a subscriber sends a Create/Update, it should keep a local map of the last create/updated object, and then use that map to make create/update idempotent

I think the problem with doing it this way is that you're going to run into weird circular data flow issues where this code is reading and writing the same data....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha! This is iteration 3, but I should probably just go back to the original. First, I had totally duplicated copies of the full FileWatch both places as you're suggesting. A second (short-lived) version was to rely entirely on the store to avoid duplicating here, which obviously did not pan out. I agree this final approach is problematic - I was trying to get closer to the K8s model somewhat (i.e. pretend that it's level-triggered).

I'll flip back to that - I think the next big experiment that needs to be done is shifting responsibility for the creation of the FileWatch to the resource to move towards our desired model, at which point, hopefully this becomes much more like a real reconciler, at which point it should just read specs to trigger FS watchers, and let the FS watchers do status updates in the background. At that point, shouldn't be any circular weirdness 😵

Copy link
Member

Choose a reason for hiding this comment

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

ya, i had a similar experience - it's simpler if the controller that does create/delete is separate from the controller that does UpdateStatus. i think that having the ChangeSummary stuff to tell the controller what changed will also help with this

internal/engine/fswatch/watchmanager.go Outdated Show resolved Hide resolved
}

// we always have the latest status, so just unconditionally overwrite whatever is in the object
tw.status.DeepCopyInto(&fw.Status)
Copy link
Member

Choose a reason for hiding this comment

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

should we reset the status when the spec changes? (I honestly don't know, this is something I struggled with too)

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've gone back and forth as well (I think the other PR resets it 😬) - I'm guessing it's best to standardize on resetting for consistency?

Here, while there could be value in still being able to see the previous changesets, it's also actually misleading because if you add a new file to the watch paths, it of course won't get retroactively added to those events.

I think one thing that FileWatchStatus is missing is probably more actual status about the filesystem watcher. So perhaps WatchStartTime which gets updated whenever the filesystem watcher is started (or "updated"); that gives consumers another value to use against their own internal watermark, e.g. if (myLastUpdated.Before(fwStatus.LastEventTime) || myLastUpdated.Before(fwStatus.WatchStartTime); that would allow e.g. easily triggering a rebuild when the watch patterns are changed (if desired behavior).

pkg/apis/core/v1alpha1/filewatch_types.go Show resolved Hide resolved
internal/engine/upper.go Outdated Show resolved Hide resolved
internal/engine/upper.go Outdated Show resolved Hide resolved
@milas milas merged commit 074061f into master Mar 9, 2021
@milas milas deleted the milas/filewatch-api-actions branch March 9, 2021 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants