Skip to content

Commit 83dfca7

Browse files
authored
Merge pull request #1542 from kube-logging/loggingroute-logging-problems
Updates in logging status problems for usability
2 parents 31c2a4b + 7ca6841 commit 83dfca7

File tree

4 files changed

+74
-62
lines changed

4 files changed

+74
-62
lines changed

controllers/logging/logging_controller.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,14 @@ func (r *LoggingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
219219
logging.Spec.FluentbitSpec,
220220
loggingDataProvider,
221221
nameProvider,
222-
nil,
222+
nil, // Not implemented for the embedded fluentbit config
223223
).Reconcile)
224224
}
225225
default:
226226
if logging.Spec.FluentbitSpec != nil {
227227
return ctrl.Result{}, errors.New("fluentbit has to be removed from the logging resource before the new FluentbitAgent can be reconciled")
228228
}
229229
l := log.WithName("fluentbit")
230-
aps, err := r.loggingRoutes(ctx, logging.Name)
231-
if err != nil {
232-
return ctrl.Result{}, err
233-
}
234230
for _, f := range loggingResources.Fluentbits {
235231
f := f
236232
reconcilers = append(reconcilers, fluentbit.New(
@@ -241,7 +237,7 @@ func (r *LoggingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
241237
&f.Spec,
242238
loggingDataProvider,
243239
fluentbit.NewStandaloneFluentbitNameProvider(&f),
244-
aps,
240+
loggingResources.LoggingRoutes,
245241
).Reconcile)
246242
}
247243
}
@@ -278,21 +274,6 @@ func (r *LoggingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
278274
return ctrl.Result{}, nil
279275
}
280276

281-
func (r *LoggingReconciler) loggingRoutes(ctx context.Context, logging string) (aps []loggingv1beta1.LoggingRoute, err error) {
282-
apList := &loggingv1beta1.LoggingRouteList{}
283-
err = r.Client.List(ctx, apList)
284-
if err != nil {
285-
err = errors.WrapIf(err, "listing logging routes")
286-
return
287-
}
288-
for _, ap := range apList.Items {
289-
if ap.Spec.Source == logging {
290-
aps = append(aps, ap)
291-
}
292-
}
293-
return
294-
}
295-
296277
func (r *LoggingReconciler) dynamicDefaults(ctx context.Context, log logr.Logger, logging loggingv1beta1.Logging) {
297278
nodes := corev1.NodeList{}
298279
if err := r.Client.List(ctx, &nodes); err != nil {

pkg/resources/model/reconciler.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,17 @@ func NewValidationReconciler(
204204
}
205205

206206
registerForPatching(&resources.Logging)
207+
resources.Logging.Status.Problems = nil
208+
resources.Logging.Status.WatchNamespaces = nil
207209

208210
if !resources.Logging.WatchAllNamespaces() {
209211
resources.Logging.Status.WatchNamespaces = resources.WatchNamespaces
210212
}
211-
resources.Logging.Status.Problems = nil
213+
214+
if resources.Logging.Spec.WatchNamespaceSelector != nil &&
215+
len(resources.Logging.Status.WatchNamespaces) == 0 {
216+
resources.Logging.Status.Problems = append(resources.Logging.Status.Problems, "Defined watchNamespaceSelector did not match any namespaces")
217+
}
212218

213219
loggingsForTheSameRef := make([]string, 0)
214220
for _, l := range resources.AllLoggings {
@@ -257,6 +263,11 @@ func NewValidationReconciler(
257263
}
258264
}
259265
}
266+
267+
if resources.Logging.Spec.FluentbitSpec != nil && len(resources.LoggingRoutes) > 0 {
268+
resources.Logging.Status.Problems = append(resources.Logging.Status.Problems, "Logging routes are not supported for embedded fluentbit configs, please use a separate FluentbitAgent resource!")
269+
}
270+
260271
slices.Sort(resources.Logging.Status.Problems)
261272
resources.Logging.Status.ProblemsCount = len(resources.Logging.Status.Problems)
262273

pkg/resources/model/repository.go

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ func (r LoggingResourceRepository) LoggingResourcesFor(ctx context.Context, logg
6969
res.Fluentbits, err = r.FluentbitsFor(ctx, logging)
7070
errs = errors.Append(errs, err)
7171

72+
res.LoggingRoutes, err = r.LoggingRoutesFor(ctx, logging)
73+
errs = errors.Append(errs, err)
74+
7275
res.WatchNamespaces, err = UniqueWatchNamespaces(ctx, r.Client, &logging)
7376
if err != nil {
7477
errs = errors.Append(errs, err)
@@ -145,16 +148,17 @@ func (r LoggingResourceRepository) ClusterFlowsFor(ctx context.Context, logging
145148
return nil, err
146149
}
147150

148-
sort.Slice(list.Items, func(i, j int) bool {
149-
return lessByNamespacedName(&list.Items[i], &list.Items[j])
150-
})
151-
152151
var res []v1beta1.ClusterFlow
153152
for _, i := range list.Items {
154153
if i.Spec.LoggingRef == logging.Spec.LoggingRef {
155154
res = append(res, i)
156155
}
157156
}
157+
158+
sort.Slice(res, func(i, j int) bool {
159+
return lessByNamespacedName(&res[i], &res[j])
160+
})
161+
158162
return res, nil
159163
}
160164

@@ -164,16 +168,17 @@ func (r LoggingResourceRepository) ClusterOutputsFor(ctx context.Context, loggin
164168
return nil, err
165169
}
166170

167-
sort.Slice(list.Items, func(i, j int) bool {
168-
return lessByNamespacedName(&list.Items[i], &list.Items[j])
169-
})
170-
171171
var res []v1beta1.ClusterOutput
172172
for _, i := range list.Items {
173173
if i.Spec.LoggingRef == logging.Spec.LoggingRef {
174174
res = append(res, i)
175175
}
176176
}
177+
178+
sort.Slice(res, func(i, j int) bool {
179+
return lessByNamespacedName(&res[i], &res[j])
180+
})
181+
177182
return res, nil
178183
}
179184

@@ -183,16 +188,17 @@ func (r LoggingResourceRepository) FlowsInNamespaceFor(ctx context.Context, name
183188
return nil, err
184189
}
185190

186-
sort.Slice(list.Items, func(i, j int) bool {
187-
return lessByNamespacedName(&list.Items[i], &list.Items[j])
188-
})
189-
190191
var res []v1beta1.Flow
191192
for _, i := range list.Items {
192193
if i.Spec.LoggingRef == logging.Spec.LoggingRef {
193194
res = append(res, i)
194195
}
195196
}
197+
198+
sort.Slice(res, func(i, j int) bool {
199+
return lessByNamespacedName(&res[i], &res[j])
200+
})
201+
196202
return res, nil
197203
}
198204

