Showing 79 of 109 total issues
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 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 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 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 exchangeWithEphemeralContainer
has 5 return statements (exceeds 4 allowed). Open
func exchangeWithEphemeralContainer(exposePorts string, localSSHPort int, privateKey string) error {
// Get all listened ports on remote host
listenedPorts, err := getListenedPorts(localSSHPort, privateKey)
if err != nil {
return err
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], "/")
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 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 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
Method Kubernetes.waitPodsReady
has 5 return statements (exceeds 4 allowed). Open
func (k *Kubernetes) waitPodsReady(labels map[string]string, namespace string, timeoutSec int, times int) ([]coreV1.Pod, error) {
pods, err := k.GetPodsByLabel(labels, namespace)
if err != nil {
return nil, err
}
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 isPartOfRange
has 5 return statements (exceeds 4 allowed). Open
func isPartOfRange(ipRange string, subIpRange string) bool {
ipRangeBin, err := ipRangeToBin(ipRange)
if err != nil {
return false
}
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 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 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 LockService
has 5 return statements (exceeds 4 allowed). Open
func LockService(serviceName, namespace string, times int) (*coreV1.Service, error) {
if times > 10 {
return nil, fmt.Errorf("failed to obtain kt lock of service %s, please try again later", serviceName)
}
svc, err := cluster.Ins().GetService(serviceName, namespace)
Function exposeLocalService
has 5 return statements (exceeds 4 allowed). Open
func exposeLocalService(serviceName, shadowPodName string, labels, annotations map[string]string) error {
envs := make(map[string]string)
_, podName, privateKeyPath, err := cluster.Ins().GetOrCreateShadow(shadowPodName, labels, annotations, envs,
opt.Get().Preview.Expose, map[int]string{})
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 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"