Skip to content

Commit

Permalink
controller: fix conditional statement
Browse files Browse the repository at this point in the history
  • Loading branch information
talal committed Aug 21, 2020
1 parent 1ffe5be commit 9abc01a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.5.2] - 2020-08-21

### Fixed

- A bug that was introduced in the previous release.

## [0.5.1] - 2020-08-21

### Changed
Expand Down Expand Up @@ -47,7 +53,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release.

[unreleased]: https://github.com/sapcc/absent-metrics-operator/compare/v0.5.1...HEAD
[unreleased]: https://github.com/sapcc/absent-metrics-operator/compare/v0.5.2...HEAD
[0.5.2]: https://github.com/sapcc/absent-metrics-operator/compare/v0.5.1...v0.5.2
[0.5.1]: https://github.com/sapcc/absent-metrics-operator/compare/v0.5.0...v0.5.1
[0.5.0]: https://github.com/sapcc/absent-metrics-operator/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/sapcc/absent-metrics-operator/compare/v0.3.0...v0.4.0
Expand Down
27 changes: 17 additions & 10 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,12 @@ func (c *Controller) syncHandler(key string) error {
rg := promRule.Spec.Groups
// Fast path: check that the PrometheusRule contains at least one alert
// rule; no need to continue further otherwise.
hasAlerts := false
for _, g := range rg {
for _, r := range g.Rules {
if r.Alert != "" {
hasAlerts = true
}
if !hasAlerts(rg) {
if existingAbsentPromRule {
// We still need to clean up any orphaned absent alerts that may exist.
return c.cleanUpOrphanedAbsentAlerts(name, absentPromRule)
}
}
if !hasAlerts {
// We still need to clean up any orphaned absent alerts that may exist.
return c.cleanUpOrphanedAbsentAlerts(name, absentPromRule)
return nil
}

defaultTier := absentPromRule.Tier
Expand Down Expand Up @@ -393,3 +388,15 @@ func (c *Controller) syncHandler(key string) error {
c.metrics.SuccessfulPrometheusRuleReconcileTime.WithLabelValues(namespace, name).SetToCurrentTime()
return nil
}

// hasAlerts checks if a slice RuleGroup has any alert definitions.
func hasAlerts(rg []monitoringv1.RuleGroup) bool {
for _, g := range rg {
for _, r := range g.Rules {
if r.Alert != "" {
return true
}
}
}
return false
}

0 comments on commit 9abc01a

Please sign in to comment.