@@ -6,13 +6,16 @@ import (
66 "strings"
77 "sync"
88
9+ lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
910 flowslatest "github.com/netobserv/network-observability-operator/apis/flowcollector/v1beta2"
1011 "github.com/netobserv/network-observability-operator/controllers/constants"
12+ "github.com/netobserv/network-observability-operator/pkg/helper"
1113 appsv1 "k8s.io/api/apps/v1"
1214 v1 "k8s.io/api/core/v1"
1315 kerr "k8s.io/apimachinery/pkg/api/errors"
1416 "k8s.io/apimachinery/pkg/api/meta"
1517 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+ "k8s.io/apimachinery/pkg/types"
1619 "k8s.io/client-go/util/retry"
1720 "sigs.k8s.io/controller-runtime/pkg/client"
1821 "sigs.k8s.io/controller-runtime/pkg/log"
@@ -28,6 +31,7 @@ const (
2831 Monitoring ComponentName = "Monitoring"
2932 NetworkPolicy ComponentName = "NetworkPolicy"
3033 ConditionConfigurationIssue = "ConfigurationIssue"
34+ LokiIssue = "LokiIssue"
3135)
3236
3337var allNames = []ComponentName {FlowCollectorLegacy , Monitoring }
@@ -136,6 +140,7 @@ func updateStatus(ctx context.Context, c client.Client, conditions ...metav1.Con
136140 return err
137141 }
138142 conditions = append (conditions , checkValidation (ctx , & fc ))
143+ conditions = append (conditions , checkLoki (ctx , c , & fc ))
139144 for _ , c := range conditions {
140145 meta .SetStatusCondition (& fc .Status .Conditions , c )
141146 }
@@ -173,6 +178,52 @@ func checkValidation(ctx context.Context, fc *flowslatest.FlowCollector) metav1.
173178 }
174179}
175180
181+ func checkLoki (ctx context.Context , c client.Client , fc * flowslatest.FlowCollector ) metav1.Condition {
182+ if ! helper .UseLoki (& fc .Spec ) {
183+ return metav1.Condition {
184+ Type : LokiIssue ,
185+ Reason : "Unused" ,
186+ Status : metav1 .ConditionUnknown ,
187+ Message : "Loki is disabled" ,
188+ }
189+ }
190+ if fc .Spec .Loki .Mode != flowslatest .LokiModeLokiStack {
191+ return metav1.Condition {
192+ Type : LokiIssue ,
193+ Reason : "Unused" ,
194+ Status : metav1 .ConditionUnknown ,
195+ Message : "Loki is not configured in LokiStack mode" ,
196+ }
197+ }
198+ lokiStack := & lokiv1.LokiStack {}
199+ nsname := types.NamespacedName {Name : fc .Spec .Loki .LokiStack .Name , Namespace : fc .Spec .Namespace }
200+ if len (fc .Spec .Loki .LokiStack .Namespace ) > 0 {
201+ nsname .Namespace = fc .Spec .Loki .LokiStack .Namespace
202+ }
203+ err := c .Get (ctx , nsname , lokiStack )
204+ if err != nil {
205+ if kerr .IsNotFound (err ) {
206+ return metav1.Condition {
207+ Type : LokiIssue ,
208+ Reason : "LokiStackNotFound" ,
209+ Status : metav1 .ConditionTrue ,
210+ Message : fmt .Sprintf ("The configured LokiStack reference could not be found [name: %s, namespace: %s]" , nsname .Name , nsname .Namespace ),
211+ }
212+ }
213+ return metav1.Condition {
214+ Type : LokiIssue ,
215+ Reason : "Error" ,
216+ Status : metav1 .ConditionTrue ,
217+ Message : fmt .Sprintf ("Error while fetching configured LokiStack: %s" , err .Error ()),
218+ }
219+ }
220+ return metav1.Condition {
221+ Type : LokiIssue ,
222+ Reason : "NoIssue" ,
223+ Status : metav1 .ConditionFalse ,
224+ }
225+ }
226+
176227func (s * Manager ) ForComponent (cpnt ComponentName ) Instance {
177228 return Instance {cpnt : cpnt , s : s }
178229}
0 commit comments