pkg/kt/command/mesh/auto.go
Function AutoMesh
has 68 lines of code (exceeds 50 allowed). Consider refactoring. Open
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 AutoMesh
has 10 return statements (exceeds 4 allowed). Open
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 createRouter
has 7 return statements (exceeds 4 allowed). Open
Open
func createRouter(routerPodName string, svcName string, ports map[int]int, labels map[string]string, versionMark string) error {
namespace := opt.Get().Global.Namespace
routerPod, err := cluster.Ins().GetPod(routerPodName, namespace)
if err == nil && routerPod.DeletionTimestamp != nil {
routerPod, err = cluster.Ins().WaitPodTerminate(routerPodName, namespace)
Function AutoMesh
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
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
- 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 createRouter
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func createRouter(routerPodName string, svcName string, ports map[int]int, labels map[string]string, versionMark string) error {
Function createStuntmanService
has 5 return statements (exceeds 4 allowed). Open
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 isNameUsable
has 5 return statements (exceeds 4 allowed). Open
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