alibaba/kt-connect

View on GitHub

Showing 79 of 109 total issues

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 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 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 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 Kubernetes.createAndGetPod has 5 return statements (exceeds 4 allowed).
          Open

          func (k *Kubernetes) createAndGetPod(metaAndSpec *PodMetaAndSpec, sshcm string) (*coreV1.Pod, error) {
              if opt.Get().Global.UseShadowDeployment {
                  if err := k.createShadowDeployment(metaAndSpec, sshcm); err != nil {
                      return nil, err
                  }
          Severity: Major
          Found in pkg/kt/service/cluster/shadow_pod.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

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

                  func NewConnectCommand() *cobra.Command {
                      cmd := &cobra.Command{
                          Use:  "connect",
                          Short: "Create a network tunnel to kubernetes cluster",
                          PreRunE: func(cmd *cobra.Command, args []string) error {
                  Severity: Major
                  Found in pkg/kt/command/connect.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 Forward has 5 return statements (exceeds 4 allowed).
                      Open

                      func Forward(args []string) error {
                          ch, err := general.SetupProcess(util.ComponentForward)
                          if err != nil {
                              return err
                          }
                      Severity: Major
                      Found in pkg/kt/command/forward.go - About 35 mins to fix

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

                        func (k *Kubernetes) GetKtResources(namespace string) ([]coreV1.Pod, []coreV1.ConfigMap, []appV1.Deployment, []coreV1.Service, error) {
                            pods, err := Ins().GetPodsByLabel(map[string]string{util.ControlBy: util.KubernetesToolkit}, namespace)
                            if err != nil {
                                return nil, nil, nil, nil, err
                            }
                        Severity: Major
                        Found in pkg/kt/service/cluster/global.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 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 NewMeshCommand has 5 return statements (exceeds 4 allowed).
                            Open

                            func NewMeshCommand() *cobra.Command {
                                cmd := &cobra.Command{
                                    Use:  "mesh",
                                    Short: "Redirect marked requests of specified kubernetes service to local",
                                    PreRunE: func(cmd *cobra.Command, args []string) error {
                            Severity: Major
                            Found in pkg/kt/command/mesh.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

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