kubenetworks/kubevpn

View on GitHub

Showing 526 of 526 total issues

Function CmdConnect has 14 return statements (exceeds 4 allowed).
Open

func CmdConnect(f cmdutil.Factory) *cobra.Command {
    var connect = &handler.ConnectOptions{}
    var extraRoute = &handler.ExtraRouteInfo{}
    var sshConf = &pkgssh.SshConfig{}
    var transferImage, foreground, lite bool
Severity: Major
Found in cmd/kubevpn/cmds/connect.go - About 1 hr to fix

    Function recursiveTar has 14 return statements (exceeds 4 allowed).
    Open

    func recursiveTar(srcDir, srcFile localPath, destDir, destFile remotePath, tw *tar.Writer) error {
        matchedPaths, err := srcDir.Join(srcFile).Glob()
        if err != nil {
            return err
        }
    Severity: Major
    Found in pkg/cp/cp.go - About 1 hr to fix

      Function createTun has 14 return statements (exceeds 4 allowed).
      Open

      func createTun(cfg Config) (conn net.Conn, itf *net.Interface, err error) {
          if cfg.Addr == "" && cfg.Addr6 == "" {
              err = fmt.Errorf("IPv4 address and IPv6 address can not be empty at same time")
              return
          }
      Severity: Major
      Found in pkg/tun/tun_linux.go - About 1 hr to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    if lite {
                        resp, err := cli.ConnectFork(cmd.Context(), req)
                        if err != nil {
                            return err
                        }
        Severity: Major
        Found in cmd/kubevpn/cmds/connect.go and 1 other location - About 1 hr to fix
        cmd/kubevpn/cmds/connect.go on lines 121..137

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 150.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    } else {
                        resp, err := cli.Connect(cmd.Context(), req)
                        if err != nil {
                            return err
                        }
        Severity: Major
        Found in cmd/kubevpn/cmds/connect.go and 1 other location - About 1 hr to fix
        cmd/kubevpn/cmds/connect.go on lines 105..121

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 150.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Function createTun has 58 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func createTun(cfg Config) (conn net.Conn, itf *net.Interface, err error) {
            if cfg.Addr == "" && cfg.Addr6 == "" {
                err = fmt.Errorf("IPv4 address and IPv6 address can not be empty at same time")
                return
            }
        Severity: Minor
        Found in pkg/tun/tun_darwin.go - About 1 hr to fix

          Method Route.GenerateServers has 58 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (r *Route) GenerateServers() ([]Server, error) {
              chain, err := r.parseChain()
              if err != nil && !errors.Is(err, ErrorInvalidNode) {
                  log.Errorf("Failed to parse chain: %v", err)
                  return nil, err
          Severity: Minor
          Found in pkg/core/route.go - About 1 hr to fix

            Function createContainer has 57 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func createContainer(ctx context.Context, dockerCli command.Cli, runConfig *RunConfig) (string, error) {
                config := runConfig.config
                hostConfig := runConfig.hostConfig
                networkingConfig := runConfig.networkingConfig
                var (
            Severity: Minor
            Found in pkg/dev/docker_utils.go - About 1 hr to fix

              Method server.ServeDNS has 57 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (s *server) ServeDNS(w miekgdns.ResponseWriter, m *miekgdns.Msg) {
                  defer w.Close()
                  if len(m.Question) == 0 {
                      m.Response = true
                      _ = w.WriteMsg(m)
              Severity: Minor
              Found in pkg/dns/forwardserver.go - About 1 hr to fix

                Method Connects.Less has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
                Open

                func (s Connects) Less(i, j int) bool {
                    a := s[i]
                    b := s[j]
                
                    if a == nil {
                Severity: Minor
                Found in pkg/handler/sort.go - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method ConnectOptions.DoConnect has 13 return statements (exceeds 4 allowed).
                Open

                func (c *ConnectOptions) DoConnect(ctx context.Context, isLite bool) (err error) {
                    c.ctx, c.cancel = context.WithCancel(ctx)
                
                    log.Info("Starting connect")
                    m := dhcp.NewDHCPManager(c.clientset.CoreV1().ConfigMaps(c.Namespace), c.Namespace)
                Severity: Major
                Found in pkg/handler/connect.go - About 1 hr to fix

                  Method ConnectOptions.upgradeDeploy has 13 return statements (exceeds 4 allowed).
                  Open

                  func (c *ConnectOptions) upgradeDeploy(ctx context.Context) error {
                      deploy, err := c.clientset.AppsV1().Deployments(c.Namespace).Get(ctx, config.ConfigMapPodTrafficManager, metav1.GetOptions{})
                      if err != nil {
                          return err
                      }
                  Severity: Major
                  Found in pkg/handler/connect.go - About 1 hr to fix

                    Function downloadAndInstall has 13 return statements (exceeds 4 allowed).
                    Open

                    func downloadAndInstall(client *http.Client, url string) error {
                        temp, err := os.CreateTemp("", "*.zip")
                        if err != nil {
                            return err
                        }
                    Severity: Major
                    Found in pkg/upgrade/upgrade.go - About 1 hr to fix

                      Function CmdProxy has 13 return statements (exceeds 4 allowed).
                      Open

                      func CmdProxy(f cmdutil.Factory) *cobra.Command {
                          var connect = handler.ConnectOptions{}
                          var extraRoute = &handler.ExtraRouteInfo{}
                          var sshConf = &pkgssh.SshConfig{}
                          var transferImage, foreground bool
                      Severity: Major
                      Found in cmd/kubevpn/cmds/proxy.go - About 1 hr to fix

                        Method Server.redirectConnectForkToSudoDaemon has 13 return statements (exceeds 4 allowed).
                        Open

                        func (svr *Server) redirectConnectForkToSudoDaemon(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectServer) (err error) {
                            cli := svr.GetClient(true)
                            if cli == nil {
                                return fmt.Errorf("sudo daemon not start")
                            }
                        Severity: Major
                        Found in pkg/daemon/action/connect-fork.go - About 1 hr to fix

                          Method Server.redirectToSudoDaemon has 13 return statements (exceeds 4 allowed).
                          Open

                          func (svr *Server) redirectToSudoDaemon(req *rpc.ConnectRequest, resp rpc.Daemon_ConnectServer) (e error) {
                              cli := svr.GetClient(true)
                              if cli == nil {
                                  return fmt.Errorf("sudo daemon not start")
                              }
                          Severity: Major
                          Found in pkg/daemon/action/connect.go - About 1 hr to fix

                            Method Server.Proxy has 13 return statements (exceeds 4 allowed).
                            Open

                            func (svr *Server) Proxy(req *rpc.ConnectRequest, resp rpc.Daemon_ProxyServer) (e error) {
                                defer func() {
                                    util.InitLoggerForServer(true)
                                    log.SetOutput(svr.LogFile)
                                    config.Debug = false
                            Severity: Major
                            Found in pkg/daemon/action/proxy.go - About 1 hr to fix

                              Function handle has 13 return statements (exceeds 4 allowed).
                              Open

                              func handle(ctx context.Context, tcpConn net.Conn, udpConn *net.UDPConn) {
                                  defer udpConn.Close()
                                  log.Debugf("[TUN-UDP] %s <-> %s", tcpConn.RemoteAddr(), udpConn.LocalAddr())
                                  errChan := make(chan error, 2)
                                  go func() {
                              Severity: Major
                              Found in pkg/core/gvisorudphandler.go - About 1 hr to fix

                                Function networkCancel has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
                                Open

                                func networkCancel() {
                                    b, err := exec.Command("networksetup", "-listallnetworkservices").CombinedOutput()
                                    if err != nil {
                                        return
                                    }
                                Severity: Minor
                                Found in pkg/dns/dns_unix.go - About 1 hr to fix

                                Cognitive Complexity

                                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                A method's cognitive complexity is based on a few simple rules:

                                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                • Code is considered more complex for each "break in the linear flow of the code"
                                • Code is considered more complex when "flow breaking structures are nested"

                                Further reading

                                Function downloadAndInstall has 56 lines of code (exceeds 50 allowed). Consider refactoring.
                                Open

                                func downloadAndInstall(client *http.Client, url string) error {
                                    temp, err := os.CreateTemp("", "*.zip")
                                    if err != nil {
                                        return err
                                    }
                                Severity: Minor
                                Found in pkg/upgrade/upgrade.go - About 1 hr to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language