mirror of https://github.com/grafana/loki
operator: Use cluster monitoring alertmanager by default on openshift clusters (#7272)
parent
6bf5b5d8c1
commit
4103b32d0a
@ -0,0 +1,30 @@ |
||||
package openshift |
||||
|
||||
import ( |
||||
"context" |
||||
|
||||
"github.com/ViaQ/logerr/v2/kverrors" |
||||
lokiv1 "github.com/grafana/loki/operator/apis/loki/v1" |
||||
"github.com/grafana/loki/operator/internal/external/k8s" |
||||
"github.com/grafana/loki/operator/internal/manifests/openshift" |
||||
corev1 "k8s.io/api/core/v1" |
||||
apierrors "k8s.io/apimachinery/pkg/api/errors" |
||||
"sigs.k8s.io/controller-runtime/pkg/client" |
||||
) |
||||
|
||||
// AlertManagerSVCExists returns true if the Openshift AlertManager is present in the cluster.
|
||||
func AlertManagerSVCExists(ctx context.Context, stack lokiv1.LokiStackSpec, k k8s.Client) (bool, error) { |
||||
if stack.Tenants == nil || (stack.Tenants.Mode != lokiv1.OpenshiftLogging && stack.Tenants.Mode != lokiv1.OpenshiftNetwork) { |
||||
return false, nil |
||||
} |
||||
|
||||
var svc corev1.Service |
||||
key := client.ObjectKey{Name: openshift.MonitoringSVCOperated, Namespace: openshift.MonitoringNS} |
||||
|
||||
err := k.Get(ctx, key, &svc) |
||||
if err != nil && !apierrors.IsNotFound(err) { |
||||
return false, kverrors.Wrap(err, "failed to lookup alertmanager service", "name", key) |
||||
} |
||||
|
||||
return err == nil, nil |
||||
} |
Loading…
Reference in new issue