Skip to content

Commit 6fd8801

Browse files
authored
Merge pull request #1665 from kube-logging/fix-fluentbit-tenants-detached-aggregator
fix to make detached aggregators work when generating fluentbit tenants
2 parents b2f6253 + 5ffa49f commit 6fd8801

File tree

5 files changed

+43
-38
lines changed

5 files changed

+43
-38
lines changed

controllers/logging/logging_controller.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,11 @@ func (r *LoggingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
218218
r.Client,
219219
log.WithName("fluentbit-legacy"),
220220
&logging,
221-
fluentdSpec,
222-
syslogNGSpec,
223221
reconcilerOpts,
224222
logging.Spec.FluentbitSpec,
225223
loggingDataProvider,
226224
nameProvider,
227-
nil, // Not implemented for the embedded fluentbit config
225+
loggingResourceRepo,
228226
).Reconcile)
229227
}
230228
default:
@@ -238,13 +236,11 @@ func (r *LoggingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
238236
r.Client,
239237
l.WithValues("fluentbitagent", f.Name),
240238
&logging,
241-
fluentdSpec,
242-
syslogNGSpec,
243239
reconcilerOpts,
244240
&f.Spec,
245241
loggingDataProvider,
246242
fluentbit.NewStandaloneFluentbitNameProvider(&f),
247-
loggingResources.LoggingRoutes,
243+
loggingResourceRepo,
248244
).Reconcile)
249245
}
250246
}

pkg/resources/fluentbit/configsecret.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,14 @@ func (r *Reconciler) configSecret() (runtime.Object, reconciler.DesiredState, er
238238
}
239239
}
240240

