Conversation
| return m | ||
| } | ||
|
|
||
| func (d *drainer) Drain(ctx context.Context, data DrainRequest) ([]*core.Pod, error) { |
There was a problem hiding this comment.
I see the only difference between Drain and Evict is the tryDrain/tryEvict(and log lines).
Do you think is does make sense to remove this duplication? Maybe some wrapper function with would take the tryDrain/tryEvict as parameters and call them?
There was a problem hiding this comment.
they have different parameters (tryDrain(ctx context.Context, toEvict []*core.Pod, **options meta.DeleteOptions**)) if not delete option i could do something like
func (d *drainer) Drain(ctx context.Context, data DrainRequest) ([]*core.Pod, error) {
logger := logger.FromContext(ctx, d.log)
logger.Info("starting drain")
d.do(ctx, d.tryDrain / d.tryEvict)
logger.Info("drain finished")
return failed, nil
}
func (d *drainer) do(ctx context.Context, fn func (ctx context.Context, toEvict []*core.Pod) ([]*core.Pod, []*core.Pod, error)) {
pods, err := d.list(ctx, data.Node)
if err != nil ...
toEvict := d.prioritizePods(pods, data.CastNamespace, data.SkipDeletedTimeoutSeconds)
if len(toEvict) == 0 ...
_, failed, err := fn()
err = d.waitTerminaition(ctx, data.Node, failed)
if err != nil {
return []*core.Pod{}, err
}
}
but i can't, since i need to pass DeleteOptions param
or u have something else in mind?
There was a problem hiding this comment.
Okay, I see. My idea was to the one you showed above. In theory we could do smth like:
opts := ...
f := func(ctx, pods) {
d.tryDrain(ctx, pods, opts)
}
// or
f := func(ctx, pods) {
d.tryEvict(ctx, pods)
}
d.do(f)But I'm myself not convinced it's easier to read than just a having two copy-pastes.
node drainer added, will be used to evict/drain node in future drain node action handler