alibaba/kt-connect

View on GitHub

Showing 79 of 109 total issues

Function dropHosts has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
Open

func dropHosts(rawLines []string, namespaceToDrop string) ([]string, []string, error) {
    escapeBegin := -1
    escapeEnd := -1
    midDomain := fmt.Sprintf(".%s", namespaceToDrop)
    fullDomain := fmt.Sprintf(".%s.svc.%s", namespaceToDrop, opt.Get().Connect.ClusterDomain)
Severity: Minor
Found in pkg/kt/service/dns/hosts.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

Method Kubernetes.tryGetExistingShadows has 54 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (k *Kubernetes) tryGetExistingShadows(resourceMeta *ResourceMeta, sshKeyMeta *SSHkeyMeta) (*coreV1.Pod, *util.SSHGenerator, error) {
    var app *appV1.Deployment
    var pod *coreV1.Pod
    if opt.Get().Global.UseShadowDeployment {
        app2, err := k.GetDeployment(resourceMeta.Name, resourceMeta.Namespace)
Severity: Minor
Found in pkg/kt/service/cluster/shadow_pod.go - About 1 hr to fix

    Function UpdateServiceSelector has 54 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func UpdateServiceSelector(svcName, namespace string, selector map[string]string) error {
        svc, err := cluster.Ins().GetService(svcName, namespace)
        if err != nil {
            return err
        }
    Severity: Minor
    Found in pkg/kt/command/general/resource.go - About 1 hr to fix

      Function Recover has 11 return statements (exceeds 4 allowed).
      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: Major
      Found in pkg/kt/command/recover.go - About 1 hr to fix

        Function combineKubeOpts has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
        Open

        func combineKubeOpts() (err error) {
            var config *clientcmdapi.Config
            if opt.Get().Global.Kubeconfig != ""{
                // if kubeconfig specified, always read from it
                _ = os.Setenv(util.EnvKubeConfig, opt.Get().Global.Kubeconfig)
        Severity: Minor
        Found in pkg/kt/command/general/setup.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 getKtRouteRecords has 51 lines of code (exceeds 50 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 1 hr to fix

          Function HandleMeshedByAutoService has 51 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func HandleMeshedByAutoService(svc *coreV1.Service, deployment *appV1.Deployment, pod *coreV1.Pod) error {
              // shadow pods, shadow deployments, shadow services
              if deployment != nil {
                  return fmt.Errorf("service '%s' is meshed but selecting more than a router pod, cannot auto recover", svc.Name)
              } else if pod == nil {
          Severity: Minor
          Found in pkg/kt/command/recover/common.go - About 1 hr to fix

            Function getPodNameAndPort has 51 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func getPodNameAndPort(serviceName string, remotePort int, namespace string) (string, int, int, error) {
                svc, err := cluster.Ins().GetService(serviceName, namespace)
                if err != nil {
                    if k8sErrors.IsNotFound(err) {
                        return "", 0, 0, fmt.Errorf("service '%s' is not found in namespace %s", serviceName, namespace)
            Severity: Minor
            Found in pkg/kt/command/forward/common.go - About 1 hr to fix

              Method Kubernetes.tryGetExistingShadows has 10 return statements (exceeds 4 allowed).
              Open

              func (k *Kubernetes) tryGetExistingShadows(resourceMeta *ResourceMeta, sshKeyMeta *SSHkeyMeta) (*coreV1.Pod, *util.SSHGenerator, error) {
                  var app *appV1.Deployment
                  var pod *coreV1.Pod
                  if opt.Get().Global.UseShadowDeployment {
                      app2, err := k.GetDeployment(resourceMeta.Name, resourceMeta.Namespace)
              Severity: Major
              Found in pkg/kt/service/cluster/shadow_pod.go - About 1 hr to fix

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

                func AutoMesh(svc *coreV1.Service) error {
                    // Lock service to avoid conflict, must be first step
                    svc, err := general.LockService(svc.Name, opt.Get().Global.Namespace, 0)
                    if err != nil {
                        return err
                Severity: Major
                Found in pkg/kt/command/mesh/auto.go - About 1 hr to fix

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

                  func GetTargetPorts(svc *coreV1.Service) map[int]string {
                      var pod *coreV1.Pod = nil
                      svcPorts := svc.Spec.Ports
                      targetPorts := map[int]string{}
                      for _, p := range svcPorts {
                  Severity: Minor
                  Found in pkg/kt/command/general/resource.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 GetServiceStatus has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func GetServiceStatus(ktSvcs []coreV1.Service, pods []coreV1.Pod, svcs []coreV1.Service) [][]string {
                      allServices := make([][]string, 0)
                      for _, svc := range ktSvcs {
                          for _, p := range pods {
                              if p.Labels[util.KtRole] == util.RolePreviewShadow && util.MapContains(svc.Spec.Selector, p.Labels) {
                  Severity: Minor
                  Found in pkg/kt/command/birdseye/common.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 BySelector has 9 return statements (exceeds 4 allowed).
                  Open

                  func BySelector(resourceName string) error {
                      // Get service to exchange
                      svc, err := general.GetServiceByResourceName(resourceName, opt.Get().Global.Namespace)
                      if err != nil {
                          return err
                  Severity: Major
                  Found in pkg/kt/command/exchange/selector.go - About 55 mins to fix

                    Function getPodNameAndPort has 9 return statements (exceeds 4 allowed).
                    Open

                    func getPodNameAndPort(serviceName string, remotePort int, namespace string) (string, int, int, error) {
                        svc, err := cluster.Ins().GetService(serviceName, namespace)
                        if err != nil {
                            if k8sErrors.IsNotFound(err) {
                                return "", 0, 0, fmt.Errorf("service '%s' is not found in namespace %s", serviceName, namespace)
                    Severity: Major
                    Found in pkg/kt/command/forward/common.go - About 55 mins to fix

                      Function setupDns has 8 return statements (exceeds 4 allowed).
                      Open

                      func setupDns(shadowPodName, shadowPodIp string) error {
                          if strings.HasPrefix(opt.Get().Connect.DnsMode, util.DnsModeHosts) {
                              log.Info().Msgf("Setting up dns in hosts mode")
                              dump2HostsNamespaces := ""
                              pos := len(util.DnsModeHosts)
                      Severity: Major
                      Found in pkg/kt/command/connect/common.go - About 50 mins to fix

                        Function ByTun2Socks has 8 return statements (exceeds 4 allowed).
                        Open

                        func ByTun2Socks() error {
                            podIP, podName, privateKeyPath, err := getOrCreateShadow()
                            if err != nil {
                                return err
                            }
                        Severity: Major
                        Found in pkg/kt/command/connect/tun2socks.go - About 50 mins to fix

                          Function UpdateServiceSelector has 8 return statements (exceeds 4 allowed).
                          Open

                          func UpdateServiceSelector(svcName, namespace string, selector map[string]string) error {
                              svc, err := cluster.Ins().GetService(svcName, namespace)
                              if err != nil {
                                  return err
                              }
                          Severity: Major
                          Found in pkg/kt/command/general/resource.go - About 50 mins to fix

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

                            func createRouter(routerPodName string, svcName string, ports map[int]int, labels map[string]string, versionMark string) error {
                                namespace := opt.Get().Global.Namespace
                                routerPod, err := cluster.Ins().GetPod(routerPodName, namespace)
                                if err == nil && routerPod.DeletionTimestamp != nil {
                                    routerPod, err = cluster.Ins().WaitPodTerminate(routerPodName, namespace)
                            Severity: Major
                            Found in pkg/kt/command/mesh/auto.go - About 45 mins to fix

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

                              func AutoMesh(svc *coreV1.Service) error {
                                  // Lock service to avoid conflict, must be first step
                                  svc, err := general.LockService(svc.Name, opt.Get().Global.Namespace, 0)
                                  if err != nil {
                                      return err
                              Severity: Minor
                              Found in pkg/kt/command/mesh/auto.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

                                      } else if util.IsMacos() {
                                          dnsPort = opt.Get().Connect.DnsPort
                                      }
                              Severity: Major
                              Found in pkg/kt/command/connect/common.go - About 45 mins to fix
                                Severity
                                Category
                                Status
                                Source
                                Language