Showing 79 of 109 total issues
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)
- 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 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)
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
}
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)
- 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 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)
}
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
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
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
}
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])
}
Function execute
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
func execute(method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool) error {
Avoid deeply nested control flow statements. Open
} else if !strings.HasSuffix(l, midDomain) && !strings.HasSuffix(l, fullDomain) {
recordsToKeep = append(recordsToKeep, l)
}