Skip to content

Commit 51067fd

Browse files
authored
bump golangci-lint to v2.0.1 (#5097)
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
1 parent af6c3f6 commit 51067fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+166
-165
lines changed

.github/workflows/build-x86-image.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ concurrency:
2222

2323
env:
2424
KIND_VERSION: v0.27.0
25-
GOLANGCI_LINT_VERSION: 'v1.64.8'
25+
GOLANGCI_LINT_VERSION: 'v2.0.1'
2626
HELM_VERSION: v3.17.2
2727
SUBMARINER_VERSION: '0.19.3'
2828

.golangci.yml

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,69 @@
1-
run:
2-
timeout: 15m
3-
4-
output:
5-
sort-results: true
6-
1+
version: "2"
72
linters:
83
enable:
4+
- errorlint
95
- gocritic
10-
- gofumpt
11-
- goimports
6+
- gosec
7+
- loggercheck
128
- misspell
9+
- perfsprint
1310
- predeclared
1411
- revive
1512
- unconvert
16-
- unused
17-
- errcheck
18-
- gosec
19-
- govet
20-
- perfsprint
2113
- usestdlibvars
22-
- loggercheck
2314
- whitespace
24-
- errorlint
25-
15+
settings:
16+
errorlint:
17+
asserts: false
18+
perfsprint:
19+
strconcat: false
20+
exclusions:
21+
generated: lax
22+
presets:
23+
- comments
24+
- common-false-positives
25+
- legacy
26+
- std-error-handling
27+
rules:
28+
- linters:
29+
- gocritic
30+
text: appendAssign
31+
- linters:
32+
- revive
33+
text: don't use an underscore in package name
34+
- linters:
35+
- revive
36+
text: VpcDns should be VpcDNS
37+
- linters:
38+
- revive
39+
text: VpcDnsList should be VpcDNSList
40+
# Exclude gosec from running on tests files.
41+
- linters:
42+
- gosec
43+
path: _test\.go
44+
# Exclude gosec from running on tests files.
45+
- linters:
46+
- gosec
47+
path: test/
48+
paths:
49+
- third_party$
50+
- builtin$
51+
- examples$
2652
issues:
2753
max-same-issues: 0
28-
exclude-rules:
29-
- linters:
30-
- gocritic
31-
text: "appendAssign"
32-
- linters:
33-
- revive
34-
text: "don't use an underscore in package name" # package name not change
35-
- linters:
36-
- revive
37-
text: "VpcDns should be VpcDNS" # api param not change
38-
- linters:
39-
- revive
40-
text: "VpcDnsList should be VpcDNSList" # api param not change
41-
- linters:
42-
- gosec
43-
path: _test\.go
44-
- linters:
45-
- gosec
46-
path: test/
47-
48-
linters-settings:
49-
goimports:
50-
local-prefixes: github.com/kubeovn/kube-ovn
51-
gofumpt:
52-
extra-rules: true
53-
perfsprint:
54-
strconcat: false
55-
errorlint:
56-
asserts: false
57-
54+
formatters:
55+
enable:
56+
- gofumpt
57+
- goimports
58+
settings:
59+
gofumpt:
60+
extra-rules: true
61+
goimports:
62+
local-prefixes:
63+
- github.com/kubeovn/kube-ovn
64+
exclusions:
65+
generated: lax
66+
paths:
67+
- third_party$
68+
- builtin$
69+
- examples$

pkg/controller/network_policy.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ func (c *Controller) handleUpdateNp(key string) error {
9191
}
9292
}()
9393

