@@ -131,28 +131,47 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
131131 // gpr acts as a global resource to store the related plugin resources
132132 gpr := fluentdv1alpha1 .NewGlobalPluginResources ("main" )
133133
134- // Each cluster/namespace scope fluentd configs will generate their own filters/outputs plugins with their own cfgId/cfgLabel,
134+ // Each cluster/namespace scope fluentd configs will generate their own filters/outputs plugins
135+ // with their own cfgId/cfgLabel,
135136 // and they will finally be combined into one fluentd config file
136137 gpr .CombineGlobalInputsPlugins (sl , fd .Spec .GlobalInputs )
137138
138139 // Default Output and filter
139140 // list all namespaced CRs
140- inputs , filters , outputs , err := r .ListNamespacedLevelResources (ctx , fd .Namespace , fd .Spec .DefaultInputSelector , fd .Spec .DefaultFilterSelector , fd .Spec .DefaultOutputSelector )
141+ inputs , filters , outputs , err := r .ListNamespacedLevelResources (
142+ ctx ,
143+ fd .Namespace ,
144+ fd .Spec .DefaultInputSelector ,
145+ fd .Spec .DefaultFilterSelector ,
146+ fd .Spec .DefaultOutputSelector ,
147+ )
141148 if err != nil {
142149 r .Log .Info ("List namespace level resources failed" , "config" , "default" , "err" , err .Error ())
143150 return ctrl.Result {}, err
144151 }
145152 if len (inputs ) > 0 || len (filters ) > 0 || len (outputs ) > 0 {
146153 // Combine the namespaced filter/output pluginstores in this fluentd config
147- cfgResouces , errs := gpr .PatchAndFilterNamespacedLevelResources (sl , fmt .Sprintf ("%s-%s-%s" , fd .Kind , fd .Namespace , fd .Name ), inputs , filters , outputs )
154+ cfgResouces , errs := gpr .PatchAndFilterNamespacedLevelResources (
155+ sl ,
156+ fmt .Sprintf ("%s-%s-%s" , fd .Kind , fd .Namespace , fd .Name ),
157+ inputs ,
158+ filters ,
159+ outputs ,
160+ )
148161 if len (errs ) > 0 {
149162 r .Log .Info ("Patch and filter namespace level resources failed" , "config" , "default" , "err" , strings .Join (errs , "," ))
150163 return ctrl.Result {}, errors .New (strings .Join (errs , "," ))
151164 }
152165
153166 err = gpr .IdentifyCopyAndPatchOutput (cfgResouces )
154167 if err != nil {
155- r .Log .Info ("IdentifyCopy and PatchOutput namespace level resources failed" , "config" , "default" , "err" , strings .Join (errs , "," ))
168+ r .Log .Info (
169+ "IdentifyCopy and PatchOutput namespace level resources failed" ,
170+ "config" ,
171+ "default" ,
172+ "err" ,
173+ strings .Join (errs , "," ),
174+ )
156175 return ctrl.Result {}, errors .New (strings .Join (errs , "," ))
157176 }
158177
@@ -246,7 +265,15 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
246265 return ctrl.Result {}, err
247266 }
248267
249- r .Log .Info ("Fluentd main configuration has updated" , "logging-control-plane" , fd .Namespace , "fd" , fd .Name , "secret" , secName )
268+ r .Log .Info (
269+ "Fluentd main configuration has updated" ,
270+ "logging-control-plane" ,
271+ fd .Namespace ,
272+ "fd" ,
273+ fd .Name ,
274+ "secret" ,
275+ secName ,
276+ )
250277 }
251278
252279 return ctrl.Result {}, nil
@@ -287,7 +314,12 @@ func (r *FluentdConfigReconciler) ClusterCfgsForFluentd(
287314 }
288315
289316 // list all cluster CRs
290- clusterInputs , clusterfilters , clusteroutputs , err := r .ListClusterLevelResources (ctx , cfg .Spec .ClusterInputSelector , cfg .Spec .ClusterFilterSelector , cfg .Spec .ClusterOutputSelector )
317+ clusterInputs , clusterfilters , clusteroutputs , err := r .ListClusterLevelResources (
318+ ctx ,
319+ cfg .Spec .ClusterInputSelector ,
320+ cfg .Spec .ClusterFilterSelector ,
321+ cfg .Spec .ClusterOutputSelector ,
322+ )
291323 if err != nil {
292324 r .Log .Info ("List cluster level resources failed" , "config" , cfg .Name , "err" , err .Error ())
293325 if err = r .PatchObjects (ctx , & cfg , fluentdv1alpha1 .InvalidState , err .Error ()); err != nil {
@@ -298,7 +330,13 @@ func (r *FluentdConfigReconciler) ClusterCfgsForFluentd(
298330 }
299331
300332 // Combine the filter/output pluginstores in this fluentd config
301- cfgResouces , errs := gpr .PatchAndFilterClusterLevelResources (sl , cfg .GetCfgId (), clusterInputs , clusterfilters , clusteroutputs )
333+ cfgResouces , errs := gpr .PatchAndFilterClusterLevelResources (
334+ sl ,
335+ cfg .GetCfgId (),
336+ clusterInputs ,
337+ clusterfilters ,
338+ clusteroutputs ,
339+ )
302340 if len (errs ) > 0 {
303341 r .Log .Info ("Patch and filter cluster level resources failed" , "config" , cfg .Name , "err" , strings .Join (errs , "," ))
304342 if err = r .PatchObjects (ctx , & cfg , fluentdv1alpha1 .InvalidState , strings .Join (errs , ", " )); err != nil {
@@ -336,8 +374,13 @@ func (r *FluentdConfigReconciler) ClusterCfgsForFluentd(
336374}
337375
338376// CfgsForFluentd combines all namespaced cfgs selected by this fd
339- func (r * FluentdConfigReconciler ) CfgsForFluentd (ctx context.Context , cfgs fluentdv1alpha1.FluentdConfigList , sl plugins.SecretLoader ,
340- gpr * fluentdv1alpha1.PluginResources , globalCfgLabels map [string ]bool ) error {
377+ func (r * FluentdConfigReconciler ) CfgsForFluentd (
378+ ctx context.Context ,
379+ cfgs fluentdv1alpha1.FluentdConfigList ,
380+ sl plugins.SecretLoader ,
381+ gpr * fluentdv1alpha1.PluginResources ,
382+ globalCfgLabels map [string ]bool ,
383+ ) error {
341384
342385 for _ , cfg := range cfgs .Items {
343386 // Build the inner router for this cfg and append it to the MainRouter
@@ -363,7 +406,12 @@ func (r *FluentdConfigReconciler) CfgsForFluentd(ctx context.Context, cfgs fluen
363406 }
364407
365408 // list all cluster CRs
366- clusterInputs , clusterfilters , clusteroutputs , err := r .ListClusterLevelResources (ctx , cfg .Spec .ClusterInputSelector , cfg .Spec .ClusterFilterSelector , cfg .Spec .ClusterOutputSelector )
409+ clusterInputs , clusterfilters , clusteroutputs , err := r .ListClusterLevelResources (
410+ ctx ,
411+ cfg .Spec .ClusterInputSelector ,
412+ cfg .Spec .ClusterFilterSelector ,
413+ cfg .Spec .ClusterOutputSelector ,
414+ )
367415 if err != nil {
368416 r .Log .Info ("List cluster level resources failed" , "config" , cfg .Name , "err" , err .Error ())
369417 if err = r .PatchObjects (ctx , & cfg , fluentdv1alpha1 .InvalidState , err .Error ()); err != nil {
@@ -374,7 +422,13 @@ func (r *FluentdConfigReconciler) CfgsForFluentd(ctx context.Context, cfgs fluen
374422 }
375423
376424 // list all namespaced CRs
377- inputs , filters , outputs , err := r .ListNamespacedLevelResources (ctx , cfg .Namespace , cfg .Spec .InputSelector , cfg .Spec .FilterSelector , cfg .Spec .OutputSelector )
425+ inputs , filters , outputs , err := r .ListNamespacedLevelResources (
426+ ctx ,
427+ cfg .Namespace ,
428+ cfg .Spec .InputSelector ,
429+ cfg .Spec .FilterSelector ,
430+ cfg .Spec .OutputSelector ,
431+ )
378432 if err != nil {
379433 r .Log .Info ("List namespace level resources failed" , "config" , cfg .Name , "err" , err .Error ())
380434 if err = r .PatchObjects (ctx , & cfg , fluentdv1alpha1 .InvalidState , err .Error ()); err != nil {
@@ -385,7 +439,13 @@ func (r *FluentdConfigReconciler) CfgsForFluentd(ctx context.Context, cfgs fluen
385439 }
386440
387441 // Combine the cluster input/filter/output pluginstores in this fluentd config
388- clustercfgResouces , errs := gpr .PatchAndFilterClusterLevelResources (sl , cfg .GetCfgId (), clusterInputs , clusterfilters , clusteroutputs )
442+ clustercfgResouces , errs := gpr .PatchAndFilterClusterLevelResources (
443+ sl ,
444+ cfg .GetCfgId (),
445+ clusterInputs ,
446+ clusterfilters ,
447+ clusteroutputs ,
448+ )
389449 if len (errs ) > 0 {
390450 r .Log .Info ("Patch and filter cluster level resources failed" , "config" , cfg .Name , "err" , strings .Join (errs , "," ))
391451 if err = r .PatchObjects (ctx , & cfg , fluentdv1alpha1 .InvalidState , strings .Join (errs , ", " )); err != nil {
@@ -533,7 +593,8 @@ func (r *FluentdConfigReconciler) ListNamespacedLevelResources(
533593 if err != nil {
534594 return nil , nil , nil , err
535595 }
536- if err = r .List (ctx , & inputs , client .InNamespace (namespace ), client.MatchingLabelsSelector {Selector : selector }); err != nil {
596+ matchingLabelSelector := client.MatchingLabelsSelector {Selector : selector }
597+ if err = r .List (ctx , & inputs , client .InNamespace (namespace ), matchingLabelSelector ); err != nil {
537598 return nil , nil , nil , err
538599 }
539600 }
@@ -545,7 +606,8 @@ func (r *FluentdConfigReconciler) ListNamespacedLevelResources(
545606 if err != nil {
546607 return nil , nil , nil , err
547608 }
548- if err = r .List (ctx , & filters , client .InNamespace (namespace ), client.MatchingLabelsSelector {Selector : selector }); err != nil {
609+ matchingLabelSelector := client.MatchingLabelsSelector {Selector : selector }
610+ if err = r .List (ctx , & inputs , client .InNamespace (namespace ), matchingLabelSelector ); err != nil {
549611 return nil , nil , nil , err
550612 }
551613 }
@@ -557,7 +619,8 @@ func (r *FluentdConfigReconciler) ListNamespacedLevelResources(
557619 if err != nil {
558620 return nil , nil , nil , err
559621 }
560- if err = r .List (ctx , & outputs , client .InNamespace (namespace ), client.MatchingLabelsSelector {Selector : selector }); err != nil {
622+ matchingLabelSelector := client.MatchingLabelsSelector {Selector : selector }
623+ if err = r .List (ctx , & inputs , client .InNamespace (namespace ), matchingLabelSelector ); err != nil {
561624 return nil , nil , nil , err
562625 }
563626 }
@@ -566,7 +629,12 @@ func (r *FluentdConfigReconciler) ListNamespacedLevelResources(
566629}
567630
568631// PatchObjects patches the errors to the obj
569- func (r * FluentdConfigReconciler ) PatchObjects (ctx context.Context , obj client.Object , state fluentdv1alpha1.StatusState , msg string ) error {
632+ func (r * FluentdConfigReconciler ) PatchObjects (
633+ ctx context.Context ,
634+ obj client.Object ,
635+ state fluentdv1alpha1.StatusState ,
636+ msg string ,
637+ ) error {
570638 switch o := obj .(type ) {
571639 case * fluentdv1alpha1.ClusterFluentdConfig :
572640 o .Status .State = state
0 commit comments