Skip to content

go-vet: Fix the Go vet findings #1517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions controllers/fluentbitconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (r *FluentBitConfigReconciler) Reconcile(ctx context.Context, req ctrl.Requ

var ns string
if cfg.Spec.Namespace != nil {
ns = fmt.Sprintf(*cfg.Spec.Namespace)
ns = fmt.Sprint(*cfg.Spec.Namespace)
} else {
ns = os.Getenv("NAMESPACE")
}
Expand Down Expand Up @@ -402,8 +402,8 @@ func (r *FluentBitConfigReconciler) generateRewriteTagConfig(
return ""
}
var buf bytes.Buffer
buf.WriteString(fmt.Sprintf("[Filter]\n"))
buf.WriteString(fmt.Sprintf(" Name rewrite_tag\n"))
buf.WriteString(fmt.Sprintln("[Filter]"))
buf.WriteString(fmt.Sprintln(" Name rewrite_tag"))
buf.WriteString(fmt.Sprintf(" Match %s\n", tag))
buf.WriteString(
fmt.Sprintf(
Expand Down
13 changes: 7 additions & 6 deletions controllers/fluentdconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ package controllers

import (
"context"
"errors"
"fmt"
"strings"
"time"

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

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

// WithCfgResources will collect all plugins to generate main config
Expand All @@ -172,7 +173,7 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
var clustercfgs fluentdv1alpha1.ClusterFluentdConfigList
// Use fluentd selector to match the cluster config.
if err := r.List(ctx, &clustercfgs, client.MatchingLabelsSelector{Selector: fdSelector}); err != nil {
if !errors.IsNotFound(err) {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, err
}
}
Expand All @@ -184,7 +185,7 @@ func (r *FluentdConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
var cfgs fluentdv1alpha1.FluentdConfigList
// Use fluentd selector to match the cluster config
if err := r.List(ctx, &cfgs, client.MatchingLabelsSelector{Selector: fdSelector}); err != nil {
if !errors.IsNotFound(err) {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, err
}
}
Expand Down
8 changes: 4 additions & 4 deletions docs/best-practice/forwarding-logs-via-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"encoding/json"
"io/ioutil"
"io"
"log"
"net/http"
)
Expand All @@ -16,17 +16,17 @@ type Message struct {
// Sample HTTP receiver for this demo
func main() {
h := func(w http.ResponseWriter, req *http.Request) {
b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
defer req.Body.Close()
if err != nil {
log.Printf(err.Error())
log.Print(err.Error())
return
}

var msg []Message
err = json.Unmarshal(b, &msg)
if err != nil {
log.Printf(err.Error())
log.Print(err.Error())
return
}

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/fluentd/cfgrender_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestCompareFluentdMainAppConfig(t *testing.T) {
k8sClient = kc
Expect(k8sClient).NotTo(BeNil())

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

AfterSuite(func() {
Expand Down
Loading