Skip to content

Commit

Permalink
Fixing hashicorpGH-1140 by always parsing template wait intervals to …
Browse files Browse the repository at this point in the history
…avoid unnecessary rendering.
  • Loading branch information
vaLski committed Jan 3, 2025
1 parent a7fb634 commit 3631aa1
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions manager/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,36 @@ func (r *Runner) Start() {
log.Printf("[DEBUG] (runner) watching %d dependencies", r.watcher.Size())
}

// Enable quiescence for all templates if we have specified wait
// intervals. Those sould be parsed regardless of the allTemplatesRendered.
// In certain cases, due to dependencies, allTemplatesRendered is never
// reached, or reached much further down the runtime, leading to
// template rendering overflow, especially on templates receiving
// frequent updates.
NEXT_Q:
for _, t := range r.templates {
if _, ok := r.quiescenceMap[t.ID()]; ok {
continue NEXT_Q
}

c := r.templateConfigFor(t)
if *c.Wait.Enabled {
log.Printf("[DEBUG] (runner) enabling template-specific "+
"quiescence for %q", t.ID())
r.quiescenceMap[t.ID()] = newQuiescence(
r.quiescenceCh, *c.Wait.Min, *c.Wait.Max, t)
continue NEXT_Q
}

if *r.config.Wait.Enabled {
log.Printf("[DEBUG] (runner) enabling global quiescence for %q",
t.ID())
r.quiescenceMap[t.ID()] = newQuiescence(
r.quiescenceCh, *r.config.Wait.Min, *r.config.Wait.Max, t)
continue NEXT_Q
}
}

if r.allTemplatesRendered() {
log.Printf("[DEBUG] (runner) all templates rendered")

Expand All @@ -323,32 +353,6 @@ func (r *Runner) Start() {
r.readyCh <- struct{}{}
}

// Enable quiescence for all templates if we have specified wait
// intervals.
NEXT_Q:
for _, t := range r.templates {
if _, ok := r.quiescenceMap[t.ID()]; ok {
continue NEXT_Q
}

c := r.templateConfigFor(t)
if *c.Wait.Enabled {
log.Printf("[DEBUG] (runner) enabling template-specific "+
"quiescence for %q", t.ID())
r.quiescenceMap[t.ID()] = newQuiescence(
r.quiescenceCh, *c.Wait.Min, *c.Wait.Max, t)
continue NEXT_Q
}

if *r.config.Wait.Enabled {
log.Printf("[DEBUG] (runner) enabling global quiescence for %q",
t.ID())
r.quiescenceMap[t.ID()] = newQuiescence(
r.quiescenceCh, *r.config.Wait.Min, *r.config.Wait.Max, t)
continue NEXT_Q
}
}

// If an exec command was given and a command is not currently running,
// spawn the child process for supervision.
if !r.config.Exec.Command.Empty() {
Expand Down

0 comments on commit 3631aa1

Please sign in to comment.