Skip to content

Commit e7c3e4f

Browse files
u5surfmarcofranssen
authored andcommitted
Fix some lll warnings.
* except kubebuild annotations, flag description or logs. Signed-off-by: Y.Horie <[email protected]>
1 parent b02ab27 commit e7c3e4f

File tree

8 files changed

+129
-26
lines changed

8 files changed

+129
-26
lines changed

cmd/doc-gen/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
const (
2020
firstParagraph = `# API Docs
2121
This Document documents the types introduced by the %s Operator.
22-
> Note this document is generated from code comments. When contributing a change to this document please do so by changing the code comments.`
22+
> Note this document is generated from code comments.
23+
> When contributing a change to this document please do so by changing the code comments.`
2324

2425
fluentbitPluginPath = "apis/fluentbit/v1alpha2/plugins/"
2526
fluentdPluginPath = "apis/fluentd/v1alpha1/plugins/"

controllers/fluent_controller_finalizer.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ func (r *FluentdReconciler) delete(ctx context.Context, fd *fluentdv1alpha1.Flue
114114
func (r *FluentdReconciler) mutate(obj client.Object, fd *fluentdv1alpha1.Fluentd) controllerutil.MutateFn {
115115
switch o := obj.(type) {
116116
case *rbacv1.ClusterRole:
117-
expected, _, _ := operator.MakeRBACObjects(fd.Name, fd.Namespace, "fluentd", fd.Spec.RBACRules, fd.Spec.ServiceAccountAnnotations)
117+
expected, _, _ := operator.MakeRBACObjects(
118+
fd.Name,
119+
fd.Namespace,
120+
"fluentd",
121+
fd.Spec.RBACRules,
122+
fd.Spec.ServiceAccountAnnotations,
123+
)
118124

119125
return func() error {
120126
o.Rules = expected.Rules

controllers/fluentbitconfig_controller.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ func listNamespacedResources[T client.ObjectList](
292292
if err != nil {
293293
return err
294294
}
295-
if err := cli.List(ctx, list, client.InNamespace(namespace), client.MatchingLabelsSelector{Selector: sel}); err != nil {
295+
matchingLabelSelector := client.MatchingLabelsSelector{Selector: sel}
296+
if err := cli.List(ctx, list, client.InNamespace(namespace), matchingLabelSelector); err != nil {
296297
return err
297298
}
298299
return nil
@@ -323,15 +324,33 @@ func (r *FluentBitConfigReconciler) ListNamespacedResources(
323324
return filters, outputs, parsers, clusterParsers, multipleParsers, clusterMultipleParsers, err
324325
}
325326

326-
if err := listNamespacedResources(ctx, r.Client, &clusterParsers, cfg.Namespace, &cfg.Spec.ClusterParserSelector); err != nil {
327+
if err := listNamespacedResources(
328+
ctx,
329+
r.Client,
330+
&clusterParsers,
331+
cfg.Namespace,
332+
&cfg.Spec.ClusterParserSelector,
333+
); err != nil {
327334
return filters, outputs, parsers, clusterParsers, multipleParsers, clusterMultipleParsers, err
328335
}
329336

330-
if err := listNamespacedResources(ctx, r.Client, &multipleParsers, cfg.Namespace, &cfg.Spec.MultilineParserSelector); err != nil {
337+
if err := listNamespacedResources(
338+
ctx,
339+
r.Client,
340+
&multipleParsers,
341+
cfg.Namespace,
342+
&cfg.Spec.MultilineParserSelector,
343+
); err != nil {
331344
return filters, outputs, parsers, clusterParsers, multipleParsers, clusterMultipleParsers, err
332345
}
333346

334-
if err := listNamespacedResources(ctx, r.Client, &clusterMultipleParsers, cfg.Namespace, &cfg.Spec.ClusterMultilineParserSelector); err != nil {
347+
if err := listNamespacedResources(
348+
ctx,
349+
r.Client,
350+
&clusterMultipleParsers,
351+
cfg.Namespace,
352+
&cfg.Spec.ClusterMultilineParserSelector,
353+
); err != nil {
335354
return filters, outputs, parsers, clusterParsers, multipleParsers, clusterMultipleParsers, err
336355
}
337356

controllers/fluentd_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ func (r *FluentdReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
9696
}
9797

9898
// Install RBAC resources for the filter plugin kubernetes
99-
cr, sa, crb := operator.MakeRBACObjects(fd.Name, fd.Namespace, fluentdLowercase, fd.Spec.RBACRules, fd.Spec.ServiceAccountAnnotations)
99+
cr, sa, crb := operator.MakeRBACObjects(
100+
fd.Name,
101+
fd.Namespace,
102+
fluentdLowercase,
103+
fd.Spec.RBACRules,
104+
fd.Spec.ServiceAccountAnnotations,
105+
)
100106
// Deploy Fluentd ClusterRole
101107
if _, err := controllerutil.CreateOrPatch(ctx, r.Client, cr, r.mutate(cr, &fd)); err != nil {
102108
return ctrl.Result{}, err

controllers/fluentdconfig_controller.go

Lines changed: 84 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

pkg/filenotify/filenotify.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
// These are wrapped up in a common interface so that either can be used interchangeably in your code.
88
//
99
// This package is adapted from https://github.com/moby/moby/tree/master/pkg/filenotify, Apache-2.0 License.
10-
// Hopefully this can be replaced with an external package sometime in the future, see https://github.com/fsnotify/fsnotify/issues/9
10+
// Hopefully this can be replaced with an external package sometime in the future.
11+
// See https://github.com/fsnotify/fsnotify/issues/9
1112
package filenotify
1213

1314
import (

pkg/filenotify/fsnotify.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// Copyright Hugo Authors
44

55
// Package filenotify is adapted from https://github.com/moby/moby/tree/master/pkg/filenotify, Apache-2.0 License.
6-
// Hopefully this can be replaced with an external package sometime in the future, see https://github.com/fsnotify/fsnotify/issues/9
6+
// Hopefully this can be replaced with an external package sometime in the future.
7+
// See https://github.com/fsnotify/fsnotify/issues/9
78
package filenotify
89

910
import "github.com/fsnotify/fsnotify"

pkg/filenotify/poller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// Copyright Hugo Authors
44

55
// Package filenotify is adapted from https://github.com/moby/moby/tree/master/pkg/filenotify, Apache-2.0 License.
6-
// Hopefully this can be replaced with an external package sometime in the future, see https://github.com/fsnotify/fsnotify/issues/9
6+
// Hopefully this can be replaced with an external package sometime in the future.
7+
// See https://github.com/fsnotify/fsnotify/issues/9
78
package filenotify
89

910
import (

0 commit comments

Comments
 (0)