kubenetworks/kubevpn

View on GitHub

Showing 333 of 526 total issues

Function UDPForwarder has 62 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func UDPForwarder(s *stack.Stack) func(id stack.TransportEndpointID, pkt *stack.PacketBuffer) bool {
    GvisorUDPForwardAddr := GvisorUDPForwardAddr
    return udp.NewForwarder(s, func(request *udp.ForwarderRequest) {
        endpointID := request.ID()
        log.Debugf("[TUN-UDP] LocalPort: %d, LocalAddress: %s, RemotePort: %d, RemoteAddress %s",
Severity: Minor
Found in pkg/core/gvisorudpforwarder.go - About 1 hr to fix

    Function CmdDaemon has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
    Open

    func CmdDaemon(_ cmdutil.Factory) *cobra.Command {
        var opt = &daemon.SvrOption{}
        cmd := &cobra.Command{
            Use:   "daemon",
            Short: i18n.T("Startup kubevpn daemon server"),
    Severity: Minor
    Found in cmd/kubevpn/cmds/daemon.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 ConvertK8sApiServerToDomain has 15 return statements (exceeds 4 allowed).
    Open

    func ConvertK8sApiServerToDomain(kubeConfigPath string) (newPath string, err error) {
        var kubeConfigBytes []byte
        kubeConfigBytes, err = os.ReadFile(kubeConfigPath)
        if err != nil {
            return
    Severity: Major
    Found in pkg/util/kube.go - About 1 hr to fix

      Method Manager.updateDHCPConfigMap has 15 return statements (exceeds 4 allowed).
      Open

      func (m *Manager) updateDHCPConfigMap(ctx context.Context, f func(ipv4 *ipallocator.Range, ipv6 *ipallocator.Range) error) error {
          cm, err := m.client.Get(ctx, config.ConfigMapPodTrafficManager, metav1.GetOptions{})
          if err != nil {
              return fmt.Errorf("failed to get configmap DHCP server, err: %v", err)
          }
      Severity: Major
      Found in pkg/dhcp/dhcp.go - About 1 hr to fix

        Function createTun has 15 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_windows.go - About 1 hr to fix

          Function CmdCp has 60 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func CmdCp(f cmdutil.Factory) *cobra.Command {
              o := cp.NewCopyOptions(genericiooptions.IOStreams{
                  In:     os.Stdin,
                  Out:    os.Stdout,
                  ErrOut: os.Stderr,
          Severity: Minor
          Found in cmd/kubevpn/cmds/cp.go - About 1 hr to fix

            Function recursiveTar has 60 lines of code (exceeds 50 allowed). Consider refactoring.
            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: Minor
            Found in pkg/cp/cp.go - About 1 hr to fix

              Method ConnectOptions.getCIDR has 59 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (c *ConnectOptions) getCIDR(ctx context.Context, m *dhcp.Manager) (err error) {
                  defer func() {
                      if err == nil {
                          u, err2 := url.Parse(c.config.Host)
                          if err2 != nil {
              Severity: Minor
              Found in pkg/handler/connect.go - About 1 hr to fix

                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

                      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
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language