diff --git a/libnetwork/controller.go b/libnetwork/controller.go index e32f54bacf..6daaec7ce3 100644 --- a/libnetwork/controller.go +++ b/libnetwork/controller.go @@ -947,7 +947,6 @@ func (c *Controller) NewSandbox(containerID string, options ...SandboxOption) (* err := sb.osSbox.InvokeFunc(func() { sb.osSbox.ApplyOSTweaks(sb.oslTypes) }) - if err != nil { log.G(context.TODO()).Errorf("Failed to apply performance tuning sysctls to the sandbox: %v", err) } diff --git a/libnetwork/default_gateway_linux.go b/libnetwork/default_gateway_linux.go index dabf173027..051fe2c40c 100644 --- a/libnetwork/default_gateway_linux.go +++ b/libnetwork/default_gateway_linux.go @@ -24,7 +24,6 @@ func (c *Controller) createGWNetwork() (Network, error) { NetworkOptionDriverOpts(netOption), NetworkOptionEnableIPv6(false), ) - if err != nil { return nil, fmt.Errorf("error creating external connectivity network: %v", err) } diff --git a/libnetwork/default_gateway_windows.go b/libnetwork/default_gateway_windows.go index ae99364e97..f458555c6c 100644 --- a/libnetwork/default_gateway_windows.go +++ b/libnetwork/default_gateway_windows.go @@ -9,7 +9,6 @@ import ( const libnGWNetwork = "nat" func getPlatformOption() EndpointOption { - epOption := options.Generic{ windriver.DisableICC: true, windriver.DisableDNS: true, diff --git a/libnetwork/libnetwork_internal_test.go b/libnetwork/libnetwork_internal_test.go index 146b25fa80..38f7ef6087 100644 --- a/libnetwork/libnetwork_internal_test.go +++ b/libnetwork/libnetwork_internal_test.go @@ -649,39 +649,51 @@ func (b *badDriver) CreateNetwork(nid string, options map[string]interface{}, nI } return nil } + func (b *badDriver) DeleteNetwork(nid string) error { return nil } + func (b *badDriver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, options map[string]interface{}) error { return fmt.Errorf("I will not create any endpoint") } + func (b *badDriver) DeleteEndpoint(nid, eid string) error { return nil } + func (b *badDriver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { return nil, nil } + func (b *badDriver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error { return fmt.Errorf("I will not allow any join") } + func (b *badDriver) Leave(nid, eid string) error { return nil } + func (b *badDriver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { return nil } + func (b *badDriver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error { return nil } + func (b *badDriver) Type() string { return badDriverName } + func (b *badDriver) IsBuiltIn() bool { return false } + func (b *badDriver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error { return nil } + func (b *badDriver) RevokeExternalConnectivity(nid, eid string) error { return nil } diff --git a/libnetwork/libnetwork_linux_test.go b/libnetwork/libnetwork_linux_test.go index ab5c0498fb..287858661b 100644 --- a/libnetwork/libnetwork_linux_test.go +++ b/libnetwork/libnetwork_linux_test.go @@ -565,7 +565,7 @@ func TestEnableIPv6(t *testing.T) { } // cleanup defer func() { - if err := os.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil { + if err := os.WriteFile("/etc/resolv.conf", resolvConfSystem, 0o644); err != nil { t.Fatal(err) } }() @@ -593,7 +593,7 @@ func TestEnableIPv6(t *testing.T) { t.Fatal(err) } - if err := os.WriteFile("/etc/resolv.conf", tmpResolvConf, 0644); err != nil { + if err := os.WriteFile("/etc/resolv.conf", tmpResolvConf, 0o644); err != nil { t.Fatal(err) } @@ -642,7 +642,7 @@ func TestResolvConfHost(t *testing.T) { } // cleanup defer func() { - if err := os.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil { + if err := os.WriteFile("/etc/resolv.conf", resolvConfSystem, 0o644); err != nil { t.Fatal(err) } }() @@ -653,7 +653,7 @@ func TestResolvConfHost(t *testing.T) { t.Fatal(err) } - if err := os.WriteFile("/etc/resolv.conf", tmpResolvConf, 0644); err != nil { + if err := os.WriteFile("/etc/resolv.conf", tmpResolvConf, 0o644); err != nil { t.Fatal(err) } @@ -689,7 +689,7 @@ func TestResolvConfHost(t *testing.T) { t.Fatal(err) } - fmode := (os.FileMode)(0644) + fmode := (os.FileMode)(0o644) if finfo.Mode() != fmode { t.Fatalf("Expected file mode %s, got %s", fmode.String(), finfo.Mode().String()) } @@ -720,7 +720,7 @@ func TestResolvConf(t *testing.T) { } // cleanup defer func() { - if err := os.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil { + if err := os.WriteFile("/etc/resolv.conf", resolvConfSystem, 0o644); err != nil { t.Fatal(err) } }() @@ -745,7 +745,7 @@ func TestResolvConf(t *testing.T) { t.Fatal(err) } - if err := os.WriteFile("/etc/resolv.conf", tmpResolvConf1, 0644); err != nil { + if err := os.WriteFile("/etc/resolv.conf", tmpResolvConf1, 0o644); err != nil { t.Fatal(err) } @@ -772,7 +772,7 @@ func TestResolvConf(t *testing.T) { t.Fatal(err) } - fmode := (os.FileMode)(0644) + fmode := (os.FileMode)(0o644) if finfo.Mode() != fmode { t.Fatalf("Expected file mode %s, got %s", fmode.String(), finfo.Mode().String()) } @@ -792,7 +792,7 @@ func TestResolvConf(t *testing.T) { t.Fatal(err) } - if err := os.WriteFile("/etc/resolv.conf", tmpResolvConf2, 0644); err != nil { + if err := os.WriteFile("/etc/resolv.conf", tmpResolvConf2, 0o644); err != nil { t.Fatal(err) } @@ -820,7 +820,7 @@ func TestResolvConf(t *testing.T) { t.Fatalf("Expected:\n%s\nGot:\n%s", string(expectedResolvConf1), string(content)) } - if err := os.WriteFile(resolvConfPath, tmpResolvConf3, 0644); err != nil { + if err := os.WriteFile(resolvConfPath, tmpResolvConf3, 0o644); err != nil { t.Fatal(err) } diff --git a/libnetwork/libnetwork_test.go b/libnetwork/libnetwork_test.go index b284133986..df9cfeba04 100644 --- a/libnetwork/libnetwork_test.go +++ b/libnetwork/libnetwork_test.go @@ -1172,7 +1172,7 @@ func TestInvalidRemoteDriver(t *testing.T) { fmt.Fprintln(w, `{"Implements": ["InvalidDriver"]}`) }) - if err := os.MkdirAll(specPath, 0755); err != nil { + if err := os.MkdirAll(specPath, 0o755); err != nil { t.Fatal(err) } defer func() { @@ -1181,7 +1181,7 @@ func TestInvalidRemoteDriver(t *testing.T) { } }() - if err := os.WriteFile(filepath.Join(specPath, "invalid-network-driver.spec"), []byte(server.URL), 0644); err != nil { + if err := os.WriteFile(filepath.Join(specPath, "invalid-network-driver.spec"), []byte(server.URL), 0o644); err != nil { t.Fatal(err) } @@ -1227,7 +1227,7 @@ func TestValidRemoteDriver(t *testing.T) { fmt.Fprintf(w, "null") }) - if err := os.MkdirAll(specPath, 0755); err != nil { + if err := os.MkdirAll(specPath, 0o755); err != nil { t.Fatal(err) } defer func() { @@ -1236,7 +1236,7 @@ func TestValidRemoteDriver(t *testing.T) { } }() - if err := os.WriteFile(filepath.Join(specPath, "valid-network-driver.spec"), []byte(server.URL), 0644); err != nil { + if err := os.WriteFile(filepath.Join(specPath, "valid-network-driver.spec"), []byte(server.URL), 0o644); err != nil { t.Fatal(err) } diff --git a/libnetwork/libnetwork_windows_test.go b/libnetwork/libnetwork_windows_test.go index b1a1fa667b..5f067a89d9 100644 --- a/libnetwork/libnetwork_windows_test.go +++ b/libnetwork/libnetwork_windows_test.go @@ -7,6 +7,4 @@ import ( const bridgeNetType = "nat" -var ( - specPath = filepath.Join(os.Getenv("programdata"), "docker", "plugins") -) +var specPath = filepath.Join(os.Getenv("programdata"), "docker", "plugins") diff --git a/libnetwork/network.go b/libnetwork/network.go index 596143c672..f8ed6a0503 100644 --- a/libnetwork/network.go +++ b/libnetwork/network.go @@ -1643,7 +1643,7 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error { // irrespective of whether ipam driver returned a gateway already. // If none of the above is true, libnetwork will allocate one. if cfg.Gateway != "" || d.Gateway == nil { - var gatewayOpts = map[string]string{ + gatewayOpts := map[string]string{ ipamapi.RequestAddressType: netlabel.Gateway, } if d.Gateway, _, err = ipam.RequestAddress(d.PoolID, net.ParseIP(cfg.Gateway), gatewayOpts); err != nil { @@ -1919,7 +1919,7 @@ func (n *network) Labels() map[string]string { n.mu.Lock() defer n.mu.Unlock() - var lbls = make(map[string]string, len(n.labels)) + lbls := make(map[string]string, len(n.labels)) for k, v := range n.labels { lbls[k] = v } diff --git a/libnetwork/portmapper/mock_proxy_test.go b/libnetwork/portmapper/mock_proxy_test.go index ceb7b02926..967be44f15 100644 --- a/libnetwork/portmapper/mock_proxy_test.go +++ b/libnetwork/portmapper/mock_proxy_test.go @@ -6,8 +6,7 @@ func newMockProxyCommand(proto string, hostIP net.IP, hostPort int, containerIP return &mockProxyCommand{}, nil } -type mockProxyCommand struct { -} +type mockProxyCommand struct{} func (p *mockProxyCommand) Start() error { return nil diff --git a/libnetwork/sandbox.go b/libnetwork/sandbox.go index 930ce7a102..91060db34d 100644 --- a/libnetwork/sandbox.go +++ b/libnetwork/sandbox.go @@ -1175,9 +1175,7 @@ func OptionLoadBalancer(nid string) SandboxOption { // epi.joininfo <=> epj.joininfo # ipv6 < ipv4 // epi.name <=> epj.name # bar < foo func (epi *Endpoint) Less(epj *Endpoint) bool { - var ( - prioi, prioj int - ) + var prioi, prioj int sbi, _ := epi.getSandbox() sbj, _ := epj.getSandbox() diff --git a/libnetwork/sandbox_externalkey_unix.go b/libnetwork/sandbox_externalkey_unix.go index d441e9d3a1..968d61ca41 100644 --- a/libnetwork/sandbox_externalkey_unix.go +++ b/libnetwork/sandbox_externalkey_unix.go @@ -105,7 +105,7 @@ func (c *Controller) startExternalKeyListener() error { execRoot = v } udsBase := filepath.Join(execRoot, execSubdir) - if err := os.MkdirAll(udsBase, 0600); err != nil { + if err := os.MkdirAll(udsBase, 0o600); err != nil { return err } shortCtlrID := stringid.TruncateID(c.id) @@ -114,7 +114,7 @@ func (c *Controller) startExternalKeyListener() error { if err != nil { return err } - if err := os.Chmod(uds, 0600); err != nil { + if err := os.Chmod(uds, 0o600); err != nil { l.Close() return err } diff --git a/libnetwork/service_linux.go b/libnetwork/service_linux.go index 2fcd5487c9..eecdad083f 100644 --- a/libnetwork/service_linux.go +++ b/libnetwork/service_linux.go @@ -562,7 +562,7 @@ func (sb *Sandbox) configureFWMark(vip net.IP, fwMark uint32, ingressPorts []*Po rule := append([]string{"-t", "nat", "-A", "POSTROUTING"}, ruleParams...) rules = append(rules, rule) - err := os.WriteFile("/proc/sys/net/ipv4/vs/conntrack", []byte{'1', '\n'}, 0644) + err := os.WriteFile("/proc/sys/net/ipv4/vs/conntrack", []byte{'1', '\n'}, 0o644) if err != nil { innerErr = err return diff --git a/libnetwork/service_windows.go b/libnetwork/service_windows.go index 123d162ddc..7f445019d7 100644 --- a/libnetwork/service_windows.go +++ b/libnetwork/service_windows.go @@ -25,7 +25,7 @@ func (n *network) addLBBackend(ip net.IP, lb *loadBalancer) { lb.Lock() defer lb.Unlock() - //find the load balancer IP for the network. + // find the load balancer IP for the network. var sourceVIP string for _, e := range n.Endpoints() { epInfo := e.Info() @@ -49,7 +49,7 @@ func (n *network) addLBBackend(ip net.IP, lb *loadBalancer) { if be.disabled { continue } - //Call HNS to get back ID (GUID) corresponding to the endpoint. + // Call HNS to get back ID (GUID) corresponding to the endpoint. hnsEndpoint, err := hcsshim.GetHNSEndpointByName(eid) if err != nil { log.G(context.TODO()).Errorf("Failed to find HNS ID for endpoint %v: %v", eid, err) diff --git a/libnetwork/types/types.go b/libnetwork/types/types.go index caf9328bae..6982ff3019 100644 --- a/libnetwork/types/types.go +++ b/libnetwork/types/types.go @@ -379,9 +379,10 @@ type StaticRoute struct { func (r *StaticRoute) GetCopy() *StaticRoute { d := GetIPNetCopy(r.Destination) nh := GetIPCopy(r.NextHop) - return &StaticRoute{Destination: d, - RouteType: r.RouteType, - NextHop: nh, + return &StaticRoute{ + Destination: d, + RouteType: r.RouteType, + NextHop: nh, } }