From 6eb557d02094cc2b500fcb07f242eb395e45e73b Mon Sep 17 00:00:00 2001 From: lou-lan Date: Fri, 16 Aug 2024 18:06:33 +0800 Subject: [PATCH] Fix golanglint Signed-off-by: lou-lan --- pkg/controller/webhook/validate.go | 2 +- pkg/iptables/restore_buffer.go | 2 +- pkg/iptables/testutils/test.go | 2 +- test/e2e/common/ds.go | 3 +-- test/e2e/common/egw.go | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/controller/webhook/validate.go b/pkg/controller/webhook/validate.go index 619da6669..73d9a587d 100644 --- a/pkg/controller/webhook/validate.go +++ b/pkg/controller/webhook/validate.go @@ -86,7 +86,7 @@ func validateEgressPolicy(ctx context.Context, client client.Client, req webhook } // denied when both PodSelector and PodSubnet are empty - if egp.Spec.AppliedTo.PodSubnet == nil || len(egp.Spec.AppliedTo.PodSubnet) == 0 { + if len(egp.Spec.AppliedTo.PodSubnet) == 0 { if egp.Spec.AppliedTo.PodSelector == nil || (len(egp.Spec.AppliedTo.PodSelector.MatchLabels) == 0 && len(egp.Spec.AppliedTo.PodSelector.MatchExpressions) == 0) { return webhook.Denied("invalid EgressPolicy, spec.appliedTo field requires at least one of spec.appliedTo.podSubnet, .spec.appliedTo.podSelector.matchLabels or .spec.appliedTo.podSelector.matchExpressions to be specified.") } diff --git a/pkg/iptables/restore_buffer.go b/pkg/iptables/restore_buffer.go index 6b1f99abf..92d2faeeb 100644 --- a/pkg/iptables/restore_buffer.go +++ b/pkg/iptables/restore_buffer.go @@ -115,7 +115,7 @@ func (b *RestoreInputBuilder) WriteForwardReference(chainName string) { // write the actual rules and will cause a panic if there is no open transaction. func (b *RestoreInputBuilder) WriteLine(line string) { b.maybeWriteTransactionOpener() - b.writeFormattedLine(line) + b.writeFormattedLine("%s", line) } // GetBytesAndReset returns the contents of the buffer and, as a side effect, resets the buffer. For performance, diff --git a/pkg/iptables/testutils/test.go b/pkg/iptables/testutils/test.go index 7e1c4b2e4..af72b42d8 100644 --- a/pkg/iptables/testutils/test.go +++ b/pkg/iptables/testutils/test.go @@ -310,7 +310,7 @@ func (d *restoreCmd) Run() error { } rest := strings.Join(parts[2:], " ") if chains[chainName] == nil { - panic(fmt.Sprintf("Append to unknown chain: " + chainName)) + panic(fmt.Sprintf("Append to unknown chain: %s", chainName)) } chains[chainName] = append(chains[chainName], rest) d.Dataplane.ChainMods.Add(chainMod{name: chainName, ruleNum: len(chains[chainName])}) diff --git a/test/e2e/common/ds.go b/test/e2e/common/ds.go index d8a7fb930..b6a619e54 100644 --- a/test/e2e/common/ds.go +++ b/test/e2e/common/ds.go @@ -57,7 +57,7 @@ func CreateDaemonSet(ctx context.Context, cli client.Client, name string, image case <-ctx.Done(): _ = DeleteObj(context.Background(), cli, res) log.Log("create DaemonSet time out") - return nil, fmt.Errorf(log.Save()) + return nil, fmt.Errorf("%s", log.Save()) default: err := cli.Get(ctx, types.NamespacedName{Namespace: res.Namespace, Name: res.Name}, res) if err != nil { @@ -72,7 +72,6 @@ func CreateDaemonSet(ctx context.Context, cli client.Client, name string, image return res, nil } - log.Log("--------") log.Log(fmt.Sprintf("CurrentNumberScheduled=%v\nDesiredNumberScheduled=%v\nNumberAvailable=%v", a, b, c)) nodes := new(corev1.NodeList) diff --git a/test/e2e/common/egw.go b/test/e2e/common/egw.go index 129d0be18..84c87b269 100644 --- a/test/e2e/common/egw.go +++ b/test/e2e/common/egw.go @@ -277,7 +277,7 @@ func DeleteEgressGateway(ctx context.Context, cli client.Client, egw *egressv1.E select { case <-ctx.Done(): log.Log("check delete egress gateway object timeout") - return fmt.Errorf(log.Save()) + return fmt.Errorf("%s", log.Save()) default: err = cli.Get(ctx, types.NamespacedName{Name: egw.Name}, egw) if apierrors.IsNotFound(err) {