From 122ad6d349ad72e66084fb992cee9a9519a1d0dd Mon Sep 17 00:00:00 2001 From: manuelbuil Date: Wed, 20 Nov 2024 11:02:17 +0100 Subject: [PATCH] Use the standard context library Signed-off-by: manuelbuil --- main.go | 8 ++++---- pkg/backend/alloc/alloc.go | 3 ++- pkg/backend/common.go | 2 +- pkg/backend/extension/extension.go | 7 +++---- pkg/backend/extension/extension_network.go | 6 ++---- pkg/backend/hostgw/hostgw.go | 2 +- pkg/backend/hostgw/hostgw_windows.go | 2 +- pkg/backend/ipip/ipip.go | 2 +- pkg/backend/ipsec/handle_charon.go | 2 +- pkg/backend/ipsec/ipsec.go | 3 +-- pkg/backend/ipsec/ipsec_network.go | 2 +- pkg/backend/manager.go | 2 +- pkg/backend/route_network.go | 2 +- pkg/backend/route_network_windows.go | 2 +- pkg/backend/simple_network.go | 3 ++- pkg/backend/tencentvpc/tencentvpc.go | 2 +- pkg/backend/udp/udp_amd64.go | 2 +- pkg/backend/udp/udp_network_amd64.go | 2 +- pkg/backend/vxlan/vxlan.go | 2 +- pkg/backend/vxlan/vxlan_network.go | 2 +- pkg/backend/vxlan/vxlan_network_windows.go | 2 +- pkg/backend/vxlan/vxlan_windows.go | 5 +++-- pkg/backend/wireguard/device.go | 2 +- pkg/backend/wireguard/wireguard.go | 2 +- pkg/backend/wireguard/wireguard_network.go | 2 +- pkg/subnet/etcd/local_manager.go | 2 +- pkg/subnet/etcd/mock_registry.go | 2 +- pkg/subnet/etcd/registry.go | 2 +- pkg/subnet/etcd/registry_test.go | 5 +++-- pkg/subnet/etcd/subnet_test.go | 14 +++++++++----- pkg/subnet/kube/kube.go | 2 +- pkg/subnet/subnet.go | 2 +- 32 files changed, 52 insertions(+), 48 deletions(-) diff --git a/main.go b/main.go index e8ab0626eb..1ae72cdbaf 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ package main import ( + "context" "errors" "flag" "fmt" @@ -40,10 +41,8 @@ import ( "github.com/flannel-io/flannel/pkg/trafficmngr/iptables" "github.com/flannel-io/flannel/pkg/trafficmngr/nftables" "github.com/flannel-io/flannel/pkg/version" - "golang.org/x/net/context" - log "k8s.io/klog/v2" - "github.com/joho/godotenv" + log "k8s.io/klog/v2" // Backends need to be imported for their init() to get executed and them to register "github.com/coreos/go-systemd/v22/daemon" @@ -508,7 +507,8 @@ func mustRunHealthz(stopChan <-chan struct{}, wg *sync.WaitGroup) { <-stopChan // create new context with timeout for http server to shutdown gracefully - ctx, _ := context.WithTimeout(context.Background(), 3*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() if err := server.Shutdown(ctx); err != nil { log.Errorf("Shutdown healthz server error. %v", err) } diff --git a/pkg/backend/alloc/alloc.go b/pkg/backend/alloc/alloc.go index 1641676e9d..920f5717a9 100644 --- a/pkg/backend/alloc/alloc.go +++ b/pkg/backend/alloc/alloc.go @@ -18,11 +18,12 @@ import ( "fmt" "sync" + "context" + "github.com/flannel-io/flannel/pkg/backend" "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" ) func init() { diff --git a/pkg/backend/common.go b/pkg/backend/common.go index 3ff350eee7..33a5d37c86 100644 --- a/pkg/backend/common.go +++ b/pkg/backend/common.go @@ -15,12 +15,12 @@ package backend import ( + "context" "net" "sync" "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" ) type ExternalInterface struct { diff --git a/pkg/backend/extension/extension.go b/pkg/backend/extension/extension.go index 111a04b5f5..1e6ad775ee 100644 --- a/pkg/backend/extension/extension.go +++ b/pkg/backend/extension/extension.go @@ -15,20 +15,19 @@ package extension import ( + "context" + "encoding/json" "fmt" "io" "os" - "strings" - - "encoding/json" "os/exec" + "strings" "sync" "github.com/flannel-io/flannel/pkg/backend" "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/extension/extension_network.go b/pkg/backend/extension/extension_network.go index 009712fb3e..52de707bc9 100644 --- a/pkg/backend/extension/extension_network.go +++ b/pkg/backend/extension/extension_network.go @@ -15,12 +15,10 @@ package extension import ( + "context" "encoding/json" - "sync" - - "golang.org/x/net/context" - "fmt" + "sync" "github.com/flannel-io/flannel/pkg/backend" "github.com/flannel-io/flannel/pkg/lease" diff --git a/pkg/backend/hostgw/hostgw.go b/pkg/backend/hostgw/hostgw.go index 64871bf5be..595f0f87bc 100644 --- a/pkg/backend/hostgw/hostgw.go +++ b/pkg/backend/hostgw/hostgw.go @@ -18,6 +18,7 @@ package hostgw import ( + "context" "fmt" "sync" @@ -26,7 +27,6 @@ import ( "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" "github.com/vishvananda/netlink" - "golang.org/x/net/context" ) func init() { diff --git a/pkg/backend/hostgw/hostgw_windows.go b/pkg/backend/hostgw/hostgw_windows.go index 011721bfdc..fa15ba7874 100644 --- a/pkg/backend/hostgw/hostgw_windows.go +++ b/pkg/backend/hostgw/hostgw_windows.go @@ -15,6 +15,7 @@ package hostgw import ( + "context" "fmt" "strings" "sync" @@ -27,7 +28,6 @@ import ( "github.com/flannel-io/flannel/pkg/routing" "github.com/flannel-io/flannel/pkg/subnet" "github.com/pkg/errors" - "golang.org/x/net/context" "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/wait" log "k8s.io/klog/v2" diff --git a/pkg/backend/ipip/ipip.go b/pkg/backend/ipip/ipip.go index c07960e5da..2774b98cd2 100644 --- a/pkg/backend/ipip/ipip.go +++ b/pkg/backend/ipip/ipip.go @@ -18,6 +18,7 @@ package ipip import ( + "context" "encoding/json" "fmt" "sync" @@ -28,7 +29,6 @@ import ( "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" "github.com/vishvananda/netlink" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/ipsec/handle_charon.go b/pkg/backend/ipsec/handle_charon.go index 6ca5656476..0bdeadc803 100644 --- a/pkg/backend/ipsec/handle_charon.go +++ b/pkg/backend/ipsec/handle_charon.go @@ -17,6 +17,7 @@ package ipsec import ( + "context" "fmt" "net" "os" @@ -28,7 +29,6 @@ import ( "github.com/bronze1man/goStrongswanVici" "github.com/flannel-io/flannel/pkg/lease" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/ipsec/ipsec.go b/pkg/backend/ipsec/ipsec.go index a9528f9b0c..49e76d9c0a 100644 --- a/pkg/backend/ipsec/ipsec.go +++ b/pkg/backend/ipsec/ipsec.go @@ -17,12 +17,11 @@ package ipsec import ( + "context" "encoding/json" "fmt" "sync" - "golang.org/x/net/context" - "github.com/flannel-io/flannel/pkg/backend" "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" diff --git a/pkg/backend/ipsec/ipsec_network.go b/pkg/backend/ipsec/ipsec_network.go index a4349ce2ed..24088db8fd 100644 --- a/pkg/backend/ipsec/ipsec_network.go +++ b/pkg/backend/ipsec/ipsec_network.go @@ -17,6 +17,7 @@ package ipsec import ( + "context" "fmt" "net" "strconv" @@ -26,7 +27,6 @@ import ( "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" "github.com/vishvananda/netlink" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/manager.go b/pkg/backend/manager.go index af006f74c9..0cfa359967 100644 --- a/pkg/backend/manager.go +++ b/pkg/backend/manager.go @@ -15,12 +15,12 @@ package backend import ( + "context" "fmt" "strings" "sync" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" ) var constructors = make(map[string]BackendCtor) diff --git a/pkg/backend/route_network.go b/pkg/backend/route_network.go index 803cd2a7ee..b54426070b 100644 --- a/pkg/backend/route_network.go +++ b/pkg/backend/route_network.go @@ -19,6 +19,7 @@ package backend import ( "bytes" + "context" "net" "sync" "time" @@ -26,7 +27,6 @@ import ( "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" "github.com/vishvananda/netlink" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/route_network_windows.go b/pkg/backend/route_network_windows.go index 66dee3a220..0631473a8d 100644 --- a/pkg/backend/route_network_windows.go +++ b/pkg/backend/route_network_windows.go @@ -15,6 +15,7 @@ package backend import ( + "context" "strings" "sync" "time" @@ -22,7 +23,6 @@ import ( "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/routing" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/simple_network.go b/pkg/backend/simple_network.go index 39d7e456b5..e5421e7695 100644 --- a/pkg/backend/simple_network.go +++ b/pkg/backend/simple_network.go @@ -15,8 +15,9 @@ package backend import ( + "context" + "github.com/flannel-io/flannel/pkg/lease" - "golang.org/x/net/context" ) type SimpleNetwork struct { diff --git a/pkg/backend/tencentvpc/tencentvpc.go b/pkg/backend/tencentvpc/tencentvpc.go index 37c182952d..7c6cbf9047 100644 --- a/pkg/backend/tencentvpc/tencentvpc.go +++ b/pkg/backend/tencentvpc/tencentvpc.go @@ -17,6 +17,7 @@ package tencentvpc import ( + "context" "encoding/json" "fmt" "io" @@ -31,7 +32,6 @@ import ( "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/udp/udp_amd64.go b/pkg/backend/udp/udp_amd64.go index 246bca78ae..ae7bda73dc 100644 --- a/pkg/backend/udp/udp_amd64.go +++ b/pkg/backend/udp/udp_amd64.go @@ -17,6 +17,7 @@ package udp import ( + "context" "encoding/json" "fmt" "sync" @@ -25,7 +26,6 @@ import ( "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" ) func init() { diff --git a/pkg/backend/udp/udp_network_amd64.go b/pkg/backend/udp/udp_network_amd64.go index 6096dbef4d..20f24fa427 100644 --- a/pkg/backend/udp/udp_network_amd64.go +++ b/pkg/backend/udp/udp_network_amd64.go @@ -18,6 +18,7 @@ package udp import ( + "context" "fmt" "net" "os" @@ -29,7 +30,6 @@ import ( "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" "github.com/vishvananda/netlink" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/vxlan/vxlan.go b/pkg/backend/vxlan/vxlan.go index 47a0c1fbdf..815a3c970c 100644 --- a/pkg/backend/vxlan/vxlan.go +++ b/pkg/backend/vxlan/vxlan.go @@ -54,6 +54,7 @@ package vxlan // this is called "directRouting" import ( + "context" "encoding/json" "fmt" "net" @@ -63,7 +64,6 @@ import ( "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/vxlan/vxlan_network.go b/pkg/backend/vxlan/vxlan_network.go index e697b2a8fc..4d8698510a 100644 --- a/pkg/backend/vxlan/vxlan_network.go +++ b/pkg/backend/vxlan/vxlan_network.go @@ -17,6 +17,7 @@ package vxlan import ( + "context" "encoding/json" "net" "sync" @@ -28,7 +29,6 @@ import ( "github.com/flannel-io/flannel/pkg/retry" "github.com/flannel-io/flannel/pkg/subnet" "github.com/vishvananda/netlink" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/vxlan/vxlan_network_windows.go b/pkg/backend/vxlan/vxlan_network_windows.go index 74cb70b7c6..311f0d7bfa 100644 --- a/pkg/backend/vxlan/vxlan_network_windows.go +++ b/pkg/backend/vxlan/vxlan_network_windows.go @@ -15,6 +15,7 @@ package vxlan import ( + "context" "encoding/json" "net" "strings" @@ -25,7 +26,6 @@ import ( "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/vxlan/vxlan_windows.go b/pkg/backend/vxlan/vxlan_windows.go index e0720aec9e..33170ed614 100644 --- a/pkg/backend/vxlan/vxlan_windows.go +++ b/pkg/backend/vxlan/vxlan_windows.go @@ -22,8 +22,10 @@ package vxlan // In this scheme the scaling of table entries (per host) is: // - 1 network entry for the overlay network // - 1 endpoint per local container -// - N remote endpoints remote node (total endpoints = +// - N remote endpoints remote node (total endpoints = N * number of remote nodes) + import ( + "context" "encoding/json" "errors" "fmt" @@ -35,7 +37,6 @@ import ( "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/backend/wireguard/device.go b/pkg/backend/wireguard/device.go index ea5be953a0..69c40126ec 100644 --- a/pkg/backend/wireguard/device.go +++ b/pkg/backend/wireguard/device.go @@ -17,6 +17,7 @@ package wireguard import ( + "context" "errors" "fmt" "net" @@ -28,7 +29,6 @@ import ( "github.com/flannel-io/flannel/pkg/ip" "github.com/vishvananda/netlink" - "golang.org/x/net/context" "golang.zx2c4.com/wireguard/wgctrl" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" log "k8s.io/klog/v2" diff --git a/pkg/backend/wireguard/wireguard.go b/pkg/backend/wireguard/wireguard.go index bc7b0e89de..352f3c5a29 100644 --- a/pkg/backend/wireguard/wireguard.go +++ b/pkg/backend/wireguard/wireguard.go @@ -17,6 +17,7 @@ package wireguard import ( + "context" "encoding/json" "fmt" "net" @@ -27,7 +28,6 @@ import ( "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" ) type Mode string diff --git a/pkg/backend/wireguard/wireguard_network.go b/pkg/backend/wireguard/wireguard_network.go index 36ed46b2c7..06531e98dd 100644 --- a/pkg/backend/wireguard/wireguard_network.go +++ b/pkg/backend/wireguard/wireguard_network.go @@ -17,6 +17,7 @@ package wireguard import ( + "context" "encoding/json" "fmt" "net" @@ -26,7 +27,6 @@ import ( "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/subnet/etcd/local_manager.go b/pkg/subnet/etcd/local_manager.go index bf90b91924..128d775640 100644 --- a/pkg/subnet/etcd/local_manager.go +++ b/pkg/subnet/etcd/local_manager.go @@ -15,6 +15,7 @@ package etcd import ( + "context" "errors" "fmt" "strconv" @@ -25,7 +26,6 @@ import ( "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/subnet/etcd/mock_registry.go b/pkg/subnet/etcd/mock_registry.go index 7c3eb9cb3f..f3226a9cc1 100644 --- a/pkg/subnet/etcd/mock_registry.go +++ b/pkg/subnet/etcd/mock_registry.go @@ -15,6 +15,7 @@ package etcd import ( + "context" "fmt" "sync" "time" @@ -23,7 +24,6 @@ import ( "github.com/flannel-io/flannel/pkg/lease" "github.com/jonboulle/clockwork" "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/subnet/etcd/registry.go b/pkg/subnet/etcd/registry.go index 84569d1e81..8b2f62f3d0 100644 --- a/pkg/subnet/etcd/registry.go +++ b/pkg/subnet/etcd/registry.go @@ -15,6 +15,7 @@ package etcd import ( + "context" "crypto/tls" "encoding/json" "errors" @@ -31,7 +32,6 @@ import ( "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" "go.etcd.io/etcd/client/pkg/v3/tlsutil" etcd "go.etcd.io/etcd/client/v3" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) diff --git a/pkg/subnet/etcd/registry_test.go b/pkg/subnet/etcd/registry_test.go index 9bb5389b69..1de8f34158 100644 --- a/pkg/subnet/etcd/registry_test.go +++ b/pkg/subnet/etcd/registry_test.go @@ -16,6 +16,7 @@ package etcd import ( "bytes" + "context" "fmt" "sync" "testing" @@ -25,7 +26,6 @@ import ( "github.com/flannel-io/flannel/pkg/lease" etcd "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/tests/v3/integration" - "golang.org/x/net/context" ) func newTestEtcdRegistry(t *testing.T, ctx context.Context, client *etcd.Client) (Registry, etcd.KV) { @@ -105,7 +105,8 @@ func TestEtcdRegistry(t *testing.T) { client := clus.RandClient() - ctx, _ := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() r, kvApi := newTestEtcdRegistry(t, ctx, client) diff --git a/pkg/subnet/etcd/subnet_test.go b/pkg/subnet/etcd/subnet_test.go index 4c5084aed1..3c66d1fb86 100644 --- a/pkg/subnet/etcd/subnet_test.go +++ b/pkg/subnet/etcd/subnet_test.go @@ -15,6 +15,7 @@ package etcd import ( + "context" "encoding/json" "path" "reflect" @@ -26,7 +27,6 @@ import ( "github.com/flannel-io/flannel/pkg/subnet" etcd "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/tests/v3/integration" - "golang.org/x/net/context" log "k8s.io/klog/v2" ) @@ -195,7 +195,8 @@ func TestWatchLeaseAdded(t *testing.T) { client := clus.RandClient() - ctx, _ := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() r, kvApi := newTestEtcdRegistry(t, ctx, client) initTestRegistry(ctx, t, r, kvApi) @@ -262,7 +263,8 @@ func TestWatchLeaseRemoved(t *testing.T) { client := clus.RandClient() - ctx, _ := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() r, kvApi := newTestEtcdRegistry(t, ctx, client) netKey := "/coreos.com/network/config" @@ -340,7 +342,8 @@ func TestCompleteLease(t *testing.T) { client := clus.RandClient() - ctx, _ := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() r, kvApi := newTestEtcdRegistry(t, ctx, client) initTestRegistry(ctx, t, r, kvApi) @@ -404,7 +407,8 @@ func TestRenewLease(t *testing.T) { client := clus.RandClient() - ctx, _ := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() r, kvApi := newTestEtcdRegistry(t, ctx, client) netKey := "/coreos.com/network/config" diff --git a/pkg/subnet/kube/kube.go b/pkg/subnet/kube/kube.go index 836455c2cb..e389ec92b9 100644 --- a/pkg/subnet/kube/kube.go +++ b/pkg/subnet/kube/kube.go @@ -15,6 +15,7 @@ package kube import ( + "context" "encoding/json" "errors" "fmt" @@ -28,7 +29,6 @@ import ( "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" "github.com/flannel-io/flannel/pkg/subnet" - "golang.org/x/net/context" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" diff --git a/pkg/subnet/subnet.go b/pkg/subnet/subnet.go index eaa5a393ea..a60c5744d7 100644 --- a/pkg/subnet/subnet.go +++ b/pkg/subnet/subnet.go @@ -15,6 +15,7 @@ package subnet import ( + "context" "fmt" "net" "os" @@ -25,7 +26,6 @@ import ( "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" - "golang.org/x/net/context" log "k8s.io/klog/v2" )