File networkallocator.go
has 684 lines of code (exceeds 500 allowed). Consider refactoring. Open
package cnmallocator
import (
"context"
"fmt"
Method cnmNetworkAllocator.IsServiceAllocated
has a Cognitive Complexity of 42 (exceeds 20 allowed). Consider refactoring. Open
func (na *cnmNetworkAllocator) IsServiceAllocated(s *api.Service, flags ...func(*networkallocator.ServiceAllocationOpts)) bool {
specNetworks := serviceNetworks(s)
// If endpoint mode is VIP and allocator does not have the
// service in VIP allocated set then it needs to be allocated.
- 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 cnmNetworkAllocator.AllocateService
has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring. Open
func (na *cnmNetworkAllocator) AllocateService(s *api.Service) (err error) {
defer func() {
if err != nil {
na.DeallocateService(s)
}
- 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
cnmNetworkAllocator
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
type cnmNetworkAllocator struct {
// The plugin getter instance used to get network and IPAM driver plugins.
pg plugingetter.PluginGetter
// The driver registry for all internal and external IPAM drivers.
Method cnmNetworkAllocator.allocatePools
has 66 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (na *cnmNetworkAllocator) allocatePools(n *api.Network) (map[string]string, error) {
ipam, dName, dOptions, err := na.resolveIPAM(n)
if err != nil {
return nil, err
}
Method cnmNetworkAllocator.AllocateService
has 64 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (na *cnmNetworkAllocator) AllocateService(s *api.Service) (err error) {
defer func() {
if err != nil {
na.DeallocateService(s)
}
Method cnmNetworkAllocator.allocateNetworkIPs
has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring. Open
func (na *cnmNetworkAllocator) allocateNetworkIPs(nAttach *api.NetworkAttachment) error {
var ip *net.IPNet
var opts map[string]string
ipam, _, _, err := na.resolveIPAM(nAttach.Network)
- 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 cnmNetworkAllocator.allocatePools
has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring. Open
func (na *cnmNetworkAllocator) allocatePools(n *api.Network) (map[string]string, error) {
ipam, dName, dOptions, err := na.resolveIPAM(n)
if err != nil {
return nil, 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
Method cnmNetworkAllocator.allocateVIP
has 8 return statements (exceeds 4 allowed). Open
func (na *cnmNetworkAllocator) allocateVIP(vip *api.Endpoint_VirtualIP) error {
var opts map[string]string
localNet := na.getNetwork(vip.NetworkID)
if localNet == nil {
return errors.New("networkallocator: could not find local network state")
Method cnmNetworkAllocator.IsAttachmentAllocated
has 8 return statements (exceeds 4 allowed). Open
func (na *cnmNetworkAllocator) IsAttachmentAllocated(node *api.Node, networkAttachment *api.NetworkAttachment) bool {
if node == nil {
return false
}
Method cnmNetworkAllocator.IsServiceAllocated
has 7 return statements (exceeds 4 allowed). Open
func (na *cnmNetworkAllocator) IsServiceAllocated(s *api.Service, flags ...func(*networkallocator.ServiceAllocationOpts)) bool {
specNetworks := serviceNetworks(s)
// If endpoint mode is VIP and allocator does not have the
// service in VIP allocated set then it needs to be allocated.
Method cnmNetworkAllocator.IsTaskAllocated
has 6 return statements (exceeds 4 allowed). Open
func (na *cnmNetworkAllocator) IsTaskAllocated(t *api.Task) bool {
// If the task is not found in the allocated set, then it is
// not allocated.
if _, ok := na.tasks[t.ID]; !ok {
return false
Method cnmNetworkAllocator.deallocateVIP
has 6 return statements (exceeds 4 allowed). Open
func (na *cnmNetworkAllocator) deallocateVIP(vip *api.Endpoint_VirtualIP) error {
localNet := na.getNetwork(vip.NetworkID)
if localNet == nil {
return errors.New("networkallocator: could not find local network state")
}
Method cnmNetworkAllocator.allocateNetworkIPs
has 6 return statements (exceeds 4 allowed). Open
func (na *cnmNetworkAllocator) allocateNetworkIPs(nAttach *api.NetworkAttachment) error {
var ip *net.IPNet
var opts map[string]string
ipam, _, _, err := na.resolveIPAM(nAttach.Network)
Method cnmNetworkAllocator.allocatePools
has 6 return statements (exceeds 4 allowed). Open
func (na *cnmNetworkAllocator) allocatePools(n *api.Network) (map[string]string, error) {
ipam, dName, dOptions, err := na.resolveIPAM(n)
if err != nil {
return nil, err
}
Method Provider.NewAllocator
has 5 return statements (exceeds 4 allowed). Open
func (p *Provider) NewAllocator(netConfig *networkallocator.Config) (networkallocator.NetworkAllocator, error) {
na := &cnmNetworkAllocator{
networks: make(map[string]*network),
services: make(map[string]struct{}),
tasks: make(map[string]struct{}),
Method cnmNetworkAllocator.Allocate
has 5 return statements (exceeds 4 allowed). Open
func (na *cnmNetworkAllocator) Allocate(n *api.Network) error {
if _, ok := na.networks[n.ID]; ok {
return fmt.Errorf("network %s already allocated", n.ID)
}
Method cnmNetworkAllocator.AllocateService
has 5 return statements (exceeds 4 allowed). Open
func (na *cnmNetworkAllocator) AllocateService(s *api.Service) (err error) {
defer func() {
if err != nil {
na.DeallocateService(s)
}