Showing 109 of 109 total issues
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)
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 {
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",
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)
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
Similar blocks of code found in 3 locations. Consider refactoring. Open
func (k *Kubernetes) GetDeploymentsByLabel(labels map[string]string, namespace string) (pods *appV1.DeploymentList, err error) {
return k.Clientset.AppsV1().Deployments(namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labelApi.SelectorFromSet(labels).String(),
TimeoutSeconds: &apiTimeout,
})
- 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 127.
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 3 locations. Consider refactoring. Open
func (k *Kubernetes) GetConfigMapsByLabel(labels map[string]string, namespace string) (pods *coreV1.ConfigMapList, err error) {
return k.Clientset.CoreV1().ConfigMaps(namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labelApi.SelectorFromSet(labels).String(),
TimeoutSeconds: &apiTimeout,
})
- 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 127.
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 3 locations. Consider refactoring. Open
func (k *Kubernetes) GetServicesByLabel(labels map[string]string, namespace string) (svcs *coreV1.ServiceList, err error) {
return k.Clientset.CoreV1().Services(namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labelApi.SelectorFromSet(labels).String(),
TimeoutSeconds: &apiTimeout,
})
- 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 127.
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
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 {
- 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
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
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)
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) {
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
func analysisExpiredServices(svc coreV1.Service, cleanThresholdInMinus int64, resourceToClean *ResourceToClean) {
lastHeartBeat := util.ParseTimestamp(svc.Annotations[util.KtLastHeartBeat])
if lastHeartBeat < 0 {
log.Debug().Msgf("Service %s does no have heart beat annotation", svc.Name)
} else if isExpired(lastHeartBeat, cleanThresholdInMinus) {
- 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 123.
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
func analysisExpiredConfigmaps(cf coreV1.ConfigMap, cleanThresholdInMinus int64, resourceToClean *ResourceToClean) {
lastHeartBeat := util.ParseTimestamp(cf.Annotations[util.KtLastHeartBeat])
if lastHeartBeat < 0 {
log.Debug().Msgf("Configmap %s does no have heart beat annotation", cf.Name)
} else if isExpired(lastHeartBeat, cleanThresholdInMinus) {
- 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 123.
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
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)
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
}
Function ByTun2Socks
has 8 return statements (exceeds 4 allowed). Open
func ByTun2Socks() error {
podIP, podName, privateKeyPath, err := getOrCreateShadow()
if err != nil {
return err
}
Similar blocks of code found in 2 locations. Consider refactoring. Open
func handleServiceEvent(obj any, status string, f func(*coreV1.Service)) {
switch obj.(type) {
case *coreV1.Service:
if f != nil {
log.Debug().Msgf("Service %s %s", obj.(*coreV1.Service).Name, status)
- 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 119.
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
func handlePodEvent(obj any, status string, f func(*coreV1.Pod)) {
switch obj.(type) {
case *coreV1.Pod:
if f != nil {
log.Debug().Msgf("Pod %s %s", obj.(*coreV1.Pod).Name, status)
- 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 119.
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
Avoid deeply nested control flow statements. Open
} else if index == 5 {
iface = parts[i]
} else if index > 5 {
iface = fmt.Sprintf("%s %s", iface, parts[i])
}