kubenetworks/kubevpn

View on GitHub

Showing 526 of 526 total issues

Avoid deeply nested control flow statements.
Open

                    } else if err != nil {
                        return err
                    }
Severity: Major
Found in cmd/kubevpn/cmds/proxy.go - About 45 mins to fix

    Function genOutput has 7 return statements (exceeds 4 allowed).
    Open

    func genOutput(status *rpc.StatusResponse, format string) (string, error) {
        switch format {
        case FormatJson:
            if len(status.List) == 0 {
                return "", nil
    Severity: Major
    Found in cmd/kubevpn/cmds/status.go - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          } else if err != nil {
                              return err
                          }
      Severity: Major
      Found in cmd/kubevpn/cmds/connect.go - About 45 mins to fix

        Function GetClusterIDByConfig has 7 return statements (exceeds 4 allowed).
        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: Major
        Found in cmd/kubevpn/cmds/status.go - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if len(comps) > 0 && len(toComplete) > 0 {
                                  if files, err := os.ReadDir("."); err == nil {
                                      for _, file := range files {
                                          filename := file.Name()
                                          if strings.HasPrefix(filename, toComplete) {
          Severity: Major
          Found in cmd/kubevpn/cmds/cp.go - About 45 mins to fix

            Function InjectVPNSidecar has 7 return statements (exceeds 4 allowed).
            Open

            func InjectVPNSidecar(ctx1 context.Context, factory util.Factory, namespace, workload string, c util2.PodRouteConfig) error {
                object, err := util2.GetUnstructuredObject(factory, namespace, workload)
                if err != nil {
                    return err
                }
            Severity: Major
            Found in pkg/inject/proxy.go - About 45 mins to fix

              Function ConvertToKubeConfigBytes has 7 return statements (exceeds 4 allowed).
              Open

              func ConvertToKubeConfigBytes(factory cmdutil.Factory) ([]byte, string, error) {
                  loader := factory.ToRawKubeConfigLoader()
                  namespace, _, err := loader.Namespace()
                  if err != nil {
                      return nil, "", err
              Severity: Major
              Found in pkg/util/ns.go - About 45 mins to fix

                Function run has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                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: Minor
                Found in pkg/dev/docker_utils.go - About 45 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 CmdStatus has 7 return statements (exceeds 4 allowed).
                Open

                func CmdStatus(f cmdutil.Factory) *cobra.Command {
                    var aliasName string
                    var localFile string
                    var remoteAddr string
                    var format string
                Severity: Major
                Found in cmd/kubevpn/cmds/status.go - About 45 mins to fix

                  Function CmdDisconnect has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func CmdDisconnect(f cmdutil.Factory) *cobra.Command {
                      var all = false
                      var clusterIDs []string
                      cmd := &cobra.Command{
                          Use:   "disconnect",
                  Severity: Minor
                  Found in cmd/kubevpn/cmds/disconnect.go - About 45 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 Parse has 7 return statements (exceeds 4 allowed).
                  Open

                  func Parse(flags *pflag.FlagSet, copts *ContainerOptions) (*Config, *HostConfig, error) {
                      var (
                          attachStdin  = copts.attach.Get("stdin")
                          attachStdout = copts.attach.Get("stdout")
                          attachStderr = copts.attach.Get("stderr")
                  Severity: Major
                  Found in pkg/dev/docker_opts.go - About 45 mins to fix

                    Method ConnectOptions.setupDNS has 7 return statements (exceeds 4 allowed).
                    Open

                    func (c *ConnectOptions) setupDNS(ctx context.Context) error {
                        const port = 53
                        const portTCP = 10800
                        pod, err := c.GetRunningPodList(ctx)
                        if err != nil {
                    Severity: Major
                    Found in pkg/handler/connect.go - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if absHostPart, err := filepath.Abs(hostPart); err == nil {
                                                  hostPart = absHostPart
                                              }
                      Severity: Major
                      Found in pkg/dev/docker_opts.go - About 45 mins to fix

                        Function monitorSize has 7 return statements (exceeds 4 allowed).
                        Open

                        func monitorSize(ctx context.Context, sessionID string) error {
                            conn := daemon.GetTCPClient(true)
                            if conn == nil {
                                return fmt.Errorf("conn is nil")
                            }
                        Severity: Major
                        Found in cmd/kubevpn/cmds/ssh.go - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                              } else if err != nil {
                                                  return err
                                              }
                          Severity: Major
                          Found in cmd/kubevpn/cmds/connect.go - About 45 mins to fix

                            Method CloneOptions.SyncDir has 7 return statements (exceeds 4 allowed).
                            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: Major
                            Found in pkg/handler/clone.go - About 45 mins to fix

                              Function NewOnAddresses has 6 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                              func NewOnAddresses(dialer httpstream.Dialer, addresses []string, ports []string, stopChan <-chan struct{}, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error) {
                              Severity: Minor
                              Found in pkg/util/portforward.go - About 45 mins to fix

                                Method SvrOption.Start has 7 return statements (exceeds 4 allowed).
                                Open

                                func (o *SvrOption) Start(ctx context.Context) error {
                                    l := &lumberjack.Logger{
                                        Filename:   action.GetDaemonLogPath(),
                                        MaxSize:    100,
                                        MaxAge:     3,
                                Severity: Major
                                Found in pkg/daemon/daemon.go - About 45 mins to fix

                                  Function TransferImage has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                                  Open

                                  func TransferImage(ctx context.Context, conf *SshConfig, imageSource, imageTarget string, out io.Writer) error {
                                      client, cli, err := GetClient()
                                      if err != nil {
                                          log.Errorf("Failed to get docker client: %v", err)
                                          return err
                                  Severity: Minor
                                  Found in pkg/ssh/image.go - About 45 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

                                  Avoid deeply nested control flow statements.
                                  Open

                                          if config.Keyfile == "" {
                                              config.Keyfile = filepath.Join(homedir.HomeDir(), ".ssh", "id_rsa")
                                          }
                                  Severity: Major
                                  Found in pkg/ssh/ssh.go - About 45 mins to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language