Skip to content

Commit 65fe256

Browse files
authored
Merge pull request #883 from mmorel-35/linter-2
enable govet and unparam linters
2 parents 00b82fb + 10ddd9e commit 65fe256

File tree

11 files changed

+61
-66
lines changed

11 files changed

+61
-66
lines changed

.golangci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ issues:
88
text: " and that stutters;"
99

1010
linters:
11+
disable:
12+
- errcheck
1113
enable:
1214
- contextcheck
1315
- durationcheck
@@ -16,17 +18,17 @@ linters:
1618
- gocritic
1719
- gofumpt
1820
- gosimple
21+
- govet
1922
- ineffassign
2023
- misspell
2124
- nonamedreturns
2225
- predeclared
2326
- revive
2427
- staticcheck
2528
- unconvert
29+
- unparam
2630
- unused
2731
- wastedassign
28-
disable:
29-
- errcheck
3032

3133
linters-settings:
3234
gci:

integration/integration_linux_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,12 @@ var _ = Describe("Basic PTP using cnitool", func() {
161161
Expect(basicBridgeIP).To(ContainSubstring("10.11.2."))
162162

163163
var chainedBridgeBandwidthPort, basicBridgePort int
164-
var err error
165164

166165
By(fmt.Sprintf("starting echo server in %s\n\n", contNS1.ShortName()))
167-
chainedBridgeBandwidthPort, chainedBridgeBandwidthSession, err = startEchoServerInNamespace(contNS1)
168-
Expect(err).ToNot(HaveOccurred())
166+
chainedBridgeBandwidthPort, chainedBridgeBandwidthSession = startEchoServerInNamespace(contNS1)
169167

170168
By(fmt.Sprintf("starting echo server in %s\n\n", contNS2.ShortName()))
171-
basicBridgePort, basicBridgeSession, err = startEchoServerInNamespace(contNS2)
172-
Expect(err).ToNot(HaveOccurred())
169+
basicBridgePort, basicBridgeSession = startEchoServerInNamespace(contNS2)
173170

174171
packetInBytes := 20000 // The shaper needs to 'warm'. Send enough to cause it to throttle,
175172
// balanced by run time.
@@ -242,7 +239,7 @@ func makeTCPClientInNS(netns string, address string, port int, numBytes int) {
242239
Expect(string(out)).To(Equal(message))
243240
}
244241

245-
func startEchoServerInNamespace(netNS Namespace) (int, *gexec.Session, error) {
242+
func startEchoServerInNamespace(netNS Namespace) (int, *gexec.Session) {
246243
session, err := startInNetNS(echoServerBinaryPath, netNS)
247244
Expect(err).NotTo(HaveOccurred())
248245

@@ -259,7 +256,7 @@ func startEchoServerInNamespace(netNS Namespace) (int, *gexec.Session, error) {
259256
io.Copy(GinkgoWriter, io.MultiReader(session.Out, session.Err))
260257
}()
261258

262-
return port, session, nil
259+
return port, session
263260
}
264261

265262
func startInNetNS(binPath string, namespace Namespace) (*gexec.Session, error) {

pkg/ip/link_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func makeVeth(name, vethPeerName string, mtu int, mac string, hostNS ns.NetNS) (
8484
veth, err = makeVethPair(name, peerName, mtu, mac, hostNS)
8585
switch {
8686
case err == nil:
87-
return peerName, veth, err
87+
return peerName, veth, nil
8888

8989
case os.IsExist(err):
9090
if peerExists(peerName) && vethPeerName == "" {

plugins/main/host-device/host-device_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ func canonicalizeIP(ip *net.IP) error {
8686
// LoadIPAMConfig creates IPAMConfig using json encoded configuration provided
8787
// as `bytes`. At the moment values provided in envArgs are ignored so there
8888
// is no possibility to overload the json configuration using envArgs
89-
func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) {
89+
func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, error) {
9090
n := Net{}
9191
if err := json.Unmarshal(bytes, &n); err != nil {
92-
return nil, "", err
92+
return nil, err
9393
}
9494

9595
if n.IPAM == nil {
96-
return nil, "", fmt.Errorf("IPAM config missing 'ipam' key")
96+
return nil, fmt.Errorf("IPAM config missing 'ipam' key")
9797
}
9898

9999
// Validate all ranges
@@ -103,13 +103,13 @@ func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) {
103103
for i := range n.IPAM.Addresses {
104104
ip, addr, err := net.ParseCIDR(n.IPAM.Addresses[i].AddressStr)
105105
if err != nil {
106-
return nil, "", fmt.Errorf("invalid CIDR %s: %s", n.IPAM.Addresses[i].AddressStr, err)
106+
return nil, fmt.Errorf("invalid CIDR %s: %s", n.IPAM.Addresses[i].AddressStr, err)
107107
}
108108
n.IPAM.Addresses[i].Address = *addr
109109
n.IPAM.Addresses[i].Address.IP = ip
110110

111111
if err := canonicalizeIP(&n.IPAM.Addresses[i].Address.IP); err != nil {
112-
return nil, "", fmt.Errorf("invalid address %d: %s", i, err)
112+
return nil, fmt.Errorf("invalid address %d: %s", i, err)
113113
}
114114

115115
if n.IPAM.Addresses[i].Address.IP.To4() != nil {
@@ -123,7 +123,7 @@ func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) {
123123
e := IPAMEnvArgs{}
124124
err := types.LoadArgs(envArgs, &e)
125125
if err != nil {
126-
return nil, "", err
126+
return nil, err
127127
}
128128

129129
if e.IP != "" {
@@ -132,7 +132,7 @@ func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) {
132132

133133
ip, subnet, err := net.ParseCIDR(ipstr)
134134
if err != nil {
135-
return nil, "", fmt.Errorf("invalid CIDR %s: %s", ipstr, err)
135+
return nil, fmt.Errorf("invalid CIDR %s: %s", ipstr, err)
136136
}
137137

138138
addr := Address{Address: net.IPNet{IP: ip, Mask: subnet.Mask}}
@@ -149,7 +149,7 @@ func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) {
149149
for _, item := range strings.Split(string(e.GATEWAY), ",") {
150150
gwip := net.ParseIP(strings.TrimSpace(item))
151151
if gwip == nil {
152-
return nil, "", fmt.Errorf("invalid gateway address: %s", item)
152+
return nil, fmt.Errorf("invalid gateway address: %s", item)
153153
}
154154

155155
for i := range n.IPAM.Addresses {
@@ -164,14 +164,14 @@ func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) {
164164
// CNI spec 0.2.0 and below supported only one v4 and v6 address
165165
if numV4 > 1 || numV6 > 1 {
166166
if ok, _ := version.GreaterThanOrEqualTo(n.CNIVersion, "0.3.0"); !ok {
167-
return nil, "", fmt.Errorf("CNI version %v does not support more than 1 address per family", n.CNIVersion)
167+
return nil, fmt.Errorf("CNI version %v does not support more than 1 address per family", n.CNIVersion)
168168
}
169169
}
170170

171171
// Copy net name into IPAM so not to drag Net struct around
172172
n.IPAM.Name = n.Name
173173

174-
return n.IPAM, n.CNIVersion, nil
174+
return n.IPAM, nil
175175
}
176176

177177
func buildOneConfig(name, cniVersion string, orig *Net, prevResult types.Result) (*Net, error) {
@@ -868,7 +868,7 @@ var _ = Describe("base functionality", func() {
868868
err = json.Unmarshal([]byte(conf), &n)
869869
Expect(err).NotTo(HaveOccurred())
870870

871-
n.IPAM, _, err = LoadIPAMConfig([]byte(conf), "")
871+
n.IPAM, err = LoadIPAMConfig([]byte(conf), "")
872872
Expect(err).NotTo(HaveOccurred())
873873

874874
if testutils.SpecVersionHasCHECK(ver) {
@@ -984,7 +984,7 @@ var _ = Describe("base functionality", func() {
984984
err = json.Unmarshal([]byte(conf), &n)
985985
Expect(err).NotTo(HaveOccurred())
986986

987-
n.IPAM, _, err = LoadIPAMConfig([]byte(conf), "")
987+
n.IPAM, err = LoadIPAMConfig([]byte(conf), "")
988988
Expect(err).NotTo(HaveOccurred())
989989

990990
if testutils.SpecVersionHasCHECK(ver) {

plugins/meta/bandwidth/bandwidth_linux_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"github.com/containernetworking/plugins/pkg/testutils"
3636
)
3737

38-
func buildOneConfig(name, cniVersion string, orig *PluginConf, prevResult types.Result) (*PluginConf, []byte, error) {
38+
func buildOneConfig(name, cniVersion string, orig *PluginConf, prevResult types.Result) ([]byte, error) {
3939
var err error
4040

4141
inject := map[string]interface{}{
@@ -54,12 +54,12 @@ func buildOneConfig(name, cniVersion string, orig *PluginConf, prevResult types.
5454

5555
confBytes, err := json.Marshal(orig)
5656
if err != nil {
57-
return nil, nil, err
57+
return nil, err
5858
}
5959

6060
err = json.Unmarshal(confBytes, &config)
6161
if err != nil {
62-
return nil, nil, fmt.Errorf("unmarshal existing network bytes: %s", err)
62+
return nil, fmt.Errorf("unmarshal existing network bytes: %s", err)
6363
}
6464

6565
for key, value := range inject {
@@ -68,15 +68,15 @@ func buildOneConfig(name, cniVersion string, orig *PluginConf, prevResult types.
6868

6969
newBytes, err := json.Marshal(config)
7070
if err != nil {
71-
return nil, nil, err
71+
return nil, err
7272
}
7373

7474
conf := &PluginConf{}
7575
if err := json.Unmarshal(newBytes, &conf); err != nil {
76-
return nil, nil, fmt.Errorf("error parsing configuration: %s", err)
76+
return nil, fmt.Errorf("error parsing configuration: %s", err)
7777
}
7878

79-
return conf, newBytes, nil
79+
return newBytes, nil
8080
}
8181

8282
var _ = Describe("bandwidth test", func() {
@@ -950,7 +950,7 @@ var _ = Describe("bandwidth test", func() {
950950
EgressRate: rateInBits,
951951
}
952952
tbfPluginConf.Type = "bandwidth"
953-
_, newConfBytes, err := buildOneConfig("myBWnet", ver, tbfPluginConf, containerWithTbfResult)
953+
newConfBytes, err := buildOneConfig("myBWnet", ver, tbfPluginConf, containerWithTbfResult)
954954
Expect(err).NotTo(HaveOccurred())
955955

956956
args := &skel.CmdArgs{
@@ -977,7 +977,7 @@ var _ = Describe("bandwidth test", func() {
977977
}
978978
checkConf.Type = "bandwidth"
979979

980-
_, newCheckBytes, err := buildOneConfig("myBWnet", ver, checkConf, result)
980+
newCheckBytes, err := buildOneConfig("myBWnet", ver, checkConf, result)
981981
Expect(err).NotTo(HaveOccurred())
982982

983983
args = &skel.CmdArgs{
@@ -995,10 +995,8 @@ var _ = Describe("bandwidth test", func() {
995995
})).To(Succeed())
996996

997997
By("starting a tcp server on both containers")
998-
portServerWithTbf, echoServerWithTbf, err = startEchoServerInNamespace(containerWithTbfNS)
999-
Expect(err).NotTo(HaveOccurred())
1000-
portServerWithoutTbf, echoServerWithoutTbf, err = startEchoServerInNamespace(containerWithoutTbfNS)
1001-
Expect(err).NotTo(HaveOccurred())
998+
portServerWithTbf, echoServerWithTbf = startEchoServerInNamespace(containerWithTbfNS)
999+
portServerWithoutTbf, echoServerWithoutTbf = startEchoServerInNamespace(containerWithoutTbfNS)
10021000
})
10031001

10041002
AfterEach(func() {

plugins/meta/bandwidth/bandwidth_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func startInNetNS(binPath string, netNS ns.NetNS) (*gexec.Session, error) {
6666
return session, err
6767
}
6868

69-
func startEchoServerInNamespace(netNS ns.NetNS) (int, *gexec.Session, error) {
69+
func startEchoServerInNamespace(netNS ns.NetNS) (int, *gexec.Session) {
7070
session, err := startInNetNS(echoServerBinaryPath, netNS)
7171
Expect(err).NotTo(HaveOccurred())
7272

@@ -83,7 +83,7 @@ func startEchoServerInNamespace(netNS ns.NetNS) (int, *gexec.Session, error) {
8383
io.Copy(GinkgoWriter, io.MultiReader(session.Out, session.Err))
8484
}()
8585

86-
return port, session, nil
86+
return port, session
8787
}
8888

8989
func makeTCPClientInNS(netns string, address string, port int, numBytes int) {

plugins/meta/firewall/firewall_firewalld_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,21 @@ func (f *fakeFirewalld) clear() {
4545
f.source = ""
4646
}
4747

48+
//nolint:unparam
4849
func (f *fakeFirewalld) AddSource(zone, source string) (string, *dbus.Error) {
4950
f.zone = zone
5051
f.source = source
5152
return "", nil
5253
}
5354

55+
//nolint:unparam
5456
func (f *fakeFirewalld) RemoveSource(zone, source string) (string, *dbus.Error) {
5557
f.zone = zone
5658
f.source = source
5759
return "", nil
5860
}
5961

62+
//nolint:unparam
6063
func (f *fakeFirewalld) QuerySource(zone, source string) (bool, *dbus.Error) {
6164
if f.zone != zone {
6265
return false, nil
@@ -101,7 +104,7 @@ func spawnSessionDbus(wg *sync.WaitGroup) (string, *exec.Cmd) {
101104
return busAddr, cmd
102105
}
103106

104-
func makeFirewalldConf(ver, ifname string, ns ns.NetNS) []byte {
107+
func makeFirewalldConf(ver string, ns ns.NetNS) []byte {
105108
return []byte(fmt.Sprintf(`{
106109
"cniVersion": "%s",
107110
"name": "firewalld-test",
@@ -111,7 +114,7 @@ func makeFirewalldConf(ver, ifname string, ns ns.NetNS) []byte {
111114
"prevResult": {
112115
"cniVersion": "%s",
113116
"interfaces": [
114-
{"name": "%s", "sandbox": "%s"}
117+
{"name": "eth0", "sandbox": "%s"}
115118
],
116119
"ips": [
117120
{
@@ -122,7 +125,7 @@ func makeFirewalldConf(ver, ifname string, ns ns.NetNS) []byte {
122125
}
123126
]
124127
}
125-
}`, ver, ver, ifname, ns.Path()))
128+
}`, ver, ver, ns.Path()))
126129
}
127130

128131
var _ = Describe("firewalld test", func() {
@@ -192,7 +195,7 @@ var _ = Describe("firewalld test", func() {
192195
It(fmt.Sprintf("[%s] works with a config", ver), func() {
193196
Expect(isFirewalldRunning()).To(BeTrue())
194197

195-
conf := makeFirewalldConf(ver, ifname, targetNs)
198+
conf := makeFirewalldConf(ver, targetNs)
196199
args := &skel.CmdArgs{
197200
ContainerID: "dummy",
198201
Netns: targetNs.Path(),
@@ -218,7 +221,7 @@ var _ = Describe("firewalld test", func() {
218221
It(fmt.Sprintf("[%s] defaults to the firewalld backend", ver), func() {
219222
Expect(isFirewalldRunning()).To(BeTrue())
220223

221-
conf := makeFirewalldConf(ver, ifname, targetNs)
224+
conf := makeFirewalldConf(ver, targetNs)
222225
args := &skel.CmdArgs{
223226
ContainerID: "dummy",
224227
Netns: targetNs.Path(),
@@ -236,7 +239,7 @@ var _ = Describe("firewalld test", func() {
236239
It(fmt.Sprintf("[%s] passes through the prevResult", ver), func() {
237240
Expect(isFirewalldRunning()).To(BeTrue())
238241

239-
conf := makeFirewalldConf(ver, ifname, targetNs)
242+
conf := makeFirewalldConf(ver, targetNs)
240243
args := &skel.CmdArgs{
241244
ContainerID: "dummy",
242245
Netns: targetNs.Path(),
@@ -260,7 +263,7 @@ var _ = Describe("firewalld test", func() {
260263
It(fmt.Sprintf("[%s] works with Check", ver), func() {
261264
Expect(isFirewalldRunning()).To(BeTrue())
262265

263-
conf := makeFirewalldConf(ver, ifname, targetNs)
266+
conf := makeFirewalldConf(ver, targetNs)
264267
args := &skel.CmdArgs{
265268
ContainerID: "dummy",
266269
Netns: targetNs.Path(),

plugins/meta/firewall/iptables.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,16 @@ func (ib *iptablesBackend) addRules(_ *FirewallNetConf, result *current.Result,
116116
return nil
117117
}
118118

119-
func (ib *iptablesBackend) delRules(_ *FirewallNetConf, result *current.Result, ipt *iptables.IPTables, proto iptables.Protocol) error {
119+
func (ib *iptablesBackend) delRules(_ *FirewallNetConf, result *current.Result, ipt *iptables.IPTables, proto iptables.Protocol) {
120120
rules := make([][]string, 0)
121121
for _, ip := range result.IPs {
122122
if protoForIP(ip.Address) == proto {
123123
rules = append(rules, getPrivChainRules(ipString(ip.Address))...)
124124
}
125125
}
126-
127126
if len(rules) > 0 {
128127
cleanupRules(ipt, ib.privChainName, rules)
129128
}
130-
131-
return nil
132129
}
133130

134131
func (ib *iptablesBackend) checkRules(_ *FirewallNetConf, result *current.Result, ipt *iptables.IPTables, proto iptables.Protocol) error {

plugins/meta/portmap/portmap_integ_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ var _ = Describe("portmap integration tests", func() {
8383
fmt.Fprintln(GinkgoWriter, "namespace:", targetNS.Path())
8484

8585
// Start an echo server and get the port
86-
containerPort, session, err = StartEchoServerInNamespace(targetNS)
87-
Expect(err).NotTo(HaveOccurred())
86+
containerPort, session = StartEchoServerInNamespace(targetNS)
8887
})
8988

9089
AfterEach(func() {
@@ -329,8 +328,7 @@ var _ = Describe("portmap integration tests", func() {
329328
fmt.Fprintln(GinkgoWriter, "namespace:", targetNS2.Path())
330329

331330
// Start an echo server and get the port
332-
containerPort, session2, err := StartEchoServerInNamespace(targetNS2)
333-
Expect(err).NotTo(HaveOccurred())
331+
containerPort, session2 := StartEchoServerInNamespace(targetNS2)
334332

335333
runtimeConfig2 := libcni.RuntimeConf{
336334
ContainerID: fmt.Sprintf("unit-test2-%d", hostPort),

0 commit comments

Comments
 (0)