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

[agent-sidecar] Add cancel hook for file watcher #535

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/vald/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ agent:
auto_backup_duration: 10m
# @schema {"name": "agent.sidecar.config.post_stop_timeout", "type": "string"}
# agent.sidecar.config.post_stop_timeout -- timeout duration for file changing during post stop
post_stop_timeout: 10s
post_stop_timeout: 20s
# @schema {"name": "agent.sidecar.config.filename", "type": "string"}
# agent.sidecar.config.filename -- backup filename
filename: _MY_POD_NAME_
Expand Down
11 changes: 10 additions & 1 deletion pkg/agent/sidecar/service/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,19 @@ func (o *observer) PostStop(ctx context.Context) (err error) {
return err
}

_, err = o.w.Start(ctx)
wctx, cancel := context.WithCancel(ctx)
defer cancel()

_, err = o.w.Start(wctx)
if err != nil {
return err
}
defer func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
only one cuddle assignment allowed before defer statement (wsl)

e := o.w.Stop(wctx)
if e != nil {
log.Error("an error occurred when watcher stopped:", e)
}
}()

for {
select {
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/sidecar/service/observer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
defaultOpts = []Option{
WithErrGroup(errgroup.Get()),
WithBackupDuration("10m"),
WithPostStopTimeout("10s"),
WithPostStopTimeout("20s"),
}
)

Expand Down