Showing 1,008 of 1,820 total issues
Method Supervisor.waitRestart
has 5 return statements (exceeds 4 allowed). Open
Open
func (r *Supervisor) waitRestart(ctx context.Context, oldDelay *delayedStart, cluster *api.Cluster, taskID string) {
// Wait for the last restart delay to elapse.
select {
case <-oldDelay.doneCh:
case <-ctx.Done():
Method Orchestrator.Run
has 5 return statements (exceeds 4 allowed). Open
Open
func (r *Orchestrator) Run(ctx context.Context) error {
defer close(r.doneChan)
// Watch changes to services and tasks
queue := r.store.WatchQueue()
Method Dispatcher.moveTasksToOrphaned
has 5 return statements (exceeds 4 allowed). Open
Open
func (d *Dispatcher) moveTasksToOrphaned(nodeID string) error {
err := d.store.Batch(func(batch *store.Batch) error {
var (
tasks []*api.Task
err error
Method Dispatcher.UpdateTaskStatus
has 5 return statements (exceeds 4 allowed). Open
Open
func (d *Dispatcher) UpdateTaskStatus(ctx context.Context, r *api.UpdateTaskStatusRequest) (*api.UpdateTaskStatusResponse, error) {
d.rpcRW.RLock()
defer d.rpcRW.RUnlock()
dctx, err := d.isRunningLocked()
Method PluginFilter.Check
has 5 return statements (exceeds 4 allowed). Open
Open
func (f *PluginFilter) Check(n *NodeInfo) bool {
if n.Description == nil || n.Description.Engine == nil {
// If the node is not running Engine, plugins are not
// supported.
return true
Method Server.UpdateNode
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (s *Server) UpdateNode(ctx context.Context, request *api.UpdateNodeRequest) (*api.UpdateNodeResponse, error) {
if request.NodeID == "" || request.NodeVersion == nil {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
if err := validateNodeSpec(request.Spec); err != nil {
- 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 plugin.PublishVolume
has 5 return statements (exceeds 4 allowed). Open
Open
func (p *plugin) PublishVolume(ctx context.Context, v *api.Volume, nodeID string) (map[string]string, error) {
if !p.publisher {
return nil, nil
}
csiNodeID := p.swarmToCSI[nodeID]
Method volumeSet.freeVolumes
has 5 return statements (exceeds 4 allowed). Open
Open
func (vs *volumeSet) freeVolumes(batch *store.Batch) error {
for volumeID, info := range vs.volumes {
if err := batch.Update(func(tx store.Tx) error {
v := store.GetVolume(tx, volumeID)
if v == nil {
Method Server.RemoveTask
has 5 return statements (exceeds 4 allowed). Open
Open
func (s *Server) RemoveTask(ctx context.Context, request *api.RemoveTaskRequest) (*api.RemoveTaskResponse, error) {
if request.TaskID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
Method Updater.useExistingTask
has 5 return statements (exceeds 4 allowed). Open
Open
func (u *Updater) useExistingTask(ctx context.Context, slot orchestrator.Slot, existing *api.Task) error {
var removeTasks []*api.Task
for _, t := range slot {
if t != existing {
removeTasks = append(removeTasks, t)
Method TasksByTimestamp.Less
has 5 return statements (exceeds 4 allowed). Open
Open
func (t TasksByTimestamp) Less(i, j int) bool {
iTimestamp := taskTimestamp(t[i])
jTimestamp := taskTimestamp(t[j])
if iTimestamp == nil {
Method Scheduler.scheduleTaskGroup
has 5 return statements (exceeds 4 allowed). Open
Open
func (s *Scheduler) scheduleTaskGroup(ctx context.Context, taskGroup map[string]*api.Task, schedulingDecisions map[string]schedulingDecision) {
// Pick at task at random from taskGroup to use for constraint
// evaluation. It doesn't matter which one we pick because all the
// tasks in the group are equal in terms of the fields the constraint
// filters consider.
Function validateResources
has 5 return statements (exceeds 4 allowed). Open
Open
func validateResources(r *api.Resources) error {
if r == nil {
return nil
}
Method Server.RemoveService
has 5 return statements (exceeds 4 allowed). Open
Open
func (s *Server) RemoveService(ctx context.Context, request *api.RemoveServiceRequest) (*api.RemoveServiceResponse, error) {
if request.ServiceID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
Method Updater.removeOldTasks
has 5 return statements (exceeds 4 allowed). Open
Open
func (u *Updater) removeOldTasks(ctx context.Context, batch *store.Batch, removeTasks []*api.Task) (*api.Task, error) {
var (
lastErr error
removedTask *api.Task
)
Method Manager.getPlugin
has 5 return statements (exceeds 4 allowed). Open
Open
func (vm *Manager) getPlugin(name string) (Plugin, error) {
// if the plugin already exists, we can just return it.
if p, ok := vm.plugins[name]; ok {
return p, nil
}
Method Manager.createVolume
has 5 return statements (exceeds 4 allowed). Open
Open
func (vm *Manager) createVolume(ctx context.Context, v *api.Volume) error {
l := log.G(ctx).WithField("volume.id", v.ID).WithField("driver", v.Spec.Driver.Name)
l.Info("creating volume")
p, err := vm.getPlugin(v.Spec.Driver.Name)
Method volumeSet.isVolumeAvailableOnNode
has 5 return statements (exceeds 4 allowed). Open
Open
func (vs *volumeSet) isVolumeAvailableOnNode(mount *api.Mount, node *NodeInfo) string {
source := mount.Source
// first, discern whether we're looking for a group or a volume
// try trimming off the "group:" prefix. if the resulting string is
// different from the input string (meaning something has been trimmed),
Method Dispatcher.Run
has 5 return statements (exceeds 4 allowed). Open
Open
func (d *Dispatcher) Run(ctx context.Context) error {
ctx = log.WithModule(ctx, "dispatcher")
log.G(ctx).Info("dispatcher starting")
d.taskUpdatesLock.Lock()
Method Deallocator.processNetwork
has 5 return statements (exceeds 4 allowed). Open
Open
func (deallocator *Deallocator) processNetwork(ctx context.Context, tx store.Tx, network *api.Network, ignoreServiceID *string) (updated bool, err error) {
if !network.PendingDelete {
return
}