Skip to content

Commit

Permalink
lint code
Browse files Browse the repository at this point in the history
Signed-off-by: Poorunga <[email protected]>
  • Loading branch information
Poorunga committed Nov 25, 2023
1 parent 52b2e59 commit 956b6c7
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 60 deletions.
4 changes: 2 additions & 2 deletions cmd/edgemesh-cni/cmd/command_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"k8s.io/klog/v2"
)

// CmdAdd TODO: file log
func CmdAdd(args *skel.CmdArgs) (err error) {
// Add TODO: file log
func Add(args *skel.CmdArgs) (err error) {
defer func() {
if e := recover(); e != nil {
msg := fmt.Sprintf("EdgeMesh CNI panicked during ADD: %s", e)
Expand Down
2 changes: 1 addition & 1 deletion cmd/edgemesh-cni/cmd/command_del.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// TODO: file log
func CmdDel(args *skel.CmdArgs) (err error) {
func Del(args *skel.CmdArgs) (err error) {
defer func() {
if e := recover(); e != nil {
msg := fmt.Sprintf("EdgeMesh CNI panicked during DEL: %s", e)
Expand Down
2 changes: 1 addition & 1 deletion cmd/edgemesh-cni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ var (
)

func main() {
skel.PluginMain(cmd.CmdAdd, nil, cmd.CmdDel, cni.All, "EdgeMesh CNI plugin "+version)
skel.PluginMain(cmd.Add, nil, cmd.Del, cni.All, "EdgeMesh CNI plugin "+version)
}
4 changes: 2 additions & 2 deletions pkg/apis/config/v1alpha1/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var defaultLoadBalancerConfig = &LoadBalancer{
},
}

func newDefaultEdgeCNIConfig(configPath string) *EdgeCNIConfig {
func newDefaultEdgeCNIConfig() *EdgeCNIConfig {
return &EdgeCNIConfig{
Enable: false,
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func NewDefaultEdgeMeshAgentConfig(configPath string) *EdgeMeshAgentConfig {
LoadBalancer: defaultLoadBalancerConfig,
},
EdgeTunnelConfig: newDefaultEdgeTunnelConfig(configPath),
EdgeCNIConfig: newDefaultEdgeCNIConfig(configPath),
EdgeCNIConfig: newDefaultEdgeCNIConfig(),
},
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/dns/corefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ func UpdateCorefile(cfg *v1alpha1.EdgeDNSConfig, kubeClient kubernetes.Interface
upstreamServers = removeDuplicate(upstreamServers)
if len(upstreamServers) == 0 {
return fmt.Errorf("failed to get nodelocal dns upstream servers")
} else {
klog.Infof("nodelocal dns upstream servers: %v", upstreamServers)
}
klog.Infof("nodelocal dns upstream servers: %v", upstreamServers)
cacheTTL = cfg.CacheDNS.CacheTTL
// disable coredns kubernetes plugin.
kubernetesPlugin = ""
Expand Down
1 change: 0 additions & 1 deletion pkg/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/coredns/caddy"
"github.com/coredns/coredns/coremain"

// blank imports to make sure the plugin code is pulled in from vendor
_ "github.com/coredns/coredns/plugin/bind"
_ "github.com/coredns/coredns/plugin/cache"
Expand Down
2 changes: 1 addition & 1 deletion pkg/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (gw *EdgeGateway) OnGatewayAdd(gateway *istiv1alpha3.Gateway) {
}

// OnGatewayUpdate update a gateway server
func (gw *EdgeGateway) OnGatewayUpdate(oldGateway, gateway *istiv1alpha3.Gateway) {
func (gw *EdgeGateway) OnGatewayUpdate(_, gateway *istiv1alpha3.Gateway) {
gw.lock.Lock()
defer gw.lock.Unlock()

Expand Down
4 changes: 2 additions & 2 deletions pkg/gateway/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ func (p *HTTP) Process() {
}

// passthrough
httpToTcp := &TCP{
httpToTCP := &TCP{
Conn: p.Conn,
SvcNamespace: p.SvcNamespace,
SvcName: p.SvcName,
SvcPort: p.SvcPort,
UpgradeReq: req,
}
httpToTcp.Process()
httpToTCP.Process()
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/gateway/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ func TestUriMatch(t *testing.T) {
{MatchType: &networkingv1alpha3.StringMatch_Prefix{Prefix: "/hello*"}},
{MatchType: &networkingv1alpha3.StringMatch_Prefix{Prefix: "/)(j3*a0"}},
}
reqUris := []string{
reqURIs := []string{
"/",
"/abc",
"/abcd",
"/xyz",
"/hello-world",
}
for _, reqUri := range reqUris {
for _, reqURI := range reqURIs {
for _, uriRule := range uriRules {
t.Log(uriMatch(uriRule, reqUri))
t.Log(uriMatch(uriRule, reqURI))
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/gateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ func (srv *Server) newProto(conn net.Conn) (Protocol, error) {
}
}
return nil, fmt.Errorf("no match virtual service")
} else {
return nil, fmt.Errorf("protocol %s not supported", srv.options.Protocol)
}
return nil, fmt.Errorf("protocol %s not supported", srv.options.Protocol)
}
return nil, fmt.Errorf("egress traffic not supported")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/loadbalancer/hashring.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func getConsistentHashKey(dr *istioapi.DestinationRule) HashKey {
}
switch consistentHashLb := lbPolicy.ConsistentHash.HashKey.(type) {
case *istiov1alpha3.LoadBalancerSettings_ConsistentHashLB_HttpHeaderName:
return HashKey{Type: HttpHeader, Key: consistentHashLb.HttpHeaderName}
return HashKey{Type: HTTPHeader, Key: consistentHashLb.HttpHeaderName}
case *istiov1alpha3.LoadBalancerSettings_ConsistentHashLB_HttpCookie:
klog.Errorf("http cookie is not supported as a hash key")
return HashKey{}
Expand Down
5 changes: 3 additions & 2 deletions pkg/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (lb *LoadBalancer) OnServiceAdd(service *v1.Service) {
lb.cleanupStaleStickySessions()
}

func (lb *LoadBalancer) OnServiceUpdate(oldService, service *v1.Service) {
func (lb *LoadBalancer) OnServiceUpdate(_, service *v1.Service) {
lb.mu.Lock()
defer lb.mu.Unlock()

Expand Down Expand Up @@ -689,7 +689,7 @@ func (lb *LoadBalancer) TryConnectEndpoints(service proxy.ServicePortName, srcAd
continue
}
if req != nil {
reqBytes, err := netutil.HttpRequestToBytes(req)
reqBytes, err := netutil.HTTPRequestToBytes(req)
if err == nil {
_, err = outConn.Write(reqBytes)
if err != nil {
Expand Down Expand Up @@ -735,6 +735,7 @@ func (lb *LoadBalancer) dialEndpoint(protocol, endpoint string) (net.Conn, error
}

func (lb *LoadBalancer) NextEndpoint(svcPort proxy.ServicePortName, srcAddr net.Addr, sessionAffinityReset bool) (string, error) {
klog.V(4).InfoS("", svcPort, srcAddr, sessionAffinityReset)
return "", nil
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/loadbalancer/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
Random = "RANDOM"
ConsistentHash = "CONSISTENT_HASH"

HttpHeader = "HTTP_HEADER"
HTTPHeader = "HTTP_HEADER"
UserSourceIP = "USER_SOURCE_IP"
)

Expand All @@ -44,15 +44,15 @@ func (*RoundRobinPolicy) Name() string {
return RoundRobin
}

func (*RoundRobinPolicy) Update(oldDr, dr *istioapi.DestinationRule) {}
func (*RoundRobinPolicy) Update(_, _ *istioapi.DestinationRule) {}

func (*RoundRobinPolicy) Pick(endpoints []string, srcAddr net.Addr, netConn net.Conn, cliReq *http.Request) (string, *http.Request, error) {
func (*RoundRobinPolicy) Pick(_ []string, _ net.Addr, _ net.Conn, cliReq *http.Request) (string, *http.Request, error) {
// RoundRobinPolicy is an empty implementation and we won't use it,
// the outer round-robin policy will be used next.
return "", cliReq, fmt.Errorf("call RoundRobinPolicy is forbidden")
}

func (*RoundRobinPolicy) Sync(endpoints []string) {}
func (*RoundRobinPolicy) Sync(_ []string) {}

func (*RoundRobinPolicy) Release() {}

Expand All @@ -68,16 +68,16 @@ func (rd *RandomPolicy) Name() string {
return Random
}

func (rd *RandomPolicy) Update(oldDr, dr *istioapi.DestinationRule) {}
func (rd *RandomPolicy) Update(_, _ *istioapi.DestinationRule) {}

func (rd *RandomPolicy) Pick(endpoints []string, srcAddr net.Addr, netConn net.Conn, cliReq *http.Request) (string, *http.Request, error) {
func (rd *RandomPolicy) Pick(endpoints []string, _ net.Addr, _ net.Conn, cliReq *http.Request) (string, *http.Request, error) {
rd.lock.Lock()
k := rand.Int() % len(endpoints)
rd.lock.Unlock()
return endpoints[k], cliReq, nil
}

func (rd *RandomPolicy) Sync(endpoints []string) {}
func (rd *RandomPolicy) Sync(_ []string) {}

func (rd *RandomPolicy) Release() {}

Expand All @@ -100,20 +100,20 @@ func (ch *ConsistentHashPolicy) Name() string {
return ConsistentHash
}

func (ch *ConsistentHashPolicy) Update(oldDr, dr *istioapi.DestinationRule) {
func (ch *ConsistentHashPolicy) Update(_, dr *istioapi.DestinationRule) {
ch.lock.Lock()
ch.hashKey = getConsistentHashKey(dr)
ch.lock.Unlock()
}

func (ch *ConsistentHashPolicy) Pick(endpoints []string, srcAddr net.Addr, netConn net.Conn, cliReq *http.Request) (endpoint string, req *http.Request, err error) {
func (ch *ConsistentHashPolicy) Pick(_ []string, srcAddr net.Addr, netConn net.Conn, cliReq *http.Request) (endpoint string, req *http.Request, err error) {
ch.lock.Lock()
defer ch.lock.Unlock()

req = cliReq
var keyValue string
switch ch.hashKey.Type {
case HttpHeader:
case HTTPHeader:
if req == nil {
req, err = http.ReadRequest(bufio.NewReader(netConn))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// EdgeProxy is used for traffic proxy
type EdgeProxy struct {
Config *v1alpha1.EdgeProxyConfig
ProxyServer *ProxyServer
ProxyServer *Server
Socks5Proxy *Socks5Proxy
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/proxy/proxysocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (tcp *tcpProxySocket) ListenPort() int {
return tcp.port
}

func (tcp *tcpProxySocket) ProxyLoop(service proxy.ServicePortName, myInfo *userspace.ServiceInfo, loadBalancer userspace.LoadBalancer) {
func (tcp *tcpProxySocket) ProxyLoop(service proxy.ServicePortName, myInfo *userspace.ServiceInfo, _ userspace.LoadBalancer) {
for {
if !myInfo.IsAlive() {
// The service port was closed or replaced.
Expand Down Expand Up @@ -123,7 +123,7 @@ func (udp *udpProxySocket) Addr() net.Addr {
return udp.LocalAddr()
}

func (udp *udpProxySocket) ProxyLoop(service proxy.ServicePortName, myInfo *userspace.ServiceInfo, loadBalancer userspace.LoadBalancer) {
func (udp *udpProxySocket) ProxyLoop(service proxy.ServicePortName, myInfo *userspace.ServiceInfo, _ userspace.LoadBalancer) {
var buffer [4096]byte // 4KiB should be enough for most whole-packets
for {
if !myInfo.IsAlive() {
Expand Down
12 changes: 6 additions & 6 deletions pkg/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
// Copy and update from https://github.com/kubernetes/kubernetes/blob/v1.23.0/cmd/kube-proxy/app/server.go and
// https://github.com/kubernetes/kubernetes/blob/v1.23.0/cmd/kube-proxy/app/server_others.go.

// ProxyServer represents all the parameters required to start the Kubernetes proxy server.
type ProxyServer struct {
// Server represents all the parameters required to start the Kubernetes proxy server.
type Server struct {
kubeClient clientset.Interface
istioClient istioclientset.Interface
IptInterface utiliptables.Interface
Expand Down Expand Up @@ -64,7 +64,7 @@ func newProxyServer(
lbConfig *v1alpha1.LoadBalancer,
client clientset.Interface,
istioClient istioclientset.Interface,
serviceFilterMode defaults.ServiceFilterMode) (*ProxyServer, error) {
serviceFilterMode defaults.ServiceFilterMode) (*Server, error) {
klog.V(0).Info("Using userspace Proxier.")

// Create a iptables utils.
Expand All @@ -91,7 +91,7 @@ func newProxyServer(
return nil, fmt.Errorf("unable to create proxier: %v", err)
}

return &ProxyServer{
return &Server{
kubeClient: client,
istioClient: istioClient,
IptInterface: iptInterface,
Expand All @@ -103,7 +103,7 @@ func newProxyServer(
}, nil
}

func (s *ProxyServer) Run() error {
func (s *Server) Run() error {
// Determine the service filter mode.
// By default, we will proxy all services that are not labeled with the LabelEdgeMeshServiceProxyName label.
operation := selection.DoesNotExist
Expand Down Expand Up @@ -159,7 +159,7 @@ func (s *ProxyServer) Run() error {
}

// CleanupAndExit remove iptables rules
func (s *ProxyServer) CleanupAndExit() error {
func (s *Server) CleanupAndExit() error {
ipts := []utiliptables.Interface{
utiliptables.New(s.execer, utiliptables.ProtocolIPv4),
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/proxy/socks5_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (s *Socks5Proxy) HandleSocksProxy(conn net.Conn) {
return
}

targetIP, err := s.getTargetIpByNodeName(s.SocksHandle.Request.DstAddr)
targetIP, err := s.getTargetIPByNodeName(s.SocksHandle.Request.DstAddr)
if err != nil {
klog.Errorf("Unable to get destination IP, %v", err)
return
Expand Down Expand Up @@ -271,10 +271,10 @@ func proxyConnectToRemote(host string, targetIP string, port int32, conn net.Con
klog.Infof("Success proxy to %v", host)
}

// getTargetIpByNodeName Returns the real IP address of the node
// getTargetIPByNodeName Returns the real IP address of the node
// We must obtain the real IP address of the node to communicate, so we need to query the IP address of the edgemesh-agent on the node
// Because users may modify the IP addresses of edgemesh-0 and edgecore. If used directly, it may cause errors
func (s *Socks5Proxy) getTargetIpByNodeName(nodeName string) (targetIP string, err error) {
func (s *Socks5Proxy) getTargetIPByNodeName(nodeName string) (targetIP string, err error) {
pods, err := s.kubeClient.CoreV1().Pods(s.Config.Namespace).List(context.Background(), metav1.ListOptions{FieldSelector: "spec.nodeName=" + nodeName, LabelSelector: LabelKubeedge})
if err != nil {
return "", err
Expand Down
6 changes: 3 additions & 3 deletions pkg/tunnel/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func buildLimitOpt(scalingLimits *rcmgr.ScalingLimitConfig, opts ...rcmgr.Option
// The resource manager expects a limiter, se we create one from our limits.
limiter := rcmgr.NewFixedLimiter(limits)
// Initialize the resource manager
if rm, err := rcmgr.NewResourceManager(limiter, opts...); err != nil {
rm, err := rcmgr.NewResourceManager(limiter, opts...)
if err != nil {
return nil, err
} else {
return libp2p.ResourceManager(rm), nil
}
return libp2p.ResourceManager(rm), nil
}

func CreateLimitOpt(config *v1alpha1.TunnelLimitConfig, opts ...rcmgr.Option) (libp2p.Option, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/net/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"k8s.io/klog/v2"
)

// HttpRequestToBytes transforms http.Request to bytes
func HttpRequestToBytes(req *http.Request) ([]byte, error) {
// HTTPRequestToBytes transforms http.Request to bytes
func HTTPRequestToBytes(req *http.Request) ([]byte, error) {
if req == nil {
return nil, fmt.Errorf("http request nil")
}
Expand Down
Loading

0 comments on commit 956b6c7

Please sign in to comment.