241-
if r.fluentdSpec != nil {
241+
loggingResources, errs := r.loggingResourcesRepo.LoggingResourcesFor(ctx, *r.Logging)
242+
if errs != nil {
243+
return nil, nil, errs
244+
}
245+
246+
fluentdSpec := loggingResources.GetFluentdSpec()
247+
248+
if fluentdSpec != nil {
242249
fluentbitTargetHost := r.fluentbitSpec.TargetHost
243250
if fluentbitTargetHost == "" {
244251
fluentbitTargetHost = aggregatorEndpoint(r.Logging, fluentd.ServiceName)
@@ -354,15 +361,15 @@ func (r *Reconciler) configSecret() (runtime.Object, reconciler.DesiredState, er
354361
}
355362
}
356363

357-
if r.syslogNGSpec != nil {
364+
if loggingResources.GetSyslogNGSpec() != nil {
358365
input.SyslogNGOutput = newSyslogNGOutputConfig()
359366
input.SyslogNGOutput.Host = aggregatorEndpoint(r.Logging, syslogng.ServiceName)
360367
input.SyslogNGOutput.Port = syslogng.ServicePort
361368
}
362369

363-
if len(r.loggingRoutes) > 0 {
370+
if len(loggingResources.LoggingRoutes) > 0 {
364371
var tenants []v1beta1.Tenant
365-
for _, a := range r.loggingRoutes {
372+
for _, a := range loggingResources.LoggingRoutes {
366373
tenants = append(tenants, a.Status.Tenants...)
367374
}
368375
if err := r.configureOutputsForTenants(ctx, tenants, &input); err != nil {

pkg/resources/fluentbit/fluentbit.go

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"k8s.io/apimachinery/pkg/runtime"
2424

2525
"github.com/kube-logging/logging-operator/pkg/resources/loggingdataprovider"
26+
"github.com/kube-logging/logging-operator/pkg/resources/model"
2627

2728
"github.com/cisco-open/operator-tools/pkg/reconciler"
2829
util "github.com/cisco-open/operator-tools/pkg/utils"
@@ -87,39 +88,33 @@ type DesiredObject struct {
8788

8889
// Reconciler holds info what resource to reconcile
8990
type Reconciler struct {
90-
resourceReconciler *reconciler.GenericResourceReconciler
91-
logger logr.Logger
92-
Logging *v1beta1.Logging
93-
fluentdSpec *v1beta1.FluentdSpec
94-
syslogNGSpec *v1beta1.SyslogNGSpec
95-
configs map[string][]byte
96-
fluentbitSpec *v1beta1.FluentbitSpec
97-
loggingDataProvider loggingdataprovider.LoggingDataProvider
98-
nameProvider NameProvider
99-
loggingRoutes []v1beta1.LoggingRoute
91+
resourceReconciler *reconciler.GenericResourceReconciler
92+
logger logr.Logger
93+
Logging *v1beta1.Logging
94+
configs map[string][]byte
95+
fluentbitSpec *v1beta1.FluentbitSpec
96+
loggingDataProvider loggingdataprovider.LoggingDataProvider
97+
nameProvider NameProvider
98+
loggingResourcesRepo *model.LoggingResourceRepository
10099
}
101100

102101
// NewReconciler creates a new FluentbitAgent reconciler
103102
func New(client client.Client,
104103
logger logr.Logger,
105104
logging *v1beta1.Logging,
106-
fluentdSpec *v1beta1.FluentdSpec,
107-
syslogNGSpec *v1beta1.SyslogNGSpec,
108105
opts reconciler.ReconcilerOpts,
109106
fluentbitSpec *v1beta1.FluentbitSpec,
110107
loggingDataProvider loggingdataprovider.LoggingDataProvider,
111108
nameProvider NameProvider,
112-
loggingRoutes []v1beta1.LoggingRoute) *Reconciler {
109+
loggingResourcesRepo *model.LoggingResourceRepository) *Reconciler {
113110
return &Reconciler{
114-
Logging: logging,
115-
fluentdSpec: fluentdSpec,
116-
syslogNGSpec: syslogNGSpec,
117-
logger: logger,
118-
resourceReconciler: reconciler.NewGenericReconciler(client, logger.WithName("reconciler"), opts),
119-
fluentbitSpec: fluentbitSpec,
120-
loggingDataProvider: loggingDataProvider,
121-
nameProvider: nameProvider,
122-
loggingRoutes: loggingRoutes,
111+
Logging: logging,
112+
logger: logger,
113+
resourceReconciler: reconciler.NewGenericReconciler(client, logger.WithName("reconciler"), opts),
114+
fluentbitSpec: fluentbitSpec,
115+
loggingDataProvider: loggingDataProvider,
116+
nameProvider: nameProvider,
117+
loggingResourcesRepo: loggingResourcesRepo,
123118
}
124119
}
125120

pkg/resources/fluentbit/tenants.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ func (r *Reconciler) configureOutputsForTenants(ctx context.Context, tenants []v
100100
if err := r.resourceReconciler.Client.Get(ctx, types.NamespacedName{Name: t.Name}, logging); err != nil {
101101
return errors.WrapIf(err, "getting logging resource")
102102
}
103-
if logging.Spec.FluentdSpec != nil {
103+
104+
loggingResources, err := r.loggingResourcesRepo.LoggingResourcesFor(ctx, *logging)
105+
if err != nil {
106+
errs = errors.Append(errs, errors.WrapIff(err, "querying related resources for logging %s", logging.Name))
107+
continue
108+
}
109+
110+
if loggingResources.GetFluentdSpec() != nil {
104111
if input.FluentForwardOutput == nil {
105112
input.FluentForwardOutput = &fluentForwardOutputConfig{}
106113
}
@@ -110,7 +117,7 @@ func (r *Reconciler) configureOutputsForTenants(ctx context.Context, tenants []v
110117
Host: aggregatorEndpoint(logging, fluentd.ServiceName),
111118
Port: fluentd.ServicePort,
112119
})
113-
} else if logging.Spec.SyslogNGSpec != nil {
120+
} else if loggingResources.GetSyslogNGSpec() != nil {
114121
if input.SyslogNGOutput == nil {
115122
input.SyslogNGOutput = newSyslogNGOutputConfig()
116123
}

pkg/resources/model/resources.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type LoggingResources struct {
2929
WatchNamespaces []string
3030
}
3131

32-
func (l LoggingResources) GetFluentd() *v1beta1.FluentdConfig {
32+
func (l LoggingResources) getFluentd() *v1beta1.FluentdConfig {
3333
if l.Fluentd.Configuration != nil {
3434
return l.Fluentd.Configuration
3535
}
@@ -38,7 +38,7 @@ func (l LoggingResources) GetFluentd() *v1beta1.FluentdConfig {
3838

3939
func (l LoggingResources) GetFluentdSpec() *v1beta1.FluentdSpec {
4040

41-
if detachedFluentd := l.GetFluentd(); detachedFluentd != nil {
41+
if detachedFluentd := l.getFluentd(); detachedFluentd != nil {
4242
return &detachedFluentd.Spec
4343
}
4444
if l.Logging.Spec.FluentdSpec != nil {
@@ -57,7 +57,7 @@ type FluentdLoggingResources struct {
5757
ExcessFluentds []v1beta1.FluentdConfig
5858
}
5959

60-
func (l LoggingResources) GetSyslogNG() *v1beta1.SyslogNGConfig {
60+
func (l LoggingResources) getSyslogNG() *v1beta1.SyslogNGConfig {
6161
if l.SyslogNG.Configuration != nil {
6262
return l.SyslogNG.Configuration
6363
}
@@ -66,7 +66,7 @@ func (l LoggingResources) GetSyslogNG() *v1beta1.SyslogNGConfig {
6666

6767
func (l LoggingResources) GetSyslogNGSpec() *v1beta1.SyslogNGSpec {
6868

69-
if detachedSyslogNG := l.GetSyslogNG(); detachedSyslogNG != nil {
69+
if detachedSyslogNG := l.getSyslogNG(); detachedSyslogNG != nil {
7070
return &detachedSyslogNG.Spec
7171
}
7272
if l.Logging.Spec.SyslogNGSpec != nil {

0 commit comments

Comments
 (0)