Skip to content

Commit 7820786

Browse files
go-vet: Fix the Go vet findings (#1517)
Signed-off-by: Marco Franssen <marco.franssen@gmail.com>
1 parent 4044981 commit 7820786

4 files changed

Lines changed: 15 additions & 14 deletions

File tree

controllers/fluentbitconfig_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (r *FluentBitConfigReconciler) Reconcile(ctx context.Context, req ctrl.Requ
157157

158158
var ns string
159159
if cfg.Spec.Namespace != nil {
160-
ns = fmt.Sprintf(*cfg.Spec.Namespace)
160+
ns = fmt.Sprint(*cfg.Spec.Namespace)
161161
} else {
162162
ns = os.Getenv("NAMESPACE")
163163
}
@@ -402,8 +402,8 @@ func (r *FluentBitConfigReconciler) generateRewriteTagConfig(
402402
return ""
403403
}
404404
var buf bytes.Buffer
405-
buf.WriteString(fmt.Sprintf("[Filter]\n"))
406-
buf.WriteString(fmt.Sprintf(" Name rewrite_tag\n"))
405+
buf.WriteString(fmt.Sprintln("[Filter]"))
406+
buf.WriteString(fmt.Sprintln(" Name rewrite_tag"))
407407
buf.WriteString(fmt.Sprintf(" Match %s\n", tag))
408408
buf.WriteString(
409409
fmt.Sprintf(

controllers/fluentdconfig_controller.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ package controllers
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"strings"
2324
"time"
2425

2526
"github.com/go-logr/logr"
2627
corev1 "k8s.io/api/core/v1"
27-
"k8s.io/apimachinery/pkg/api/errors"
28+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"k8s.io/apimachinery/pkg/runtime"
3031
ctrl "sigs.k8s.io/controller-runtime"
@@ -105,7 +106,7 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
105106
var fluentdList fluentdv1alpha1.FluentdList
106107
// List all fluentd instances to bind the generated runtime configuration to each fluentd
107108
if err := r.List(ctx, &fluentdList); err != nil {
108-
if errors.IsNotFound(err) {
109+
if apierrors.IsNotFound(err) {
109110
r.Log.Info("can not find fluentd CR definition.")
110111
return ctrl.Result{Requeue: true, RequeueAfter: time.Duration(1)}, nil
111112
}
@@ -146,13 +147,13 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
146147
cfgResouces, errs := gpr.PatchAndFilterNamespacedLevelResources(sl, fmt.Sprintf("%s-%s-%s", fd.Kind, fd.Namespace, fd.Name), inputs, filters, outputs)
147148
if len(errs) > 0 {
148149
r.Log.Info("Patch and filter namespace level resources failed", "config", "default", "err", strings.Join(errs, ","))
149-
return ctrl.Result{}, fmt.Errorf(strings.Join(errs, ","))
150+
return ctrl.Result{}, errors.New(strings.Join(errs, ","))
150151
}
151152

152153
err = gpr.IdentifyCopyAndPatchOutput(cfgResouces)
153154
if err != nil {
154155
r.Log.Info("IdentifyCopy and PatchOutput namespace level resources failed", "config", "default", "err", strings.Join(errs, ","))
155-
return ctrl.Result{}, fmt.Errorf(strings.Join(errs, ","))
156+
return ctrl.Result{}, errors.New(strings.Join(errs, ","))
156157
}
157158

158159
// WithCfgResources will collect all plugins to generate main config
@@ -172,7 +173,7 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
172173
var clustercfgs fluentdv1alpha1.ClusterFluentdConfigList
173174
// Use fluentd selector to match the cluster config.
174175
if err := r.List(ctx, &clustercfgs, client.MatchingLabelsSelector{Selector: fdSelector}); err != nil {
175-
if !errors.IsNotFound(err) {
176+
if !apierrors.IsNotFound(err) {
176177
return ctrl.Result{}, err
177178
}
178179
}
@@ -184,7 +185,7 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
184185
var cfgs fluentdv1alpha1.FluentdConfigList
185186
// Use fluentd selector to match the cluster config
186187
if err := r.List(ctx, &cfgs, client.MatchingLabelsSelector{Selector: fdSelector}); err != nil {
187-
if !errors.IsNotFound(err) {
188+
if !apierrors.IsNotFound(err) {
188189
return ctrl.Result{}, err
189190
}
190191
}

docs/best-practice/forwarding-logs-via-http/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import (
44
"encoding/json"
5-
"io/ioutil"
5+
"io"
66
"log"
77
"net/http"
88
)
@@ -16,17 +16,17 @@ type Message struct {
1616
// Sample HTTP receiver for this demo
1717
func main() {
1818
h := func(w http.ResponseWriter, req *http.Request) {
19-
b, err := ioutil.ReadAll(req.Body)
19+
b, err := io.ReadAll(req.Body)
2020
defer req.Body.Close()
2121
if err != nil {
22-
log.Printf(err.Error())
22+
log.Print(err.Error())
2323
return
2424
}
2525

2626
var msg []Message
2727
err = json.Unmarshal(b, &msg)
2828
if err != nil {
29-
log.Printf(err.Error())
29+
log.Print(err.Error())
3030
return
3131
}
3232

tests/e2e/fluentd/cfgrender_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestCompareFluentdMainAppConfig(t *testing.T) {
4545
k8sClient = kc
4646
Expect(k8sClient).NotTo(BeNil())
4747

48-
fmt.Fprintf(GinkgoWriter, time.Now().Format(time.StampMilli)+": Info: Setup Suite Execution\n")
48+
fmt.Fprintf(GinkgoWriter, "%s: Info: Setup Suite Execution\n", time.Now().Format(time.StampMilli))
4949
}, 60)
5050

5151
AfterSuite(func() {

0 commit comments

Comments
 (0)