kubenetworks/kubevpn

View on GitHub
pkg/handler/clone.go

Summary

Maintainability
F
1 wk
Test Coverage

Method CloneOptions.setEnv has a Cognitive Complexity of 92 (exceeds 20 allowed). Consider refactoring.
Open

func (d *CloneOptions) setEnv(u *unstructured.Unstructured) error {
    temp, path, err := util.GetPodTemplateSpecPath(u)
    if err != nil {
        return err
    }
Severity: Minor
Found in pkg/handler/clone.go - About 1 day 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 CloneOptions.DoClone has 238 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (d *CloneOptions) DoClone(ctx context.Context, kubeconfigJsonBytes []byte) error {
    var args []string
    if len(d.Headers) != 0 {
        args = append(args, "--headers", labels.Set(d.Headers).String())
    }
Severity: Major
Found in pkg/handler/clone.go - About 1 day to fix

    File clone.go has 768 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    package handler
    
    import (
        "context"
        "encoding/json"
    Severity: Major
    Found in pkg/handler/clone.go - About 1 day to fix

      Method CloneOptions.DoClone has a Cognitive Complexity of 67 (exceeds 20 allowed). Consider refactoring.
      Open

      func (d *CloneOptions) DoClone(ctx context.Context, kubeconfigJsonBytes []byte) error {
          var args []string
          if len(d.Headers) != 0 {
              args = append(args, "--headers", labels.Set(d.Headers).String())
          }
      Severity: Minor
      Found in pkg/handler/clone.go - About 1 day 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 CloneOptions.setVolume has a Cognitive Complexity of 51 (exceeds 20 allowed). Consider refactoring.
      Open

      func (d *CloneOptions) setVolume(u *unstructured.Unstructured) error {
      
          const TokenVolumeMountPath = "/var/run/secrets/kubernetes.io/serviceaccount"
      
          type VolumeMountContainerPair struct {
      Severity: Minor
      Found in pkg/handler/clone.go - About 5 hrs 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 CloneOptions.setVolume has 136 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (d *CloneOptions) setVolume(u *unstructured.Unstructured) error {
      
          const TokenVolumeMountPath = "/var/run/secrets/kubernetes.io/serviceaccount"
      
          type VolumeMountContainerPair struct {
      Severity: Major
      Found in pkg/handler/clone.go - About 4 hrs to fix

        Method CloneOptions.setEnv has 102 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (d *CloneOptions) setEnv(u *unstructured.Unstructured) error {
            temp, path, err := util.GetPodTemplateSpecPath(u)
            if err != nil {
                return err
            }
        Severity: Major
        Found in pkg/handler/clone.go - About 3 hrs to fix

          Method CloneOptions.SyncDir has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
          Open

          func (d *CloneOptions) SyncDir(ctx context.Context, labels string) error {
              list, err := util.GetRunningPodList(ctx, d.targetClientset, d.TargetNamespace, labels)
              if err != nil {
                  return err
              }
          Severity: Minor
          Found in pkg/handler/clone.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 CloneOptions.DoClone has 17 return statements (exceeds 4 allowed).
          Open

          func (d *CloneOptions) DoClone(ctx context.Context, kubeconfigJsonBytes []byte) error {
              var args []string
              if len(d.Headers) != 0 {
                  args = append(args, "--headers", labels.Set(d.Headers).String())
              }
          Severity: Major
          Found in pkg/handler/clone.go - About 1 hr to fix

            Method CloneOptions.SyncDir has 52 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (d *CloneOptions) SyncDir(ctx context.Context, labels string) error {
                list, err := util.GetRunningPodList(ctx, d.targetClientset, d.TargetNamespace, labels)
                if err != nil {
                    return err
                }
            Severity: Minor
            Found in pkg/handler/clone.go - About 1 hr to fix

              Method CloneOptions.replaceRegistry has 8 return statements (exceeds 4 allowed).
              Open

              func (d *CloneOptions) replaceRegistry(u *unstructured.Unstructured) error {
                  // not pass this options, do nothing
                  if !d.IsChangeTargetRegistry {
                      return nil
                  }
              Severity: Major
              Found in pkg/handler/clone.go - About 50 mins to fix

                Method CloneOptions.Cleanup has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                Open

                func (d *CloneOptions) Cleanup(workloads ...string) error {
                    if len(workloads) == 0 {
                        workloads = d.Workloads
                    }
                    for _, workload := range workloads {
                Severity: Minor
                Found in pkg/handler/clone.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

                Method CloneOptions.SyncDir has 7 return statements (exceeds 4 allowed).
                Open

                func (d *CloneOptions) SyncDir(ctx context.Context, labels string) error {
                    list, err := util.GetRunningPodList(ctx, d.targetClientset, d.TargetNamespace, labels)
                    if err != nil {
                        return err
                    }
                Severity: Major
                Found in pkg/handler/clone.go - About 45 mins to fix

                  Method CloneOptions.InitClient has 6 return statements (exceeds 4 allowed).
                  Open

                  func (d *CloneOptions) InitClient(f cmdutil.Factory) (err error) {
                      d.factory = f
                      if d.config, err = d.factory.ToRESTConfig(); err != nil {
                          return
                      }
                  Severity: Major
                  Found in pkg/handler/clone.go - About 40 mins to fix

                    Method CloneOptions.setVolume has 6 return statements (exceeds 4 allowed).
                    Open

                    func (d *CloneOptions) setVolume(u *unstructured.Unstructured) error {
                    
                        const TokenVolumeMountPath = "/var/run/secrets/kubernetes.io/serviceaccount"
                    
                        type VolumeMountContainerPair struct {
                    Severity: Major
                    Found in pkg/handler/clone.go - About 40 mins to fix

                      Method CloneOptions.setEnv has 5 return statements (exceeds 4 allowed).
                      Open

                      func (d *CloneOptions) setEnv(u *unstructured.Unstructured) error {
                          temp, path, err := util.GetPodTemplateSpecPath(u)
                          if err != nil {
                              return err
                          }
                      Severity: Major
                      Found in pkg/handler/clone.go - About 35 mins to fix

                        Method CloneOptions.Cleanup has 5 return statements (exceeds 4 allowed).
                        Open

                        func (d *CloneOptions) Cleanup(workloads ...string) error {
                            if len(workloads) == 0 {
                                workloads = d.Workloads
                            }
                            for _, workload := range workloads {
                        Severity: Major
                        Found in pkg/handler/clone.go - About 35 mins to fix

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

                              for i, container := range temp.Spec.Containers {
                                  oldImage := container.Image
                                  named, err := reference.ParseNormalizedNamed(oldImage)
                                  if err != nil {
                                      return err
                          Severity: Major
                          Found in pkg/handler/clone.go and 1 other location - About 1 hr to fix
                          pkg/handler/clone.go on lines 811..821

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

                          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

                              for i, container := range temp.Spec.InitContainers {
                                  oldImage := container.Image
                                  named, err := reference.ParseNormalizedNamed(oldImage)
                                  if err != nil {
                                      return err
                          Severity: Major
                          Found in pkg/handler/clone.go and 1 other location - About 1 hr to fix
                          pkg/handler/clone.go on lines 823..833

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

                          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 5 locations. Consider refactoring.
                          Open

                                          Resources: v1.ResourceRequirements{
                                              Requests: map[v1.ResourceName]resource.Quantity{
                                                  v1.ResourceCPU:    resource.MustParse("500m"),
                                                  v1.ResourceMemory: resource.MustParse("512Mi"),
                                              },
                          Severity: Major
                          Found in pkg/handler/clone.go and 4 other locations - About 50 mins to fix
                          pkg/inject/controller.go on lines 104..113
                          pkg/inject/controller.go on lines 145..154
                          pkg/inject/exchange.go on lines 115..124
                          pkg/handler/clone.go on lines 300..309

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

                          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 5 locations. Consider refactoring.
                          Open

                                          Resources: v1.ResourceRequirements{
                                              Requests: map[v1.ResourceName]resource.Quantity{
                                                  v1.ResourceCPU:    resource.MustParse("1000m"),
                                                  v1.ResourceMemory: resource.MustParse("1024Mi"),
                                              },
                          Severity: Major
                          Found in pkg/handler/clone.go and 4 other locations - About 50 mins to fix
                          pkg/inject/controller.go on lines 104..113
                          pkg/inject/controller.go on lines 145..154
                          pkg/inject/exchange.go on lines 115..124
                          pkg/handler/clone.go on lines 350..359

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

                          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

                              var howToGetSecret = func(name string) {
                                  if configmapMap[name] == nil {
                                      secret, err := d.clientset.CoreV1().Secrets(d.Namespace).Get(context.Background(), name, metav1.GetOptions{})
                                      if err == nil {
                                          secretMap[name] = secret
                          Severity: Minor
                          Found in pkg/handler/clone.go and 1 other location - About 35 mins to fix
                          pkg/handler/clone.go on lines 696..703

                          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

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

                              var howToGetCm = func(name string) {
                                  if configmapMap[name] == nil {
                                      cm, err := d.clientset.CoreV1().ConfigMaps(d.Namespace).Get(context.Background(), name, metav1.GetOptions{})
                                      if err == nil {
                                          configmapMap[name] = cm
                          Severity: Minor
                          Found in pkg/handler/clone.go and 1 other location - About 35 mins to fix
                          pkg/handler/clone.go on lines 704..711

                          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

                          There are no issues that match your filters.

                          Category
                          Status