Skip to content

Commit de94ee0

Browse files
oilbeaterclaude
andcommitted
fix(lint): resolve golangci-lint v2.10.1 issues
- Add #nosec G117 for BGP password field (legitimate user-configured value) - Add #nosec G602 for fixed-size array accesses in subnet route reconciliation - Add #nosec G702/G704 for trusted internal command/network operations in ovn-leader-checker - Add #nosec G115 for safe int→uintptr conversion on 64-bit Linux - Replace WriteString(fmt.Sprintf(...)) with fmt.Fprintf(...) (perfsprint auto-fix) - Add golangci.yml exclusion for revive stdlib package name conflict warnings Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 058f4a6 commit de94ee0

File tree

8 files changed

+23
-21
lines changed

8 files changed

+23
-21
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ linters:
4040
- linters:
4141
- revive
4242
text: avoid meaningless package names
43+
- linters:
44+
- revive
45+
text: avoid package names that conflict with Go standard library package names
4346
# Exclude gosec from running on tests files.
4447
- linters:
4548
- gosec

pkg/apis/kubeovn/v1/vpc-nat-gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type VpcBgpSpeaker struct {
6565
Neighbors []string `json:"neighbors"`
6666
HoldTime metav1.Duration `json:"holdTime"`
6767
RouterID string `json:"routerId"`
68-
Password string `json:"password"`
68+
Password string `json:"password"` // #nosec G117
6969
EnableGracefulRestart bool `json:"enableGracefulRestart"`
7070
ExtraArgs []string `json:"extraArgs"`
7171
}

