alibaba/kt-connect

View on GitHub

Showing 109 of 109 total issues

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

func NewRecoverCommand() *cobra.Command {
    cmd := &cobra.Command{
        Use:  "recover",
        Short: "Restore traffic of specified kubernetes service changed by exchange or mesh",
        PreRunE: func(cmd *cobra.Command, args []string) error {
Severity: Major
Found in pkg/kt/command/recover.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 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 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

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

              for _, name := range r.DeploymentsToDelete {
                  err := cluster.Ins().RemoveDeployment(name, opt.Get().Global.Namespace)
                  if err != nil {
                      log.Warn().Err(err).Msgf("Failed to delete deployment %s", name)
                  } else {
          Severity: Major
          Found in pkg/kt/command/clean/common.go and 3 other locations - About 35 mins to fix
          pkg/kt/command/clean/common.go on lines 65..72
          pkg/kt/command/clean/common.go on lines 74..81
          pkg/kt/command/clean/common.go on lines 101..108

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

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

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

                          for _, name := range r.PodsToDelete {
                              err := cluster.Ins().RemovePod(name, opt.Get().Global.Namespace)
                              if err != nil {
                                  log.Warn().Err(err).Msgf("Failed to delete pods %s", name)
                              } else {
                      Severity: Major
                      Found in pkg/kt/command/clean/common.go and 3 other locations - About 35 mins to fix
                      pkg/kt/command/clean/common.go on lines 74..81
                      pkg/kt/command/clean/common.go on lines 83..90
                      pkg/kt/command/clean/common.go on lines 101..108

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

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

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

                                    for _, name := range r.ServicesToDelete {
                                        err := cluster.Ins().RemoveService(name, opt.Get().Global.Namespace)
                                        if err != nil {
                                            log.Warn().Err(err).Msgf("Failed to delete service %s", name)
                                        } else {
                                Severity: Major
                                Found in pkg/kt/command/clean/common.go and 3 other locations - About 35 mins to fix
                                pkg/kt/command/clean/common.go on lines 65..72
                                pkg/kt/command/clean/common.go on lines 74..81
                                pkg/kt/command/clean/common.go on lines 83..90

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

                                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 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
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language