94-
logEnable := false
95-
if np.Annotations[util.NetworkPolicyLogAnnotation] == "true" {
96-
logEnable = true
97-
}
94+
logEnable := np.Annotations[util.NetworkPolicyLogAnnotation] == "true"
95+
9896
var logActions []string
9997
if np.Annotations[util.ACLActionsLogAnnotation] != "" {
10098
logActions = strings.Split(np.Annotations[util.ACLActionsLogAnnotation], ",")

pkg/controller/pod.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ func (c *Controller) reconcileRouteSubnets(pod *v1.Pod, needRoutePodNets []*kube
702702
}
703703

704704
portName := ovs.PodNameToPortName(podName, pod.Namespace, podNet.ProviderName)
705-
if (!c.config.EnableLb || !(subnet.Spec.EnableLb != nil && *subnet.Spec.EnableLb)) &&
705+
if (!c.config.EnableLb || (subnet.Spec.EnableLb == nil || !*subnet.Spec.EnableLb)) &&
706706
subnet.Spec.Vpc == c.config.ClusterRouter &&
707707
subnet.Spec.U2OInterconnection &&
708708
subnet.Spec.Vlan != "" &&
@@ -1896,9 +1896,9 @@ func appendCheckPodToDel(c *Controller, pod *v1.Pod, ownerRefName, ownerRefKind
18961896
}
18971897
klog.Errorf("failed to get StatefulSet %s, %v", ownerRefName, err)
18981898
}
1899-
if ss.Spec.Template.ObjectMeta.Annotations[util.LogicalSwitchAnnotation] != "" {
1899+
if ss.Spec.Template.Annotations[util.LogicalSwitchAnnotation] != "" {
19001900
ownerRefSubnetExist = true
1901-
ownerRefSubnet = ss.Spec.Template.ObjectMeta.Annotations[util.LogicalSwitchAnnotation]
1901+
ownerRefSubnet = ss.Spec.Template.Annotations[util.LogicalSwitchAnnotation]
19021902
}
19031903

19041904
case util.VMInstance:

pkg/controller/subnet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (c *Controller) enqueueUpdateSubnet(oldObj, newObj interface{}) {
7777
}
7878

7979
if oldSubnet.Spec.Vpc != newSubnet.Spec.Vpc &&
80-
!(oldSubnet.Spec.Vpc == "" && newSubnet.Spec.Vpc == c.config.ClusterRouter || oldSubnet.Spec.Vpc == c.config.ClusterRouter && newSubnet.Spec.Vpc == "") {
80+
((oldSubnet.Spec.Vpc != "" || newSubnet.Spec.Vpc != c.config.ClusterRouter) && (oldSubnet.Spec.Vpc != c.config.ClusterRouter || newSubnet.Spec.Vpc != "")) {
8181
if newSubnet.Annotations == nil {
8282
newSubnet.Annotations = make(map[string]string)
8383
}
@@ -1679,7 +1679,7 @@ func (c *Controller) reconcileOvnDefaultVpcRoute(subnet *kubeovnv1.Subnet) error
16791679
}
16801680
}
16811681

1682-
if (!c.config.EnableLb || !(subnet.Spec.EnableLb != nil && *subnet.Spec.EnableLb)) &&
1682+
if (!c.config.EnableLb || (subnet.Spec.EnableLb == nil || !*subnet.Spec.EnableLb)) &&
16831683
subnet.Spec.U2OInterconnection && subnet.Status.U2OInterconnectionIP != "" {
16841684
if err := c.addPolicyRouteForU2ONoLoadBalancer(subnet); err != nil {
16851685
klog.Errorf("failed to add policy route for underlay to overlay subnet interconnection without enabling loadbalancer %s %v", subnet.Name, err)

pkg/controller/vpc.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ func (c *Controller) handleUpdateVpcStatus(key string) error {
150150
return err
151151
}
152152

153-
change := false
154-
if vpc.Status.DefaultLogicalSwitch != defaultSubnet {
155-
change = true
156-
}
153+
change := vpc.Status.DefaultLogicalSwitch != defaultSubnet
157154

158155
vpc.Status.DefaultLogicalSwitch = defaultSubnet
159156
vpc.Status.Subnets = subnets

pkg/controller/vpc_dns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (c *Controller) genVpcDNSDeployment(vpcDNS *kubeovnv1.VpcDns, oldDeploy *v1
307307
dep.Spec.Template.Annotations = maps.Clone(oldDeploy.Annotations)
308308
}
309309

310-
dep.ObjectMeta.Labels = map[string]string{
310+
dep.Labels = map[string]string{
311311
util.VpcDNSNameLabel: "true",
312312
}
313313

pkg/controller/vpc_nat_gateway.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,8 @@ func (c *Controller) execNatGwQoSInPod(
11981198
}
11991199
var addRules []string
12001200
var classifierType, matchDirection, cidr string
1201-
switch {
1202-
case r.MatchType == "ip":
1201+
switch r.MatchType {
1202+
case "ip":
12031203
classifierType = "u32"
12041204
// matchValue: dst xxx.xxx.xxx.xxx/32
12051205
splitStr := strings.Split(r.MatchValue, " ")
@@ -1210,7 +1210,7 @@ func (c *Controller) execNatGwQoSInPod(
12101210
}
12111211
matchDirection = splitStr[0]
12121212
cidr = splitStr[1]
1213-
case r.MatchType == "":
1213+
case "":
12141214
classifierType = "matchall"
12151215
default:
12161216
err := fmt.Errorf("MatchType %s format error", r.MatchType)

pkg/daemon/config_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func getIfaceByIP(ip string) (string, int, error) {
4141
return "", 0, fmt.Errorf("failed to get addresses of link %s: %w", link.Attrs().Name, err)
4242
}
4343
for _, addr := range addrs {
44-
if addr.IPNet.Contains(net.ParseIP(ip)) && addr.IP.String() == ip {
44+
if addr.Contains(net.ParseIP(ip)) && addr.IP.String() == ip {
4545
return link.Attrs().Name, link.Attrs().MTU, nil
4646
}
4747
}

pkg/daemon/gateway_linux.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,10 @@ func (c *Controller) generateNatOutgoingPolicyChainRules(protocol string) ([]uti
10111011
natPolicySubnetIptables = append(natPolicySubnetIptables, util.IPTableRule{Table: NAT, Chain: OvnNatOutGoingPolicy, Rule: strings.Fields(fmt.Sprintf(`-s %s -m comment --comment natPolicySubnet-%s -j %s`, cidrBlock, subnet.Name, ovnNatPolicySubnetChainName))})
10121012
for _, rule := range subnet.Status.NatOutgoingPolicyRules {
10131013
var markCode string
1014-
if rule.Action == util.NatPolicyRuleActionNat {
1014+
switch rule.Action {
1015+
case util.NatPolicyRuleActionNat:
10151016
markCode = OnOutGoingNatMark
1016-
} else if rule.Action == util.NatPolicyRuleActionForward {
1017+
case util.NatPolicyRuleActionForward:
10171018
markCode = OnOutGoingForwardMark
10181019
}
10191020

0 commit comments

Comments
 (0)