alibaba/kt-connect

View on GitHub

Showing 109 of 109 total issues

Function calculateMinimalIpRange has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
Open

func calculateMinimalIpRange(ips []string) []string {
    if opt.Store.Ipv6Cluster == true {
        return calculateMinimalIpv6Range(ips)
    }

Severity: Minor
Found in pkg/kt/service/cluster/cidr.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 HandleMeshedByAutoService has a Cognitive Complexity of 29 (exceeds 20 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

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 AutoMesh has 68 lines of code (exceeds 50 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 1 hr to fix

    Function TidyClusterResources has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
    Open

    func TidyClusterResources(r *ResourceToClean) {
        log.Info().Msgf("Deleting %d unavailing kt pods", len(r.PodsToDelete))
        for _, name := range r.PodsToDelete {
            err := cluster.Ins().RemovePod(name, opt.Get().Global.Namespace)
            if err != nil {
    Severity: Minor
    Found in pkg/kt/command/clean/common.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 SetOptions has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
    Open

    func SetOptions(cmd *cobra.Command, flags *flag.FlagSet, optionStore any, config []OptionConfig) {
        cmd.Long = cmd.Short
        cmd.Flags().SortFlags = false
        cmd.InheritedFlags().SortFlags = false
        flags.SortFlags = false
    Severity: Minor
    Found in pkg/kt/command/options/option_config.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 a Cognitive Complexity of 28 (exceeds 20 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

    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.ClusterCidr has 63 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (k *Kubernetes) ClusterCidr(namespace string) ([]string, []string) {
        ips := getServiceIps(k.Clientset, namespace)
        log.Debug().Msgf("Found %d IPs", len(ips))
        svcCidr := calculateMinimalIpRange(ips)
        log.Debug().Msgf("Service ips are: %v", ips)
    Severity: Minor
    Found in pkg/kt/service/cluster/cidr.go - About 1 hr to fix

      Function TidyClusterResources has 63 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func TidyClusterResources(r *ResourceToClean) {
          log.Info().Msgf("Deleting %d unavailing kt pods", len(r.PodsToDelete))
          for _, name := range r.PodsToDelete {
              err := cluster.Ins().RemovePod(name, opt.Get().Global.Namespace)
              if err != nil {
      Severity: Minor
      Found in pkg/kt/command/clean/common.go - About 1 hr to fix

        Method Cli.SetRoute has 62 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (s *Cli) SetRoute(ipRange []string, excludeIpRange []string) error {
            var lastErr error
            anyRouteOk := false
        
            // add by lichp, set ipv6 address
        Severity: Minor
        Found in pkg/kt/service/tun/tun_windows.go - About 1 hr to fix

          Function combineKubeOpts has 62 lines of code (exceeds 50 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

            Function getPodNameAndPort has a Cognitive Complexity of 27 (exceeds 20 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

            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 getDnsAddresses has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
            Open

            func getDnsAddresses(dnsOrder []string, upstreamDns string, clusterDnsPort int) []string {
                upstreamPattern := fmt.Sprintf("^([cdptu]{3}:)?%s(:[0-9]+)?$", util.DnsOrderUpstream)
                var dnsAddresses []string
                for _, dnsAddr := range dnsOrder {
                    if dnsAddr == util.DnsOrderCluster {
            Severity: Minor
            Found in pkg/kt/service/dns/dnsserver.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

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

            func (k *Kubernetes) WatchPod(name, namespace string, fAdd, fDel, fMod func(*coreV1.Pod)) {
                k.watchResource(name, namespace, string(coreV1.ResourcePods), &coreV1.Pod{},
                    func(obj any) {
                        handlePodEvent(obj, "added", fAdd)
                    },
            Severity: Major
            Found in pkg/kt/service/cluster/pod.go and 1 other location - About 1 hr to fix
            pkg/kt/service/cluster/service.go on lines 93..105

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

            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

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

            func (k *Kubernetes) WatchService(name, namespace string, fAdd, fDel, fMod func(*coreV1.Service)) {
                k.watchResource(name, namespace, string(coreV1.ResourceServices), &coreV1.Service{},
                    func(obj any) {
                        handleServiceEvent(obj, "added", fAdd)
                    },
            Severity: Major
            Found in pkg/kt/service/cluster/service.go and 1 other location - About 1 hr to fix
            pkg/kt/service/cluster/pod.go on lines 92..104

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

            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 Recover has 57 lines of code (exceeds 50 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 1 hr to fix

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