Showing 79 of 109 total issues
Function cleanShadowPodAndConfigMap
has a Cognitive Complexity of 38 (exceeds 20 allowed). Consider refactoring. Open
func cleanShadowPodAndConfigMap() {
var err error
if opt.Store.Shadow != "" {
shouldDelWithShared := false
if opt.Get().Connect.ShareShadow {
- 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 GlobalFlags
has 100 lines of code (exceeds 50 allowed). Consider refactoring. Open
func GlobalFlags() []OptionConfig {
flags := []OptionConfig{
{
Target: "Namespace",
Alias: "n",
Function ConnectFlags
has 86 lines of code (exceeds 50 allowed). Consider refactoring. Open
func ConnectFlags() []OptionConfig {
flags := []OptionConfig{
{
Target: "Mode",
DefaultValue: util.ConnectModeTun2Socks,
Method Kubernetes.ClusterCidr
has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring. Open
func (k *Kubernetes) ClusterCidr(namespace string) ([]string, []string) {
ips := getServiceIps(k.Clientset, namespace)
log.Debug().Msgf("Found %d IPs", len(ips))
svcCidr := calculateMinimalIpRange(ips)
log.Debug().Msgf("Service ips are: %v", ips)
- 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 getServiceHosts
has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring. Open
func getServiceHosts(namespace string, shortDomainOnly bool) (map[string]string, []string) {
hosts := make(map[string]string)
podNames := make([]string, 0)
services, err := cluster.Ins().GetAllServiceInNamespace(namespace)
if err == 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
Function UpdateServiceSelector
has a Cognitive Complexity of 30 (exceeds 20 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
}
- 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 mergeOptions
has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring. Open
func mergeOptions(opt *DaemonOptions, data []byte) {
config := make(map[string]map[string]string)
err := yaml.Unmarshal(data, &config)
if err != nil {
log.Warn().Msgf("Invalid config content, skipping ...")
- 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 calculateMinimalIpRange
has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring. Open
func calculateMinimalIpRange(ips []string) []string {
if opt.Store.Ipv6Cluster == true {
return calculateMinimalIpv6Range(ips)
}
- 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 HandleMeshedByAutoService
has a Cognitive Complexity of 29 (exceeds 20 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 {
- 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 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
Function TidyClusterResources
has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring. Open
func TidyClusterResources(r *ResourceToClean) {
log.Info().Msgf("Deleting %d unavailing kt pods", len(r.PodsToDelete))
for _, name := range r.PodsToDelete {
err := cluster.Ins().RemovePod(name, opt.Get().Global.Namespace)
if err != 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
Function SetOptions
has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring. Open
func SetOptions(cmd *cobra.Command, flags *flag.FlagSet, optionStore any, config []OptionConfig) {
cmd.Long = cmd.Short
cmd.Flags().SortFlags = false
cmd.InheritedFlags().SortFlags = false
flags.SortFlags = false
- 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 a Cognitive Complexity of 28 (exceeds 20 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)
- 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.ClusterCidr
has 63 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (k *Kubernetes) ClusterCidr(namespace string) ([]string, []string) {
ips := getServiceIps(k.Clientset, namespace)
log.Debug().Msgf("Found %d IPs", len(ips))
svcCidr := calculateMinimalIpRange(ips)
log.Debug().Msgf("Service ips are: %v", ips)
Function TidyClusterResources
has 63 lines of code (exceeds 50 allowed). Consider refactoring. Open
func TidyClusterResources(r *ResourceToClean) {
log.Info().Msgf("Deleting %d unavailing kt pods", len(r.PodsToDelete))
for _, name := range r.PodsToDelete {
err := cluster.Ins().RemovePod(name, opt.Get().Global.Namespace)
if err != nil {
Method Cli.SetRoute
has 62 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (s *Cli) SetRoute(ipRange []string, excludeIpRange []string) error {
var lastErr error
anyRouteOk := false
// add by lichp, set ipv6 address
Function combineKubeOpts
has 62 lines of code (exceeds 50 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)
Function getPodNameAndPort
has a Cognitive Complexity of 27 (exceeds 20 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)
- 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 getDnsAddresses
has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring. Open
func getDnsAddresses(dnsOrder []string, upstreamDns string, clusterDnsPort int) []string {
upstreamPattern := fmt.Sprintf("^([cdptu]{3}:)?%s(:[0-9]+)?$", util.DnsOrderUpstream)
var dnsAddresses []string
for _, dnsAddr := range dnsOrder {
if dnsAddr == util.DnsOrderCluster {
- 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 57 lines of code (exceeds 50 allowed). Consider refactoring. 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)
}