@@ -202,16 +208,16 @@ func (r LoggingResourceRepository) OutputsInNamespaceFor(ctx context.Context, na
202208
return nil, err
203209
}
204210

205-
sort.Slice(list.Items, func(i, j int) bool {
206-
return lessByNamespacedName(&list.Items[i], &list.Items[j])
207-
})
208-
209211
var res []v1beta1.Output
210212
for _, i := range list.Items {
211213
if i.Spec.LoggingRef == logging.Spec.LoggingRef {
212214
res = append(res, i)
213215
}
214216
}
217+
218+
sort.Slice(res, func(i, j int) bool {
219+
return lessByNamespacedName(&res[i], &res[j])
220+
})
215221
return res, nil
216222
}
217223

@@ -221,16 +227,16 @@ func (r LoggingResourceRepository) SyslogNGClusterFlowsFor(ctx context.Context,
221227
return nil, err
222228
}
223229

224-
sort.Slice(list.Items, func(i, j int) bool {
225-
return lessByNamespacedName(&list.Items[i], &list.Items[j])
226-
})
227-
228230
var res []v1beta1.SyslogNGClusterFlow
229231
for _, i := range list.Items {
230232
if i.Spec.LoggingRef == logging.Spec.LoggingRef {
231233
res = append(res, i)
232234
}
233235
}
236+
237+
sort.Slice(res, func(i, j int) bool {
238+
return lessByNamespacedName(&res[i], &res[j])
239+
})
234240
return res, nil
235241
}
236242

@@ -240,16 +246,15 @@ func (r LoggingResourceRepository) SyslogNGClusterOutputsFor(ctx context.Context
240246
return nil, err
241247
}
242248

