alibaba/kt-connect

View on GitHub

Showing 79 of 109 total issues

Function NewPreviewCommand has 5 return statements (exceeds 4 allowed).
Open

func NewPreviewCommand() *cobra.Command {
    cmd := &cobra.Command{
        Use:   "preview",
        Short: "Expose a local service to kubernetes cluster",
        PreRunE: func(cmd *cobra.Command, args []string) error {
Severity: Major
Found in pkg/kt/command/preview.go - About 35 mins to fix

    Function LoadProfile has 5 return statements (exceeds 4 allowed).
    Open

    func LoadProfile(args []string) error {
        if len(args) != 1 {
            return fmt.Errorf("must specifiy a profile name")
        }
        profile := profileFile(args[0])
    Severity: Major
    Found in pkg/kt/command/config/load.go - About 35 mins to fix

      Method Cli.RunScript has 5 return statements (exceeds 4 allowed).
      Open

      func (c *Cli) RunScript(privateKey, sshAddress, script string) (result string, err error) {
          dialer, err := sshproxy.NewDialer(getSshTunnelAddress(privateKey, sshAddress))
          if err != nil {
              return "", err
          }
      Severity: Major
      Found in pkg/kt/service/sshchannel/ssh.go - About 35 mins to fix

        Function createStuntmanService has 5 return statements (exceeds 4 allowed).
        Open

        func createStuntmanService(svc *coreV1.Service, ports map[int]int) error {
            stuntmanSvcName := svc.Name + util.StuntmanServiceSuffix
            namespace := opt.Get().Global.Namespace
            if stuntmanSvc, err := cluster.Ins().GetService(stuntmanSvcName, namespace); err != nil {
                if !k8sErrors.IsNotFound(err) {
        Severity: Major
        Found in pkg/kt/command/mesh/auto.go - About 35 mins to fix

          Function exchangeWithEphemeralContainer has 5 return statements (exceeds 4 allowed).
          Open

          func exchangeWithEphemeralContainer(exposePorts string, localSSHPort int, privateKey string) error {
              // Get all listened ports on remote host
              listenedPorts, err := getListenedPorts(localSSHPort, privateKey)
              if err != nil {
                  return err
          Severity: Major
          Found in pkg/kt/command/exchange/ephemeral.go - About 35 mins to fix

            Function ExtractHostIp has 5 return statements (exceeds 4 allowed).
            Open

            func ExtractHostIp(url string) string {
                if !strings.Contains(url, ":") {
                    return ""
                }
                host := strings.Trim(strings.Split(url, ":")[1], "/")
            Severity: Major
            Found in pkg/kt/util/network.go - About 35 mins to fix

              Function updateRoute has 5 return statements (exceeds 4 allowed).
              Open

              func updateRoute(header, version, action string) error {
                  ktConf, err := router.ReadKtConf()
                  if err != nil {
                      return err
                  }
              Severity: Major
              Found in cmd/router/main.go - About 35 mins to fix

                Function NewExchangeCommand has 5 return statements (exceeds 4 allowed).
                Open

                func NewExchangeCommand() *cobra.Command {
                    cmd := &cobra.Command{
                        Use:  "exchange",
                        Short: "Redirect all requests of specified kubernetes service to local",
                        PreRunE: func(cmd *cobra.Command, args []string) error {
                Severity: Major
                Found in pkg/kt/command/exchange.go - About 35 mins to fix

                  Function isNameUsable has 5 return statements (exceeds 4 allowed).
                  Open

                  func isNameUsable(name, meshVersion string, times int) error {
                      if times > 10 {
                          return fmt.Errorf("meshing pod for service %s still terminating, please try again later", name)
                      }
                      shadowName := name + util.MeshPodInfix + meshVersion
                  Severity: Major
                  Found in pkg/kt/command/mesh/auto.go - About 35 mins to fix

                    Method Kubernetes.waitPodsReady has 5 return statements (exceeds 4 allowed).
                    Open

                    func (k *Kubernetes) waitPodsReady(labels map[string]string, namespace string, timeoutSec int, times int) ([]coreV1.Pod, error) {
                        pods, err := k.GetPodsByLabel(labels, namespace)
                        if err != nil {
                            return nil, err
                        }
                    Severity: Major
                    Found in pkg/kt/service/cluster/pod.go - About 35 mins to fix

                      Function updateHostsFile has 5 return statements (exceeds 4 allowed).
                      Open

                      func updateHostsFile(lines []string) error {
                          lock := flock.New(fmt.Sprintf("%s/hosts.lock", util.KtLockDir))
                          timeoutContext, cancel := context.WithTimeout(context.TODO(), 2 * time.Second)
                          defer cancel()
                          if ok, err := lock.TryLockContext(timeoutContext, 100 * time.Millisecond); !ok {
                      Severity: Major
                      Found in pkg/kt/service/dns/hosts.go - About 35 mins to fix

                        Function isPartOfRange has 5 return statements (exceeds 4 allowed).
                        Open

                        func isPartOfRange(ipRange string, subIpRange string) bool {
                            ipRangeBin, err := ipRangeToBin(ipRange)
                            if err != nil {
                                return false
                            }
                        Severity: Major
                        Found in pkg/kt/service/cluster/cidr.go - About 35 mins to fix

                          Function DumpHosts has 5 return statements (exceeds 4 allowed).
                          Open

                          func DumpHosts(hostsMap map[string]string, namespaceToDrop string) error {
                              if doNotDump {
                                  return nil
                              }
                              lines, err := loadHostsFile()
                          Severity: Major
                          Found in pkg/kt/service/dns/hosts.go - About 35 mins to fix

                            Function Unset has 5 return statements (exceeds 4 allowed).
                            Open

                            func Unset(args []string) error {
                                if unsetAll {
                                    return saveConfig(make(map[string]map[string]string))
                                }
                                if len(args) < 1 {
                            Severity: Major
                            Found in pkg/kt/command/config/reset.go - About 35 mins to fix

                              Function Recover has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                              Open

                              func Recover(serviceName string) error {
                                  svc, err := cluster.Ins().GetService(serviceName, opt.Get().Global.Namespace)
                                  if err != nil {
                                      log.Error().Err(err).Msgf("Failed to fetch service '%s'", serviceName)
                                  }
                              Severity: Minor
                              Found in pkg/kt/command/recover.go - About 35 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 LockService has 5 return statements (exceeds 4 allowed).
                              Open

                              func LockService(serviceName, namespace string, times int) (*coreV1.Service, error) {
                                  if times > 10 {
                                      return nil, fmt.Errorf("failed to obtain kt lock of service %s, please try again later", serviceName)
                                  }
                                  svc, err := cluster.Ins().GetService(serviceName, namespace)
                              Severity: Major
                              Found in pkg/kt/command/general/lock.go - About 35 mins to fix

                                Function exposeLocalService has 5 return statements (exceeds 4 allowed).
                                Open

                                func exposeLocalService(serviceName, shadowPodName string, labels, annotations map[string]string) error {
                                
                                    envs := make(map[string]string)
                                    _, podName, privateKeyPath, err := cluster.Ins().GetOrCreateShadow(shadowPodName, labels, annotations, envs,
                                        opt.Get().Preview.Expose, map[int]string{})
                                Severity: Major
                                Found in pkg/kt/command/preview/expose.go - About 35 mins to fix

                                  Function getKtRouteRecords has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                                  Open

                                  func getKtRouteRecords(s *Cli) ([]RouteRecord, error) {
                                      records := []RouteRecord{}
                                  
                                      // run command: netsh interface ipv4 show route store=persistent
                                      out, _, err := util.RunAndWait(exec.Command("netsh",
                                  Severity: Minor
                                  Found in pkg/kt/service/tun/tun_windows.go - About 35 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 fetchTargetRole has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                                  Open

                                  func fetchTargetRole(apps *appV1.DeploymentList, pods *coreV1.PodList) (*appV1.Deployment, *coreV1.Pod, string) {
                                      if len(apps.Items) > 0 {
                                          for _, app := range apps.Items {
                                              if app.Labels != nil {
                                                  if role, ok2 := app.Labels[util.KtRole]; ok2 {
                                  Severity: Minor
                                  Found in pkg/kt/command/recover.go - About 25 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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language