monitoring: only set prometheus rules ownerref in same namespace

The ownerref of the prometheus rules should not be set if in
a different namespace than the cluster CR.

Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
This commit is contained in:
Travis Nielsen committed 2022-04-08 13:36:36 -06:00
1 parent c30086c2a0
commit 778daef68c
1 file changed
+6 -3
+6 -3
View File
@@ -523,9 +523,12 @@ func (c *Cluster) DeployPrometheusRule(name, namespace string) error {
}
prometheusRule.SetName(name)
prometheusRule.SetNamespace(namespace)
err = c.clusterInfo.OwnerInfo.SetControllerReference(prometheusRule)
if err != nil {
return errors.Wrapf(err, "failed to set owner reference to prometheus rule %q", prometheusRule.Name)
if namespace == c.clusterInfo.Namespace {
// only set the ownerref if in the same namespace
err = c.clusterInfo.OwnerInfo.SetControllerReference(prometheusRule)
if err != nil {
return errors.Wrapf(err, "failed to set owner reference to prometheus rule %q", prometheusRule.Name)
}
}
cephv1.GetMonitoringLabels(c.spec.Labels).OverwriteApplyToObjectMeta(&prometheusRule.ObjectMeta)
if _, err := k8sutil.CreateOrUpdatePrometheusRule(c.clusterInfo.Context, prometheusRule); err != nil {