Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic Notification Policy Routes (#1800)
* feat: run operator-sdk create api command Adapted PROJECT to new go module version path and ran: ``` ./bin/operator-sdk create api --group grafana --version v1beta1 --kind GrafanaNotificationPolicyRoute --controller false ``` * feat: add new fields to GrafanaNotificationPolicyRoute spec * chore: run make manifests && make generate * feat: add DiscoveredRoutes to GrafanaNotificationPolicy status * refactor: switch to RouteSelector instead of InstanceSelector - during the reconcile loop in notificationpolicy_controller.go, we have to fetch all matching GrafanaNotificationPolicyRoutes for the currently reconciled GrafanaNotificationPolicy - this can be very easily achieved with a routeSelector, which will be a Kubernetes LabelSelector - if we would go with instanceSelector, we would have to fetch all available GrafanaNotificationPolicyRoutes and then do some filtering afterwards, to see if the instanceSelector matches, which would be both more inefficient and more complex * chore: run make * feat: implement merging of NotificationPolicyRoutes * test: add test for mergeNotificationPolicyRoutesWithRouteList * chore: add samples for local GrafanaNotificationPolicyRoute testing * feat: setup ownerReferences for GrafanaNotificationPolicyRoutes * feat: replace owner references with watches to support cross-namespace The GrafanaNotificationPolicy Controller now watches GrafanaNoticationPolicyRoutes instead of using ownerReferences, as ownerReferences do not support cross-namespace references. We now also emit a event on the GrafanaNotificationPolicyRoute to indicate that it has been merged into a specific policy. * docs: add docs and example for new NotificationPolicyRoute * refactor: move routeSelector to route object, make it mutually exclusive * refactor: implement new assembleNotificationPolicyRoutes logic * refactor: implement new dynamic route assembly and add tests * refactor: remove priority * chore: re-run make manifest and generate, fix go mods * feat: add status condition for mutual exclusivity check - adds validation for ensuring routes and routeSelector are mutual exclusive - updates both GrafanaNotificationPolicy and GrafanaNotificationPolicyRoute status conditions accordingly * docs: update examples and docs related to NotificationPolicies * refactor: convert to member func and rename to selectorMutuallyExclusive * chore: mention mutual exclusivity in comments * test: fix test setup order and kind args * refactor: inline Route object * refactor: remove controller for GrafanaNotificationPolicyRoute * refactor: implement NamespacedResource for NotificationPolicyRoute * docs: switch to example image of rendered routes * Update docs/docs/alerting/notification-policies.md Co-authored-by: Dominik Süß <dominik@suess.wtf> * Update docs/docs/alerting/notification-policies.md Co-authored-by: Dominik Süß <dominik@suess.wtf> * fix * refactor: always sync applyErrors status condition on defer * refactor: always sync all GrafanaNotificationPolicy on route changes related GrafanaNotificationPolicies can now no longer easily retrieved by comparing labels, as routes can be referenced transitively. Therefore we simply sync all related policies now. * Update docs/docs/alerting/notification-policies.md Co-authored-by: Dominik Süß <dominik@suess.wtf> * refactor: remove duplicate IsCrossNamespaceImportAllowed * Update controllers/notificationpolicy_controller.go Co-authored-by: Steffen Baarsgaard <steff.bpoulsen@gmail.com> * refactor: move hasRouteSelector to struct function * refactor: set invalid spec on mutual exclusivity constraint not met * lint: fix test lint issues * refactor: move namespace detection to assembleNotificationPolicyRoutes * refactor: remove duplicate status condition set, already done on defer * refactor: set specific condition and events for assembly errors - reverted changes that moved building synchronized condition to defer - added a specific error type for loop detected errors - set condition for specific errors and emit events otherwise for assembly errors * fix: formatting * fix: return error when spec is invalid * chore: fix repo in PROJECT * refactor: fix linter issues * chore: regenerate api docs --------- Co-authored-by: Dominik Süß <dominik@suess.wtf> Co-authored-by: Steffen Baarsgaard <steff.bpoulsen@gmail.com>
- Loading branch information