Showing 79 of 109 total issues
Function Unset
has 5 return statements (exceeds 4 allowed). Open
func Unset(args []string) error {
if unsetAll {
return saveConfig(make(map[string]map[string]string))
}
if len(args) < 1 {
Function updateRoute
has 5 return statements (exceeds 4 allowed). Open
func updateRoute(header, version, action string) error {
ktConf, err := router.ReadKtConf()
if err != nil {
return err
}
Function createStuntmanService
has 5 return statements (exceeds 4 allowed). Open
func createStuntmanService(svc *coreV1.Service, ports map[int]int) error {
stuntmanSvcName := svc.Name + util.StuntmanServiceSuffix
namespace := opt.Get().Global.Namespace
if stuntmanSvc, err := cluster.Ins().GetService(stuntmanSvcName, namespace); err != nil {
if !k8sErrors.IsNotFound(err) {
Function LoadProfile
has 5 return statements (exceeds 4 allowed). Open
func LoadProfile(args []string) error {
if len(args) != 1 {
return fmt.Errorf("must specifiy a profile name")
}
profile := profileFile(args[0])
Method Kubernetes.createAndGetPod
has 5 return statements (exceeds 4 allowed). Open
func (k *Kubernetes) createAndGetPod(metaAndSpec *PodMetaAndSpec, sshcm string) (*coreV1.Pod, error) {
if opt.Get().Global.UseShadowDeployment {
if err := k.createShadowDeployment(metaAndSpec, sshcm); err != nil {
return nil, err
}
Function isNameUsable
has 5 return statements (exceeds 4 allowed). Open
func isNameUsable(name, meshVersion string, times int) error {
if times > 10 {
return fmt.Errorf("meshing pod for service %s still terminating, please try again later", name)
}
shadowName := name + util.MeshPodInfix + meshVersion
Function updateHostsFile
has 5 return statements (exceeds 4 allowed). Open
func updateHostsFile(lines []string) error {
lock := flock.New(fmt.Sprintf("%s/hosts.lock", util.KtLockDir))
timeoutContext, cancel := context.WithTimeout(context.TODO(), 2 * time.Second)
defer cancel()
if ok, err := lock.TryLockContext(timeoutContext, 100 * time.Millisecond); !ok {
Function NewPreviewCommand
has 5 return statements (exceeds 4 allowed). Open
func NewPreviewCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "preview",
Short: "Expose a local service to kubernetes cluster",
PreRunE: func(cmd *cobra.Command, args []string) error {
Function NewConnectCommand
has 5 return statements (exceeds 4 allowed). Open
func NewConnectCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "connect",
Short: "Create a network tunnel to kubernetes cluster",
PreRunE: func(cmd *cobra.Command, args []string) error {
Function NewExchangeCommand
has 5 return statements (exceeds 4 allowed). Open
func NewExchangeCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "exchange",
Short: "Redirect all requests of specified kubernetes service to local",
PreRunE: func(cmd *cobra.Command, args []string) error {
Function Forward
has 5 return statements (exceeds 4 allowed). Open
func Forward(args []string) error {
ch, err := general.SetupProcess(util.ComponentForward)
if err != nil {
return err
}
Method Kubernetes.GetKtResources
has 5 return statements (exceeds 4 allowed). Open
func (k *Kubernetes) GetKtResources(namespace string) ([]coreV1.Pod, []coreV1.ConfigMap, []appV1.Deployment, []coreV1.Service, error) {
pods, err := Ins().GetPodsByLabel(map[string]string{util.ControlBy: util.KubernetesToolkit}, namespace)
if err != nil {
return nil, nil, nil, nil, err
}
Function getKtRouteRecords
has a Cognitive Complexity of 22 (exceeds 20 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",
- 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 DumpHosts
has 5 return statements (exceeds 4 allowed). Open
func DumpHosts(hostsMap map[string]string, namespaceToDrop string) error {
if doNotDump {
return nil
}
lines, err := loadHostsFile()
Function NewMeshCommand
has 5 return statements (exceeds 4 allowed). Open
func NewMeshCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "mesh",
Short: "Redirect marked requests of specified kubernetes service to local",
PreRunE: func(cmd *cobra.Command, args []string) error {
Function ExtractHostIp
has 5 return statements (exceeds 4 allowed). Open
func ExtractHostIp(url string) string {
if !strings.Contains(url, ":") {
return ""
}
host := strings.Trim(strings.Split(url, ":")[1], "/")
Method Cli.RunScript
has 5 return statements (exceeds 4 allowed). Open
func (c *Cli) RunScript(privateKey, sshAddress, script string) (result string, err error) {
dialer, err := sshproxy.NewDialer(getSshTunnelAddress(privateKey, sshAddress))
if err != nil {
return "", err
}
Function Recover
has a Cognitive Complexity of 22 (exceeds 20 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)
}
- 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 fetchTargetRole
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
func fetchTargetRole(apps *appV1.DeploymentList, pods *coreV1.PodList) (*appV1.Deployment, *coreV1.Pod, string) {
if len(apps.Items) > 0 {
for _, app := range apps.Items {
if app.Labels != nil {
if role, ok2 := app.Labels[util.KtRole]; ok2 {
- 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"