Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Make sync operations timeout configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Sep 26, 2019
1 parent bf83c71 commit 86f37b2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
2 changes: 2 additions & 0 deletions cmd/fluxd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func main() {

// syncing
syncInterval = fs.Duration("sync-interval", 5*time.Minute, "apply config in git to cluster at least this often, even if there are no new commits")
syncTimeout = fs.Duration("sync-timeout", 1*time.Minute, "duration after which sync operations time out")
syncGC = fs.Bool("sync-garbage-collection", false, "experimental; delete resources that were created by fluxd, but are no longer in the git repo")
dryGC = fs.Bool("sync-garbage-collection-dry", false, "experimental; only log what would be garbage collected, rather than deleting. Implies --sync-garbage-collection")
syncState = fs.String("sync-state", fluxsync.GitTagStateMode, fmt.Sprintf("method used by flux for storing state (one of {%s})", strings.Join([]string{fluxsync.GitTagStateMode, fluxsync.NativeStateMode}, ",")))
Expand Down Expand Up @@ -689,6 +690,7 @@ func main() {
ManifestGenerationEnabled: *manifestGeneration,
LoopVars: &daemon.LoopVars{
SyncInterval: *syncInterval,
SyncTimeout: *syncTimeout,
SyncState: syncProvider,
AutomationInterval: *automationInterval,
GitTimeout: *gitTimeout,
Expand Down
13 changes: 2 additions & 11 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ import (
"github.com/fluxcd/flux/pkg/update"
)

const (
// This is set to be in sympathy with the request / RPC timeout (i.e., empirically)
defaultHandlerTimeout = 10 * time.Second
// A job can take an arbitrary amount of time but we want to have
// a (generous) threshold for considering a job stuck and
// abandoning it
defaultJobTimeout = 60 * time.Second
)

// Daemon is the fully-functional state of a daemon (compare to
// `NotReadyDaemon`).
type Daemon struct {
Expand Down Expand Up @@ -276,7 +267,7 @@ func (d *Daemon) makeJobFromUpdate(update updateFunc) jobFunc {
// executeJob runs a job func and keeps track of its status, so the
// daemon can report it when asked.
func (d *Daemon) executeJob(id job.ID, do jobFunc, logger log.Logger) (job.Result, error) {
ctx, cancel := context.WithTimeout(context.Background(), defaultJobTimeout)
ctx, cancel := context.WithTimeout(context.Background(), d.SyncTimeout)
defer cancel()
d.JobStatusCache.SetStatus(id, job.Status{StatusString: job.StatusRunning})
result, err := do(ctx, id, logger)
Expand Down Expand Up @@ -371,7 +362,7 @@ func (d *Daemon) UpdateManifests(ctx context.Context, spec update.Spec) (job.ID,
func (d *Daemon) sync() jobFunc {
return func(ctx context.Context, jobID job.ID, logger log.Logger) (job.Result, error) {
var result job.Result
ctx, cancel := context.WithTimeout(ctx, defaultJobTimeout)
ctx, cancel := context.WithTimeout(ctx, d.SyncTimeout)
defer cancel()
err := d.Repo.Refresh(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ func mockDaemon(t *testing.T) (*Daemon, func(), func(), *mock.Mock, *mockEventWr
JobStatusCache: &job.StatusCache{Size: 100},
EventWriter: events,
Logger: logger,
LoopVars: &LoopVars{GitTimeout: timeout, SyncState: gitSync},
LoopVars: &LoopVars{SyncTimeout: timeout, GitTimeout: timeout, SyncState: gitSync},
}

start := func() {
Expand Down
1 change: 1 addition & 0 deletions pkg/daemon/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

type LoopVars struct {
SyncInterval time.Duration
SyncTimeout time.Duration
AutomationInterval time.Duration
GitTimeout time.Duration
GitVerifySignatures bool
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func daemon(t *testing.T) (*Daemon, func()) {
JobStatusCache: &job.StatusCache{Size: 100},
EventWriter: events,
Logger: log.NewLogfmtLogger(os.Stdout),
LoopVars: &LoopVars{GitTimeout: timeout},
LoopVars: &LoopVars{SyncTimeout: timeout, GitTimeout: timeout},
}
return d, func() {
close(shutdown)
Expand Down

0 comments on commit 86f37b2

Please sign in to comment.