File connect.go
has 996 lines of code (exceeds 500 allowed). Consider refactoring. Open
package handler
import (
"context"
"encoding/json"
Method ConnectOptions.addExtraRoute
has a Cognitive Complexity of 65 (exceeds 20 allowed). Consider refactoring. Open
func (c *ConnectOptions) addExtraRoute(ctx context.Context, nameserver string) error {
if len(c.ExtraRouteInfo.ExtraDomain) == 0 {
return nil
}
- Read upRead up
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 ConnectOptions.addRouteDynamic
has a Cognitive Complexity of 52 (exceeds 20 allowed). Consider refactoring. Open
func (c *ConnectOptions) addRouteDynamic(ctx context.Context) error {
tunName, e := c.GetTunDeviceName()
if e != nil {
return e
}
- Read upRead up
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 ConnectOptions.addExtraRoute
has 120 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *ConnectOptions) addExtraRoute(ctx context.Context, nameserver string) error {
if len(c.ExtraRouteInfo.ExtraDomain) == 0 {
return nil
}
Method ConnectOptions.getCIDR
has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring. Open
func (c *ConnectOptions) getCIDR(ctx context.Context, m *dhcp.Manager) (err error) {
defer func() {
if err == nil {
u, err2 := url.Parse(c.config.Host)
if err2 != nil {
- Read upRead up
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 ConnectOptions.PreCheckResource
has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring. Open
func (c *ConnectOptions) PreCheckResource() error {
if len(c.Workloads) == 0 {
return nil
}
- Read upRead up
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
ConnectOptions
has 26 methods (exceeds 20 allowed). Consider refactoring. Open
type ConnectOptions struct {
Namespace string
Headers map[string]string
PortMap []string
Workloads []string
Method ConnectOptions.portForward
has a Cognitive Complexity of 36 (exceeds 20 allowed). Consider refactoring. Open
func (c *ConnectOptions) portForward(ctx context.Context, portPair []string) error {
firstCtx, firstCancelFunc := context.WithCancel(ctx)
defer firstCancelFunc()
var errChan = make(chan error, 1)
go func() {
- Read upRead up
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 ConnectOptions.addRouteDynamic
has 78 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *ConnectOptions) addRouteDynamic(ctx context.Context) error {
tunName, e := c.GetTunDeviceName()
if e != nil {
return e
}
Method ConnectOptions.portForward
has 77 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *ConnectOptions) portForward(ctx context.Context, portPair []string) error {
firstCtx, firstCancelFunc := context.WithCancel(ctx)
defer firstCancelFunc()
var errChan = make(chan error, 1)
go func() {
Method ConnectOptions.startLocalTunServe
has 73 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *ConnectOptions) startLocalTunServe(ctx context.Context, forwardAddress string, lite bool) (err error) {
log.Debugf("IPv4: %s, IPv6: %s", c.localTunIPv4.IP.String(), c.localTunIPv6.IP.String())
var cidrList []*net.IPNet
if !lite {
Method ConnectOptions.DoConnect
has 66 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *ConnectOptions) DoConnect(ctx context.Context, isLite bool) (err error) {
c.ctx, c.cancel = context.WithCancel(ctx)
log.Info("Starting connect")
m := dhcp.NewDHCPManager(c.clientset.CoreV1().ConfigMaps(c.Namespace), c.Namespace)
Method ConnectOptions.setupDNS
has 66 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *ConnectOptions) setupDNS(ctx context.Context) error {
const port = 53
const portTCP = 10800
pod, err := c.GetRunningPodList(ctx)
if err != nil {
Method ConnectOptions.upgradeDeploy
has 64 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *ConnectOptions) upgradeDeploy(ctx context.Context) error {
deploy, err := c.clientset.AppsV1().Deployments(c.Namespace).Get(ctx, config.ConfigMapPodTrafficManager, metav1.GetOptions{})
if err != nil {
return err
}
Method ConnectOptions.getCIDR
has 59 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *ConnectOptions) getCIDR(ctx context.Context, m *dhcp.Manager) (err error) {
defer func() {
if err == nil {
u, err2 := url.Parse(c.config.Host)
if err2 != nil {
Method ConnectOptions.DoConnect
has 13 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) DoConnect(ctx context.Context, isLite bool) (err error) {
c.ctx, c.cancel = context.WithCancel(ctx)
log.Info("Starting connect")
m := dhcp.NewDHCPManager(c.clientset.CoreV1().ConfigMaps(c.Namespace), c.Namespace)
Method ConnectOptions.upgradeDeploy
has 13 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) upgradeDeploy(ctx context.Context) error {
deploy, err := c.clientset.AppsV1().Deployments(c.Namespace).Get(ctx, config.ConfigMapPodTrafficManager, metav1.GetOptions{})
if err != nil {
return err
}
Method ConnectOptions.addExtraRoute
has 12 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) addExtraRoute(ctx context.Context, nameserver string) error {
if len(c.ExtraRouteInfo.ExtraDomain) == 0 {
return nil
}
Method ConnectOptions.PreCheckResource
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (c *ConnectOptions) PreCheckResource() error {
if len(c.Workloads) == 0 {
return nil
}
Method ConnectOptions.addRouteDynamic
has 10 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) addRouteDynamic(ctx context.Context) error {
tunName, e := c.GetTunDeviceName()
if e != nil {
return e
}
Function newer
has 8 return statements (exceeds 4 allowed). Open
func newer(clientImgStr, serverImgStr string) (bool, error) {
clientImg, err := reference.ParseNormalizedNamed(clientImgStr)
if err != nil {
return false, err
}
Method ConnectOptions.setupDNS
has 7 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) setupDNS(ctx context.Context) error {
const port = 53
const portTCP = 10800
pod, err := c.GetRunningPodList(ctx)
if err != nil {
Method ConnectOptions.portForward
has 6 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) portForward(ctx context.Context, portPair []string) error {
firstCtx, firstCancelFunc := context.WithCancel(ctx)
defer firstCancelFunc()
var errChan = make(chan error, 1)
go func() {
Method ConnectOptions.GetIPFromContext
has 6 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) GetIPFromContext(ctx context.Context) error {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return fmt.Errorf("can not get IOP from context")
}
Method ConnectOptions.startLocalTunServe
has 6 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) startLocalTunServe(ctx context.Context, forwardAddress string, lite bool) (err error) {
log.Debugf("IPv4: %s, IPv6: %s", c.localTunIPv4.IP.String(), c.localTunIPv6.IP.String())
var cidrList []*net.IPNet
if !lite {
Method ConnectOptions.InitClient
has 5 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) InitClient(f cmdutil.Factory) (err error) {
c.factory = f
if c.config, err = c.factory.ToRESTConfig(); err != nil {
return
}
Method ConnectOptions.PreCheckResource
has 5 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) PreCheckResource() error {
if len(c.Workloads) == 0 {
return nil
}
Method ConnectOptions.getCIDR
has 5 return statements (exceeds 4 allowed). Open
func (c *ConnectOptions) getCIDR(ctx context.Context, m *dhcp.Manager) (err error) {
defer func() {
if err == nil {
u, err2 := url.Parse(c.config.Host)
if err2 != nil {
Similar blocks of code found in 2 locations. Consider refactoring. Open
go func() {
var listDone bool
for ctx.Err() == nil {
err := func() error {
if !listDone {
- Read upRead up
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 231.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
go func() {
var listDone bool
for ctx.Err() == nil {
err := func() error {
if !listDone {
- Read upRead up
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 231.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
case *miekgdns.A:
if ip := net.ParseIP(a.A.String()); ip != nil && !ip.IsLoopback() {
addRouteFunc(domain, a.A.String())
c.extraHost = append(c.extraHost, dns.Entry{IP: a.A.String(), Domain: domain})
success = true
- Read upRead up
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 124.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
case *miekgdns.AAAA:
if ip := net.ParseIP(a.AAAA.String()); ip != nil && !ip.IsLoopback() {
addRouteFunc(domain, a.AAAA.String())
c.extraHost = append(c.extraHost, dns.Entry{IP: a.AAAA.String(), Domain: domain})
success = true
- Read upRead up
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 124.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76