-
Notifications
You must be signed in to change notification settings - Fork 372
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
Refactor StackApplier #1815
Refactor StackApplier #1815
Conversation
|
||
return sa, nil | ||
doApply: func(ctx context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any actual profit from making this configurable? asking because delegates imo makes code harder to follow during debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent wasn't to make it configurable, but to synchronize access to the Applier via a Mutex. Alternatively, we can put the Mutex and the Applier into the StackApplier struct, allowing the Applier to be called without locking the Mutex and making it less obvious which parts of the struct are actually guarded by that Mutex.
Using the function pointers was basically a shorthand for something like this:
type StackApplier struct {
// ...
applier applier
}
type applier interface {
Apply(context.Context) error
Delete(context.Context) error
}
type syncApplier struct {
sync.Mutex
applier applier
}
func (a *syncApplier) Apply(ctx context.Context) error {
a.Lock()
defer a.Unlock()
return a.applier.Apply(ctx)
}
func (a *syncApplier) Delete(ctx context.Context) error {
a.Lock()
defer a.Unlock()
return a.applier.Delete(ctx)
}
func NewStackApplier(path string, kubeClientFactory kubernetes.ClientFactoryInterface) *StackApplier {
applier := NewApplier(path, kubeClientFactory)
return &StackApplier{
// ...
applier: &syncApplier{applier: &applier},
}
}
(In theory, a unit test could leverage the doApply, doDelete stuff as well, but that was not the goal.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks much better now, few minor nitpicks are in the comments.
Changes to StackApplier: * Combine Start/Stop methods into a simple Run method that exits when the given context is done. The start method blocked anyways, exiting when the Stop method was called. The context approach is somewhat more straight forward. * Only consider fsnotify events for manifest files. * Also log fsnotify watcher errors in the StackApplier. * Synchronize access to the internal applier, as calls to it might happen concurrently. * Remove the unused Healthy method. Changes to the Manager: * Always remove a stack from internal map, even if its deletion failed. The directory is gone anyways, and a readdition wouldn't work otherwise, because of the old, stopped stack still being in the map. * Retry stack running on failure. Signed-off-by: Tom Wieczorek <[email protected]>
0bb662e
to
85c26e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Part of #1814.
Changes to StackApplier:
Changes to the Manager:
Type of change
How Has This Been Tested?
Checklist: