Skip to content

Commit

Permalink
Wait for the old CRD Manager to stop before starting a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev committed Sep 27, 2024
1 parent f9054d3 commit 838570b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Main (unreleased)
- Update yet-another-cloudwatch-exporter from v0.60.0 vo v0.61.0: (@morremeyer)
- Fixes a bug where cloudwatch S3 metrics are reported as `0`

- `prometheus.operator.*` components: Fixed a bug which would sometimes cause a
"failed to create service discovery refresh metrics" error after a config reload. (@ptodev)

### Other changes

- Small fix in UI stylesheet to fit more content into visible table area. (@defanator)
Expand Down
10 changes: 10 additions & 0 deletions internal/component/prometheus/operator/common/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func (c *Component) Run(ctx context.Context) error {

c.reportHealth(nil)
errChan := make(chan error, 1)
runWg := sync.WaitGroup{}
defer runWg.Wait()
for {
select {
case <-ctx.Done():
Expand All @@ -87,15 +89,23 @@ func (c *Component) Run(ctx context.Context) error {
c.mut.Lock()
manager := newCrdManager(c.opts, c.cluster, c.opts.Logger, c.config, c.kind, c.ls)
c.manager = manager

// Wait for the old manager to stop.
// If we start the new manager before stopping the old one,
// the new manager might not be able to register its debug metrics due to a duplicate registration error.
if cancel != nil {
cancel()
}
runWg.Wait()

innerCtx, cancel = context.WithCancel(ctx)
runWg.Add(1)
go func() {
if err := manager.Run(innerCtx); err != nil {
level.Error(c.opts.Logger).Log("msg", "error running crd manager", "err", err)
errChan <- err
}
runWg.Done()
}()
c.mut.Unlock()
}
Expand Down

0 comments on commit 838570b

Please sign in to comment.