Showing 109 of 109 total issues
Function NewRecoverCommand
has 5 return statements (exceeds 4 allowed). Open
func NewRecoverCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "recover",
Short: "Restore traffic of specified kubernetes service changed by exchange or mesh",
PreRunE: func(cmd *cobra.Command, args []string) error {
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 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 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 {
Similar blocks of code found in 4 locations. Consider refactoring. Open
for _, name := range r.DeploymentsToDelete {
err := cluster.Ins().RemoveDeployment(name, opt.Get().Global.Namespace)
if err != nil {
log.Warn().Err(err).Msgf("Failed to delete deployment %s", name)
} else {
- 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 105.
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 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], "/")
Similar blocks of code found in 4 locations. Consider refactoring. Open
for _, name := range r.PodsToDelete {
err := cluster.Ins().RemovePod(name, opt.Get().Global.Namespace)
if err != nil {
log.Warn().Err(err).Msgf("Failed to delete pods %s", name)
} else {
- 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 105.
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 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 {
Similar blocks of code found in 4 locations. Consider refactoring. Open
for _, name := range r.ServicesToDelete {
err := cluster.Ins().RemoveService(name, opt.Get().Global.Namespace)
if err != nil {
log.Warn().Err(err).Msgf("Failed to delete service %s", name)
} else {
- 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 105.
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 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()