alibaba/kt-connect

View on GitHub
pkg/kt/command/mesh/auto.go

Summary

Maintainability
B
6 hrs
Test Coverage

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

      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 createRouter has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        func createRouter(routerPodName string, svcName string, ports map[int]int, labels map[string]string, versionMark string) error {
        Severity: Minor
        Found in pkg/kt/command/mesh/auto.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 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

              There are no issues that match your filters.

              Category
              Status