pkg/controller/subnet.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,16 +1468,16 @@ func (c *Controller) reconcileEcmpCentralizedSubnetRouteInDefaultVpc(subnet *kub
14681468
v4CIDR, v6CIDR := util.SplitStringIP(subnet.Spec.CIDRBlock)
14691469
cidrs := [2]string{v4CIDR, v6CIDR}
14701470
for i, cidr := range cidrs {
1471-
if len(nodeIPs[i]) == 0 || cidr == "" {
1471+
if len(nodeIPs[i]) == 0 || cidr == "" { // #nosec G602
14721472
continue
14731473
}
14741474
klog.Infof("delete old distributed policy route for subnet %s", subnet.Name)
14751475
if err := c.deletePolicyRouteByGatewayType(subnet, kubeovnv1.GWDistributedType, false); err != nil {
14761476
klog.Errorf("failed to delete policy route for overlay subnet %s, %v", subnet.Name, err)
14771477
return err
14781478
}
1479-
klog.Infof("subnet %s configure ecmp policy route, nexthops %v", subnet.Name, nodeIPs[i])
1480-
if err := c.updatePolicyRouteForCentralizedSubnet(subnet.Name, cidr, nodeIPs[i], nameIPMaps[i]); err != nil {
1479+
klog.Infof("subnet %s configure ecmp policy route, nexthops %v", subnet.Name, nodeIPs[i]) // #nosec G602
1480+
if err := c.updatePolicyRouteForCentralizedSubnet(subnet.Name, cidr, nodeIPs[i], nameIPMaps[i]); err != nil { // #nosec G602
14811481
klog.Errorf("failed to add ecmp policy route for centralized subnet %s: %v", subnet.Name, err)
14821482
return err
14831483
}

pkg/ovn_ic_controller/ovn_ic_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ func genHostAddress(host, port string) (hostAddress string) {
486486
var builder strings.Builder
487487
i := 0
488488
for i < len(hostList)-1 {
489-
builder.WriteString(fmt.Sprintf("tcp:[%s]:%s,", hostList[i], port))
489+
fmt.Fprintf(&builder, "tcp:[%s]:%s,", hostList[i], port)
490490
i++
491491
}
492-
builder.WriteString(fmt.Sprintf("tcp:[%s]:%s", hostList[i], port))
492+
fmt.Fprintf(&builder, "tcp:[%s]:%s", hostList[i], port)
493493
hostAddress = builder.String()
494494
}
495495
return hostAddress

pkg/ovn_leader_checker/ovn.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func stealLock() {
245245
args = slices.Insert(args, 0, ovs.CmdSSLArgs()...)
246246
}
247247

248-
output, err := exec.Command("ovsdb-client", args...).CombinedOutput() // #nosec G204
248+
output, err := exec.Command("ovsdb-client", args...).CombinedOutput() // #nosec G204 G702
249249
if err != nil {
250250
klog.Errorf("stealLock err %v", err)
251251
return
@@ -267,7 +267,7 @@ func checkNorthdSvcExist(cfg *Configuration, namespace, svcName string) bool {
267267

268268
func checkNorthdEpAvailable(ip string) bool {
269269
address := util.JoinHostPort(ip, util.NBRaftPort)
270-
conn, err := net.DialTimeout("tcp", address, northdDialTimeout)
270+
conn, err := net.DialTimeout("tcp", address, northdDialTimeout) // #nosec G704
271271
if err != nil {
272272
klog.Errorf("failed to connect to northd leader %s, err: %v", ip, err)
273273
failCount++
@@ -529,8 +529,7 @@ func updateTS() error {
529529
fmt.Sprintf(`external_ids:subnet="%s"`, subnet),
530530
fmt.Sprintf(`external_ids:vendor="%s"`, util.CniTypeName),
531531
)
532-
// #nosec G204
533-
cmd = exec.Command("ovn-ic-nbctl", args...)
532+
cmd = exec.Command("ovn-ic-nbctl", args...) // #nosec G204 G702
534533
output, err := cmd.CombinedOutput()
535534
if err != nil {
536535
return fmt.Errorf("output: %s, err: %w", output, err)

pkg/ovs/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func formatDHCPOptions(options map[string]string) string {
164164
if k == "dns_server" {
165165
v = strings.ReplaceAll(v, ",", ";")
166166
}
167-
sb.WriteString(fmt.Sprintf("%s=%s", k, v))
167+
fmt.Fprintf(&sb, "%s=%s", k, v)
168168
}
169169
return sb.String()
170170
}

pkg/tproxy/tproxy_tcp_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func dialTCP(device string, laddr, raddr *net.TCPAddr, dontAssumeRemote, isnonbl
220220
return nil, &net.OpError{Op: "dial", Err: fmt.Errorf("socket connect: %w", err)}
221221
}
222222

223-
fdFile := os.NewFile(uintptr(fileDescriptor), "net-tcp-dial-"+raddr.String())
223+
fdFile := os.NewFile(uintptr(fileDescriptor), "net-tcp-dial-"+raddr.String()) // #nosec G115
224224
defer func() {
225225
if err := fdFile.Close(); err != nil {
226226
klog.Errorf("fdFile %v Close err: %v", fdFile, err)

test/e2e/iptables-eip-qos/e2e_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,32 +1034,32 @@ type bandwidthValidationResult struct {
10341034
func formatBandwidthSummary(result bandwidthValidationResult, testType, direction string) string {
10351035
var sb strings.Builder
10361036
sb.WriteString("\n╔═══════════════════════════════════════════════════════════════════════════════╗\n")
1037-
sb.WriteString(fmt.Sprintf("║ QoS Bandwidth Test Summary - %s (%s)\n", testType, direction))
1037+
fmt.Fprintf(&sb, "║ QoS Bandwidth Test Summary - %s (%s)\n", testType, direction)
10381038
sb.WriteString("╠═══════════════════════════════════════════════════════════════════════════════╣\n")
1039-
sb.WriteString(fmt.Sprintf("║ QoS Limit: %.2f Mbps\n", result.LimitMbps))
1039+
fmt.Fprintf(&sb, "║ QoS Limit: %.2f Mbps\n", result.LimitMbps)
10401040

10411041
if result.MaxExpected > 0 {
1042-
sb.WriteString(fmt.Sprintf("║ Expected Range: %.2f ~ %.2f Mbps (%.0f%% ~ %.0f%% of limit)\n",
1042+
fmt.Fprintf(&sb, "║ Expected Range: %.2f ~ %.2f Mbps (%.0f%% ~ %.0f%% of limit)\n",
10431043
result.MinExpected, result.MaxExpected,
1044-
bandwidthToleranceLow*100, bandwidthToleranceHigh*100))
1044+
bandwidthToleranceLow*100, bandwidthToleranceHigh*100)
10451045
} else {
1046-
sb.WriteString(fmt.Sprintf("║ Expected: > %.2f Mbps (QoS disabled, should exceed %.0f%% of limit)\n",
1047-
result.MinExpected, bandwidthToleranceHigh*100))
1046+
fmt.Fprintf(&sb, "║ Expected: > %.2f Mbps (QoS disabled, should exceed %.0f%% of limit)\n",
1047+
result.MinExpected, bandwidthToleranceHigh*100)
10481048
}
10491049

10501050
sb.WriteString("║ Measured Values: ")
10511051
for i, bw := range result.MeasuredMbps {
10521052
if i > 0 {
10531053
sb.WriteString(", ")
10541054
}
1055-
sb.WriteString(fmt.Sprintf("%.2f", bw))
1055+
fmt.Fprintf(&sb, "%.2f", bw)
10561056
}
10571057
sb.WriteString(" Mbps\n")
10581058

10591059
if result.Passed {
1060-
sb.WriteString(fmt.Sprintf("║ Best Match: %.2f Mbps ✓ PASS\n", result.BestMatch))
1060+
fmt.Fprintf(&sb, "║ Best Match: %.2f Mbps ✓ PASS\n", result.BestMatch)
10611061
} else {
1062-
sb.WriteString(fmt.Sprintf("║ Best Match: %.2f Mbps ✗ FAIL\n", result.BestMatch))
1062+
fmt.Fprintf(&sb, "║ Best Match: %.2f Mbps ✗ FAIL\n", result.BestMatch)
10631063
}
10641064

10651065
sb.WriteString("╚═══════════════════════════════════════════════════════════════════════════════╝\n")

0 commit comments

Comments
 (0)