243-
sort.Slice(list.Items, func(i, j int) bool {
244-
return lessByNamespacedName(&list.Items[i], &list.Items[j])
245-
})
246-
247249
var res []v1beta1.SyslogNGClusterOutput
248250
for _, i := range list.Items {
249251
if i.Spec.LoggingRef == logging.Spec.LoggingRef {
250252
res = append(res, i)
251253
}
252254
}
255+
sort.Slice(res, func(i, j int) bool {
256+
return lessByNamespacedName(&res[i], &res[j])
257+
})
253258
return res, nil
254259
}
255260

@@ -259,16 +264,15 @@ func (r LoggingResourceRepository) SyslogNGFlowsInNamespaceFor(ctx context.Conte
259264
return nil, err
260265
}
261266

262-
sort.Slice(list.Items, func(i, j int) bool {
263-
return lessByNamespacedName(&list.Items[i], &list.Items[j])
264-
})
265-
266267
var res []v1beta1.SyslogNGFlow
267268
for _, i := range list.Items {
268269
if i.Spec.LoggingRef == logging.Spec.LoggingRef {
269270
res = append(res, i)
270271
}
271272
}
273+
sort.Slice(res, func(i, j int) bool {
274+
return lessByNamespacedName(&res[i], &res[j])
275+
})
272276
return res, nil
273277
}
274278

@@ -278,16 +282,15 @@ func (r LoggingResourceRepository) SyslogNGOutputsInNamespaceFor(ctx context.Con
278282
return nil, err
279283
}
280284

281-
sort.Slice(list.Items, func(i, j int) bool {
282-
return lessByNamespacedName(&list.Items[i], &list.Items[j])
283-
})
284-
285285
var res []v1beta1.SyslogNGOutput
286286
for _, i := range list.Items {
287287
if i.Spec.LoggingRef == logging.Spec.LoggingRef {
288288
res = append(res, i)
289289
}
290290
}
291+
sort.Slice(res, func(i, j int) bool {
292+
return lessByNamespacedName(&res[i], &res[j])
293+
})
291294
return res, nil
292295
}
293296

@@ -302,16 +305,15 @@ func (r LoggingResourceRepository) NodeAgentsFor(ctx context.Context, logging v1
302305
return nil, err
303306
}
304307

305-
sort.Slice(list.Items, func(i, j int) bool {
306-
return lessByNamespacedName(&list.Items[i], &list.Items[j])
307-
})
308-
309308
var res []v1beta1.NodeAgent
310309
for _, i := range list.Items {
311310
if i.Spec.LoggingRef == logging.Spec.LoggingRef {
312311
res = append(res, i)
313312
}
314313
}
314+
sort.Slice(res, func(i, j int) bool {
315+
return lessByNamespacedName(&res[i], &res[j])
316+
})
315317
return res, nil
316318
}
317319

@@ -321,16 +323,33 @@ func (r LoggingResourceRepository) FluentbitsFor(ctx context.Context, logging v1
321323
return nil, err
322324
}
323325

324-
sort.Slice(list.Items, func(i, j int) bool {
325-
return lessByNamespacedName(&list.Items[i], &list.Items[j])
326-
})
327-
328326
var res []v1beta1.FluentbitAgent
329327
for _, i := range list.Items {
330328
if i.Spec.LoggingRef == logging.Spec.LoggingRef {
331329
res = append(res, i)
332330
}
333331
}
332+
sort.Slice(res, func(i, j int) bool {
333+
return lessByNamespacedName(&res[i], &res[j])
334+
})
335+
return res, nil
336+
}
337+
338+
func (r LoggingResourceRepository) LoggingRoutesFor(ctx context.Context, logging v1beta1.Logging) ([]v1beta1.LoggingRoute, error) {
339+
var list v1beta1.LoggingRouteList
340+
if err := r.Client.List(ctx, &list); err != nil {
341+
return nil, err
342+
}
343+
344+
var res []v1beta1.LoggingRoute
345+
for _, i := range list.Items {
346+
if i.Spec.Source == logging.Spec.LoggingRef {
347+
res = append(res, i)
348+
}
349+
}
350+
sort.Slice(res, func(i, j int) bool {
351+
return lessByNamespacedName(&res[i], &res[j])
352+
})
334353
return res, nil
335354
}
336355

pkg/resources/model/resources.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type LoggingResources struct {
2525
SyslogNG SyslogNGLoggingResources
2626
NodeAgents []v1beta1.NodeAgent
2727
Fluentbits []v1beta1.FluentbitAgent
28+
LoggingRoutes []v1beta1.LoggingRoute
2829
WatchNamespaces []string
2930
}
3031

0 commit comments

Comments
 (0)