-
Notifications
You must be signed in to change notification settings - Fork 656
Update task status during a network allocation failure #2358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import ( | |
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/docker/go-events" | ||
| events "github.com/docker/go-events" | ||
| "github.com/docker/swarmkit/api" | ||
| "github.com/docker/swarmkit/log" | ||
| "github.com/docker/swarmkit/manager/allocator/cnmallocator" | ||
|
|
@@ -529,6 +529,7 @@ func (a *Allocator) allocateTasks(ctx context.Context, existingAddressesOnly boo | |
| nc = a.netCtx | ||
| tasks []*api.Task | ||
| allocatedTasks []*api.Task | ||
| errorTasks []*api.Task | ||
| err error | ||
| ) | ||
| a.store.View(func(tx store.ReadTx) { | ||
|
|
@@ -587,14 +588,16 @@ func (a *Allocator) allocateTasks(ctx context.Context, existingAddressesOnly boo | |
| if err == nil { | ||
| allocatedTasks = append(allocatedTasks, t) | ||
| } else if err != errNoChanges { | ||
| errorTasks = append(errorTasks, t) | ||
| log.G(ctx).WithError(err).Errorf("failed allocating task %s during init", t.ID) | ||
| updateTaskError(t, fmt.Sprintf("failed allocating task during init: %s", err)) | ||
| nc.unallocatedTasks[t.ID] = t | ||
| } | ||
| } | ||
|
|
||
| if err := a.store.Batch(func(batch *store.Batch) error { | ||
| for _, t := range allocatedTasks { | ||
| if err := a.commitAllocatedTask(ctx, batch, t); err != nil { | ||
| for _, t := range append(allocatedTasks, errorTasks...) { | ||
| if err := a.commitTask(ctx, batch, t); err != nil { | ||
| log.G(ctx).WithError(err).Errorf("failed committing allocation of task %s during init", t.ID) | ||
| } | ||
| } | ||
|
|
@@ -1001,7 +1004,7 @@ func (a *Allocator) allocateTask(ctx context.Context, t *api.Task) (err error) { | |
| return nil | ||
| } | ||
|
|
||
| func (a *Allocator) commitAllocatedTask(ctx context.Context, batch *store.Batch, t *api.Task) error { | ||
| func (a *Allocator) commitTask(ctx context.Context, batch *store.Batch, t *api.Task) error { | ||
| return batch.Update(func(tx store.Tx) error { | ||
| err := store.UpdateTask(tx, t) | ||
|
|
||
|
|
@@ -1106,26 +1109,29 @@ func (a *Allocator) procTasksNetwork(ctx context.Context, onRetry bool) { | |
| quiet = true | ||
| } | ||
| allocatedTasks := make([]*api.Task, 0, len(toAllocate)) | ||
| errorTasks := make([]*api.Task, 0, len(toAllocate)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do tasks get added to this slice?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops, forgot to update this code block. Fixed. |
||
|
|
||
| for _, t := range toAllocate { | ||
| if err := a.allocateTask(ctx, t); err == nil { | ||
| allocatedTasks = append(allocatedTasks, t) | ||
| } else if err != errNoChanges { | ||
| errorTasks = append(errorTasks, t) | ||
| if quiet { | ||
| log.G(ctx).WithError(err).Debug("task allocation failure") | ||
| } else { | ||
| log.G(ctx).WithError(err).Error("task allocation failure") | ||
| } | ||
| updateTaskError(t, fmt.Sprintf("task allocation failure: %s", err)) | ||
| } | ||
| } | ||
|
|
||
| if len(allocatedTasks) == 0 { | ||
| if len(allocatedTasks) == 0 && len(errorTasks) == 0 { | ||
| return | ||
| } | ||
|
|
||
| err := a.store.Batch(func(batch *store.Batch) error { | ||
| for _, t := range allocatedTasks { | ||
| err := a.commitAllocatedTask(ctx, batch, t) | ||
| for _, t := range append(allocatedTasks, errorTasks...) { | ||
| err := a.commitTask(ctx, batch, t) | ||
| if err != nil { | ||
| log.G(ctx).WithError(err).Error("task allocation commit failure") | ||
| continue | ||
|
|
@@ -1157,13 +1163,19 @@ func PredefinedNetworks() []networkallocator.PredefinedNetworkData { | |
| return cnmallocator.PredefinedNetworks() | ||
| } | ||
|
|
||
| // updateTaskStatus sets TaskStatus and updates timestamp. | ||
| // updateTaskStatus sets TaskStatus and message and updates timestamp. | ||
| func updateTaskStatus(t *api.Task, newStatus api.TaskState, message string) { | ||
| t.Status.State = newStatus | ||
| t.Status.Message = message | ||
| t.Status.Timestamp = ptypes.MustTimestampProto(time.Now()) | ||
| } | ||
|
|
||
| // updateTaskError sets the task error and updates timestamp. | ||
| func updateTaskError(t *api.Task, message string) { | ||
| t.Status.Err = message | ||
| t.Status.Timestamp = ptypes.MustTimestampProto(time.Now()) | ||
| } | ||
|
|
||
| // IsIngressNetwork returns whether the passed network is an ingress network. | ||
| func IsIngressNetwork(nw *api.Network) bool { | ||
| return networkallocator.IsIngressNetwork(nw) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change shouldn't be necessary.