mirror of
https://github.com/kyverno/policy-reporter.git
synced 2024-12-14 11:57:32 +00:00
remove labels from deleted reports and rules
This commit is contained in:
parent
a9f9fcd5c9
commit
04c220d3e3
5 changed files with 49 additions and 56 deletions
|
@ -1,4 +1,4 @@
|
||||||
FROM golang:1.16 as builder
|
FROM golang:1.16-buster as builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
|
@ -3,5 +3,5 @@ name: policy-reporter
|
||||||
description: K8s PolicyReporter watches for wgpolicyk8s.io/v1alpha1.PolicyReport resources. It creates Prometheus Metrics and can send rule validation events to Loki
|
description: K8s PolicyReporter watches for wgpolicyk8s.io/v1alpha1.PolicyReport resources. It creates Prometheus Metrics and can send rule validation events to Loki
|
||||||
|
|
||||||
type: application
|
type: application
|
||||||
version: 0.6.0
|
version: 0.6.1
|
||||||
appVersion: 0.5.0
|
appVersion: 0.5.1
|
||||||
|
|
|
@ -15,7 +15,7 @@ metrics:
|
||||||
image:
|
image:
|
||||||
repository: fjogeleit/policy-reporter
|
repository: fjogeleit/policy-reporter
|
||||||
pullPolicy: IfNotPresent
|
pullPolicy: IfNotPresent
|
||||||
tag: 0.5.0
|
tag: 0.5.1
|
||||||
|
|
||||||
imagePullSecrets: []
|
imagePullSecrets: []
|
||||||
|
|
||||||
|
|
|
@ -64,16 +64,14 @@ func (m ClusterPolicyReportMetrics) GenerateMetrics() error {
|
||||||
|
|
||||||
for _, rule := range m.getCachedReport(report.GetIdentifier()).Results {
|
for _, rule := range m.getCachedReport(report.GetIdentifier()).Results {
|
||||||
res := rule.Resources[0]
|
res := rule.Resources[0]
|
||||||
ruleGauge.
|
ruleGauge.DeleteLabelValues(
|
||||||
WithLabelValues(
|
rule.Rule,
|
||||||
rule.Rule,
|
rule.Policy,
|
||||||
rule.Policy,
|
report.Name,
|
||||||
report.Name,
|
res.Kind,
|
||||||
res.Kind,
|
res.Name,
|
||||||
res.Name,
|
rule.Status,
|
||||||
rule.Status,
|
)
|
||||||
).
|
|
||||||
Set(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rule := range report.Results {
|
for _, rule := range report.Results {
|
||||||
|
@ -92,24 +90,22 @@ func (m ClusterPolicyReportMetrics) GenerateMetrics() error {
|
||||||
|
|
||||||
m.cachedReport(report)
|
m.cachedReport(report)
|
||||||
case watch.Deleted:
|
case watch.Deleted:
|
||||||
policyGauge.WithLabelValues(report.Name, "Pass").Set(0)
|
policyGauge.DeleteLabelValues(report.Name, "Pass")
|
||||||
policyGauge.WithLabelValues(report.Name, "Fail").Set(0)
|
policyGauge.DeleteLabelValues(report.Name, "Fail")
|
||||||
policyGauge.WithLabelValues(report.Name, "Warn").Set(0)
|
policyGauge.DeleteLabelValues(report.Name, "Warn")
|
||||||
policyGauge.WithLabelValues(report.Name, "Error").Set(0)
|
policyGauge.DeleteLabelValues(report.Name, "Error")
|
||||||
policyGauge.WithLabelValues(report.Name, "Skip").Set(0)
|
policyGauge.DeleteLabelValues(report.Name, "Skip")
|
||||||
|
|
||||||
for _, rule := range report.Results {
|
for _, rule := range report.Results {
|
||||||
res := rule.Resources[0]
|
res := rule.Resources[0]
|
||||||
ruleGauge.
|
ruleGauge.DeleteLabelValues(
|
||||||
WithLabelValues(
|
rule.Rule,
|
||||||
rule.Rule,
|
rule.Policy,
|
||||||
rule.Policy,
|
report.Name,
|
||||||
report.Name,
|
res.Kind,
|
||||||
res.Kind,
|
res.Name,
|
||||||
res.Name,
|
rule.Status,
|
||||||
rule.Status,
|
)
|
||||||
).
|
|
||||||
Set(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.removeCachedReport(report.GetIdentifier())
|
m.removeCachedReport(report.GetIdentifier())
|
||||||
|
|
|
@ -74,17 +74,15 @@ func (m PolicyReportMetrics) GenerateMetrics() error {
|
||||||
|
|
||||||
for _, rule := range m.getCachedReport(report.GetIdentifier()).Results {
|
for _, rule := range m.getCachedReport(report.GetIdentifier()).Results {
|
||||||
res := rule.Resources[0]
|
res := rule.Resources[0]
|
||||||
ruleGauge.
|
ruleGauge.DeleteLabelValues(
|
||||||
WithLabelValues(
|
report.Namespace,
|
||||||
report.Namespace,
|
rule.Rule,
|
||||||
rule.Rule,
|
rule.Policy,
|
||||||
rule.Policy,
|
report.Name,
|
||||||
report.Name,
|
res.Kind,
|
||||||
res.Kind,
|
res.Name,
|
||||||
res.Name,
|
rule.Status,
|
||||||
rule.Status,
|
)
|
||||||
).
|
|
||||||
Set(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rule := range report.Results {
|
for _, rule := range report.Results {
|
||||||
|
@ -104,25 +102,24 @@ func (m PolicyReportMetrics) GenerateMetrics() error {
|
||||||
|
|
||||||
m.cachedReport(report)
|
m.cachedReport(report)
|
||||||
case watch.Deleted:
|
case watch.Deleted:
|
||||||
policyGauge.WithLabelValues(report.Namespace, report.Name, "Pass").Set(0)
|
policyGauge.DeleteLabelValues(report.Namespace, report.Name, "Pass")
|
||||||
policyGauge.WithLabelValues(report.Namespace, report.Name, "Fail").Set(0)
|
policyGauge.DeleteLabelValues(report.Namespace, report.Name, "Fail")
|
||||||
policyGauge.WithLabelValues(report.Namespace, report.Name, "Warn").Set(0)
|
policyGauge.DeleteLabelValues(report.Namespace, report.Name, "Warn")
|
||||||
policyGauge.WithLabelValues(report.Namespace, report.Name, "Error").Set(0)
|
policyGauge.DeleteLabelValues(report.Namespace, report.Name, "Error")
|
||||||
policyGauge.WithLabelValues(report.Namespace, report.Name, "Skip").Set(0)
|
policyGauge.DeleteLabelValues(report.Namespace, report.Name, "Skip")
|
||||||
|
|
||||||
for _, rule := range report.Results {
|
for _, rule := range report.Results {
|
||||||
res := rule.Resources[0]
|
res := rule.Resources[0]
|
||||||
ruleGauge.
|
|
||||||
WithLabelValues(
|
ruleGauge.DeleteLabelValues(
|
||||||
report.Namespace,
|
report.Namespace,
|
||||||
rule.Rule,
|
rule.Rule,
|
||||||
rule.Policy,
|
rule.Policy,
|
||||||
report.Name,
|
report.Name,
|
||||||
res.Kind,
|
res.Kind,
|
||||||
res.Name,
|
res.Name,
|
||||||
rule.Status,
|
rule.Status,
|
||||||
).
|
)
|
||||||
Set(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.removeCachedReport(report.GetIdentifier())
|
m.removeCachedReport(report.GetIdentifier())
|
||||||
|
|
Loading…
Reference in a new issue