Method Updater.Run
has a Cognitive Complexity of 73 (exceeds 20 allowed). Consider refactoring. Open
func (u *Updater) Run(ctx context.Context, slots []orchestrator.Slot) {
defer close(u.doneChan)
service := u.newService
- 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 Updater.Run
has 149 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (u *Updater) Run(ctx context.Context, slots []orchestrator.Slot) {
defer close(u.doneChan)
service := u.newService
Method Updater.worker
has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring. Open
func (u *Updater) worker(ctx context.Context, queue <-chan orchestrator.Slot, updateConfig *api.UpdateConfig) {
for slot := range queue {
// Do we have a task with the new spec in desired state = RUNNING?
// If so, all we have to do to complete the update is remove the
// other tasks. Or if we have a task with the new spec that has
- 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
File updater.go
has 523 lines of code (exceeds 500 allowed). Consider refactoring. Open
package update
import (
"context"
"errors"
Method Updater.updateTask
has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring. Open
func (u *Updater) updateTask(ctx context.Context, slot orchestrator.Slot, updated *api.Task, order api.UpdateConfig_UpdateOrder) error {
// Kick off the watch before even creating the updated task. This is in order to avoid missing any event.
taskUpdates, cancel := state.Watch(u.watchQueue, api.EventUpdateTask{
Task: &api.Task{ID: updated.ID},
Checks: []api.TaskCheckFunc{api.TaskCheckID},
- 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 Updater.updateTask
has 66 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (u *Updater) updateTask(ctx context.Context, slot orchestrator.Slot, updated *api.Task, order api.UpdateConfig_UpdateOrder) error {
// Kick off the watch before even creating the updated task. This is in order to avoid missing any event.
taskUpdates, cancel := state.Watch(u.watchQueue, api.EventUpdateTask{
Task: &api.Task{ID: updated.ID},
Checks: []api.TaskCheckFunc{api.TaskCheckID},
Method Updater.updateTask
has 11 return statements (exceeds 4 allowed). Open
func (u *Updater) updateTask(ctx context.Context, slot orchestrator.Slot, updated *api.Task, order api.UpdateConfig_UpdateOrder) error {
// Kick off the watch before even creating the updated task. This is in order to avoid missing any event.
taskUpdates, cancel := state.Watch(u.watchQueue, api.EventUpdateTask{
Task: &api.Task{ID: updated.ID},
Checks: []api.TaskCheckFunc{api.TaskCheckID},
Avoid deeply nested control flow statements. Open
if err != nil {
log.G(ctx).WithError(err).WithField("task.id", updated.ID).Warning("failed to remove old task after starting replacement")
}
Method Updater.Run
has 7 return statements (exceeds 4 allowed). Open
func (u *Updater) Run(ctx context.Context, slots []orchestrator.Slot) {
defer close(u.doneChan)
service := u.newService
Method Updater.useExistingTask
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. 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)
- 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 Updater.useExistingTask
has 5 return statements (exceeds 4 allowed). 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 Updater.rollbackUpdate
has 5 return statements (exceeds 4 allowed). Open
func (u *Updater) rollbackUpdate(ctx context.Context, serviceID, message string) {
log.G(ctx).Debugf("starting rollback of service %s", serviceID)
err := u.store.Update(func(tx store.Tx) error {
service := store.GetService(tx, serviceID)
Method Updater.removeOldTasks
has 5 return statements (exceeds 4 allowed). Open
func (u *Updater) removeOldTasks(ctx context.Context, batch *store.Batch, removeTasks []*api.Task) (*api.Task, error) {
var (
lastErr error
removedTask *api.Task
)