kubenetworks/kubevpn

View on GitHub

Showing 526 of 526 total issues

Function createTun has a Cognitive Complexity of 25 (exceeds 20 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_linux.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 Server.Connect has 11 return statements (exceeds 4 allowed).
Open

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

    Method admissionReviewHandler.handleCreate has 11 return statements (exceeds 4 allowed).
    Open

    func (h *admissionReviewHandler) handleCreate(ar v1.AdmissionReview) *v1.AdmissionResponse {
        raw := ar.Request.Object.Raw
        pod := corev1.Pod{}
        deserializer := codecs.UniversalDeserializer()
        if _, _, err := deserializer.Decode(raw, nil, &pod); err != nil {
    Severity: Major
    Found in pkg/webhook/pods.go - About 1 hr to fix

      Method Server.ConnectFork has 11 return statements (exceeds 4 allowed).
      Open

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

        Method wsHandler.installKubevpnOnRemote has 11 return statements (exceeds 4 allowed).
        Open

        func (w *wsHandler) installKubevpnOnRemote(ctx context.Context, sshClient *ssh.Client) (err error) {
            defer func() {
                if err == nil {
                    w.Log("Remote daemon server version: %s", startDaemonProcess(sshClient))
                }
        Severity: Major
        Found in pkg/daemon/handler/ssh.go - About 1 hr to fix

          Method Server.Status has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
          Open

          func (svr *Server) Status(ctx context.Context, req *rpc.StatusRequest) (*rpc.StatusResponse, error) {
              var list []*rpc.Status
          
              if len(req.ClusterIDs) != 0 {
                  for _, clusterID := range req.ClusterIDs {
          Severity: Minor
          Found in pkg/daemon/action/status.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

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

          func (c *gvisorFakeUDPTunnelConn) Close() error {
              if cc, ok := c.Conn.(interface{ CloseRead() error }); ok {
                  _ = cc.CloseRead()
              }
              if cc, ok := c.Conn.(interface{ CloseWrite() error }); ok {
          Severity: Major
          Found in pkg/core/gvisorudphandler.go and 1 other location - About 1 hr to fix
          pkg/core/tcphandler.go on lines 144..152

          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 135.

          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

          func (c *fakeUDPTunnelConn) Close() error {
              if cc, ok := c.Conn.(interface{ CloseRead() error }); ok {
                  _ = cc.CloseRead()
              }
              if cc, ok := c.Conn.(interface{ CloseWrite() error }); ok {
          Severity: Major
          Found in pkg/core/tcphandler.go and 1 other location - About 1 hr to fix
          pkg/core/gvisorudphandler.go on lines 108..116

          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 135.

          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 GetClusterIDByConfig has 52 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func GetClusterIDByConfig(cmd *cobra.Command, config Config) (string, error) {
              flags := flag.NewFlagSet("", flag.ContinueOnError)
              var sshConf = &pkgssh.SshConfig{}
              pkgssh.AddSshFlags(flags, sshConf)
              handler.AddExtraRoute(flags, &handler.ExtraRouteInfo{})
          Severity: Minor
          Found in cmd/kubevpn/cmds/status.go - About 1 hr to fix

            Method CloneOptions.SyncDir has 52 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (d *CloneOptions) SyncDir(ctx context.Context, labels string) error {
                list, err := util.GetRunningPodList(ctx, d.targetClientset, d.TargetNamespace, labels)
                if err != nil {
                    return err
                }
            Severity: Minor
            Found in pkg/handler/clone.go - About 1 hr to fix

              Function GetClient has 52 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func GetClient(isSudo bool) (cli rpc.DaemonClient) {
                  sockPath := config.GetSockPath(isSudo)
                  if _, err := os.Stat(sockPath); errors.Is(err, os.ErrNotExist) {
                      return nil
                  }
              Severity: Minor
              Found in pkg/daemon/client.go - About 1 hr to fix

                Method CopyOptions.untarAll has 52 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (o *CopyOptions) untarAll(prefix string, dest localPath, reader io.Reader) error {
                    // TODO: use compression here?
                    tarReader := tar.NewReader(reader)
                    var linkList []tar.Header
                    var genDstFilename = func(headerName string) localPath {
                Severity: Minor
                Found in pkg/cp/cp.go - About 1 hr to fix

                  Method Config.removeHosts has 52 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (c *Config) removeHosts(hosts []Entry) error {
                      if len(hosts) == 0 {
                          return nil
                      }
                  
                  
                  Severity: Minor
                  Found in pkg/dns/dns.go - About 1 hr to fix

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

                        for i, container := range temp.Spec.Containers {
                            oldImage := container.Image
                            named, err := reference.ParseNormalizedNamed(oldImage)
                            if err != nil {
                                return err
                    Severity: Major
                    Found in pkg/handler/clone.go and 1 other location - About 1 hr to fix
                    pkg/handler/clone.go on lines 811..821

                    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 134.

                    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

                        for i, container := range temp.Spec.InitContainers {
                            oldImage := container.Image
                            named, err := reference.ParseNormalizedNamed(oldImage)
                            if err != nil {
                                return err
                    Severity: Major
                    Found in pkg/handler/clone.go and 1 other location - About 1 hr to fix
                    pkg/handler/clone.go on lines 823..833

                    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 134.

                    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 GetVolume has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func GetVolume(ctx context.Context, f util.Factory, ns, podName string) (map[string][]mount.Mount, error) {
                        clientSet, err := f.KubernetesClientSet()
                        if err != nil {
                            return nil, err
                        }
                    Severity: Minor
                    Found in pkg/util/volume.go - About 1 hr to fix

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

                                      case <-immediate:
                                          var list *v12.ServiceList
                                          list, err = serviceInterface.List(ctx, v1.ListOptions{})
                                          if err != nil {
                                              continue
                      Severity: Major
                      Found in pkg/dns/dns.go and 1 other location - About 1 hr to fix
                      pkg/dns/dns.go on lines 124..136

                      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 132.

                      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

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

                                      case <-ticker.C:
                                          var list *v12.ServiceList
                                          list, err = serviceInterface.List(ctx, v1.ListOptions{})
                                          if err != nil {
                                              continue
                      Severity: Major
                      Found in pkg/dns/dns.go and 1 other location - About 1 hr to fix
                      pkg/dns/dns.go on lines 137..149

                      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 132.

                      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 CmdClone has 10 return statements (exceeds 4 allowed).
                      Open

                      func CmdClone(f cmdutil.Factory) *cobra.Command {
                          var options = handler.CloneOptions{}
                          var sshConf = &pkgssh.SshConfig{}
                          var extraRoute = &handler.ExtraRouteInfo{}
                          var transferImage bool
                      Severity: Major
                      Found in cmd/kubevpn/cmds/clone.go - About 1 hr to fix

                        Method ConnectOptions.addRouteDynamic has 10 return statements (exceeds 4 allowed).
                        Open

                        func (c *ConnectOptions) addRouteDynamic(ctx context.Context) error {
                            tunName, e := c.GetTunDeviceName()
                            if e != nil {
                                return e
                            }
                        Severity: Major
                        Found in pkg/handler/connect.go - About 1 hr to fix
                          Severity
                          Category
                          Status
                          Source
                          Language