Skip to content

Commit

Permalink
Fix OVNKubernetes alert rules for OpenShift 4.14
Browse files Browse the repository at this point in the history
OpenShift 4.14 moved the OVNKubernetes control plane alerts (and we
can't use the 4.13 alerts, because 4.14 makes significant changes to the
OVNKubernetes architecture). Additionally 4.14 introduced gotemplate
snippets in the OVNKubernetes alerts that we need to render.

Since the files also contain gotemplate snippets which aren't valid
Jinja2, we implement very simple rendering logic which uses
`std.strReplace()` in the component.
  • Loading branch information
simu committed Apr 9, 2024
1 parent 06d57db commit 3f430a7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
12 changes: 9 additions & 3 deletions class/openshift4-monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ parameters:
control_plane: https://raw.githubusercontent.com/openshift/cluster-network-operator/${openshift4_monitoring:manifests_version}/bindata/network/ovn-kubernetes/self-hosted/alert-rules-control-plane.yaml
release-4.14:
common: https://raw.githubusercontent.com/openshift/cluster-network-operator/${openshift4_monitoring:manifests_version}/bindata/network/ovn-kubernetes/common/alert-rules.yaml
# We use the "self-hosted" variant of the control-plane alerts, so
# we don't have to worry about unresolved gotemplate references.
control_plane: https://raw.githubusercontent.com/openshift/cluster-network-operator/release-4.13/bindata/network/ovn-kubernetes/self-hosted/alert-rules-control-plane.yaml
# We handle the gotemplate stuff in Jsonnet for now, since Jinja
# can't deal with gotemplate expressions like `{{.OvnkubeMasterReplicas}}`.
# The only templates that are in the alerting rules can be handled
# with a simple string replace.
# By default we use the `multi-zone-interconnect` rules for 4.14,
# since those rules match the rules that are deployed by default
# when selecting OVNKubernetes as the network plugin during
# installation.
control_plane: https://raw.githubusercontent.com/openshift/cluster-network-operator/release-4.14/bindata/network/ovn-kubernetes/self-hosted/multi-zone-interconnect/alert-rules-control-plane.yaml

kapitan:
dependencies:
Expand Down
38 changes: 37 additions & 1 deletion component/rules.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,40 @@ local upstreamManifests = std.flattenArrays(
]
);

// Currently this function can only render the following gotemplate
// expressions:
// * '{{"{{"}}' -> '{{'
// * '{{"}}"}}' -> '}}'
local simpleRenderGoTemplate(groups) =
// We only try to render gotemplates in the rule groups listed in this
// variable.
local rulegroups = [
'cluster-network-operator-master.rules',
'cluster-network-operator-ovn.rules',
];
[
if std.member(rulegroups, g.name) then
g {
rules: [
if std.objectHas(r, 'alert') then
// only try to render templates in alerting rules
r {
annotations+: {
summary: std.strReplace(
std.strReplace(r.annotations.summary, '{{"{{"}}', '{{'), '{{"}}"}}', '}}'
),
},
}
else
r
for r in g.rules
],
}
else
g
for g in groups
];

local additionalRules = {
spec+: {
groups+: [ {
Expand Down Expand Up @@ -84,7 +118,9 @@ local additionalRules = {
function(obj)
if com.getValueOrDefault(obj, 'kind', '') == 'PrometheusRule' then
// handle case for empty PrometheusRule objects
com.getValueOrDefault(obj, 'spec', { groups: [] }).groups
local groups =
com.getValueOrDefault(obj, 'spec', { groups: [] }).groups;
simpleRenderGoTemplate(groups)
else if std.objectHas(obj, 'groups') then
obj.groups
else
Expand Down

0 comments on commit 3f430a7

Please sign in to comment.