kubenetworks/kubevpn

View on GitHub

Showing 333 of 526 total issues

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

    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

              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

                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

                    Function CmdSSH has 10 return statements (exceeds 4 allowed).
                    Open

                    func CmdSSH(_ cmdutil.Factory) *cobra.Command {
                        var sshConf = &pkgssh.SshConfig{}
                        var ExtraCIDR []string
                        cmd := &cobra.Command{
                            Use:   "ssh",
                    Severity: Major
                    Found in cmd/kubevpn/cmds/ssh.go - About 1 hr to fix

                      Function CmdDev has 10 return statements (exceeds 4 allowed).
                      Open

                      func CmdDev(f cmdutil.Factory) *cobra.Command {
                          var options = &dev.Options{
                              NoProxy:        false,
                              ExtraRouteInfo: handler.ExtraRouteInfo{},
                          }
                      Severity: Major
                      Found in cmd/kubevpn/cmds/dev.go - About 1 hr to fix

                        Method Server.Clone has 10 return statements (exceeds 4 allowed).
                        Open

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

                          Function run has 10 return statements (exceeds 4 allowed).
                          Open

                          func run(ctx context.Context, cli *client.Client, dockerCli *command.DockerCli, runConfig *RunConfig) (id string, err error) {
                              rand.New(rand.NewSource(time.Now().UnixNano()))
                          
                              var config = runConfig.config
                              var hostConfig = runConfig.hostConfig
                          Severity: Major
                          Found in pkg/dev/docker_utils.go - About 1 hr to fix

                            Method CopyOptions.untarAll has 10 return statements (exceeds 4 allowed).
                            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: Major
                            Found in pkg/cp/cp.go - About 1 hr to fix

                              Function createContainer has 10 return statements (exceeds 4 allowed).
                              Open

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

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

                                  Consider simplifying this complex logical expression.
                                  Open

                                              if (ipProtocol == int(layers.IPProtocolUDP) || ipProtocol == int(layers.IPProtocolUDPLite) || ipProtocol == int(layers.IPProtocolTCP)) &&
                                                  (engine == config.EngineGvisor || (engine == config.EngineMix && (!config.CIDR.Contains(dst) && !config.CIDR6.Contains(dst)))) {
                                  Severity: Major
                                  Found in pkg/core/gvisortunendpoint.go - About 1 hr to fix

                                    Function fromPatchToProbe has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                                    Open

                                    func fromPatchToProbe(spec *v1.PodTemplateSpec, path []string, patch []P) {
                                        // 3 = readiness + liveness + startup
                                        if len(patch) != 3*len(spec.Spec.Containers) {
                                            log.Debugf("patch not match container num, not restore")
                                            return
                                    Severity: Minor
                                    Found in pkg/inject/proxy.go - About 55 mins 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 ExtractSyncthingGUIZipToDir has 9 return statements (exceeds 4 allowed).
                                    Open

                                    func ExtractSyncthingGUIZipToDir(fs embed.FS, zipPath, targetDir string) error {
                                        zipData, err := fs.Open(zipPath)
                                        if err != nil {
                                            return err
                                        }
                                    Severity: Major
                                    Found in pkg/syncthing/gui.go - About 55 mins to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language