Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OVNKubernetes alert rules for OpenShift 4.14 #197

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading