-
Notifications
You must be signed in to change notification settings - Fork 656
Delete node attachments when node is removed #2409
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
Merged
Merged
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 |
|---|---|---|
|
|
@@ -248,6 +248,29 @@ func (s *Server) UpdateNode(ctx context.Context, request *api.UpdateNodeRequest) | |
| }, nil | ||
| } | ||
|
|
||
| func removeNodeAttachments(tx store.Tx, nodeID string) error { | ||
| // orphan the node's attached containers. if we don't do this, the | ||
| // network these attachments are connected to will never be removeable | ||
| tasks, err := store.FindTasks(tx, store.ByNodeID(nodeID)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for _, task := range tasks { | ||
| // if the task is an attachment, then we just delete it. the allocator | ||
| // will do the heavy lifting. basically, GetAttachment will return the | ||
| // attachment if that's the kind of runtime, or nil if it's not. | ||
| if task.Spec.GetAttachment() != nil { | ||
| // don't delete the task. instead, update it to `ORPHANED` so that | ||
| // the taskreaper will clean it up. | ||
| task.Status.State = api.TaskStateOrphaned | ||
| if err := store.UpdateTask(tx, task); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // RemoveNode removes a Node referenced by NodeID with the given NodeSpec. | ||
| // - Returns NotFound if the Node is not found. | ||
| // - Returns FailedPrecondition if the Node has manager role (and is part of the memberlist) or is not shut down. | ||
|
|
@@ -313,6 +336,10 @@ func (s *Server) RemoveNode(ctx context.Context, request *api.RemoveNodeRequest) | |
| return err | ||
| } | ||
|
|
||
| if err := removeNodeAttachments(tx, request.NodeID); err != nil { | ||
|
Contributor
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. It probably makes sense to add a comment here to say why we're doing this. |
||
| return err | ||
| } | ||
|
|
||
| return store.DeleteNode(tx, request.NodeID) | ||
| }) | ||
| if err != nil { | ||
|
|
||
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
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.
Spoke with @dperny offline but capturing here for everyone else: I guess it makes sense to enforce a model where the task reaper is the only place where tasks are deleted. We could mark these tasks as orphaned and let them be cleaned out by the reaper, with the caveat that the network attachments are removable for orphaned tasks.
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.
I agree with marking the tasks
Orphanedwhen the associated node is deleted. I think that's exactly the right behavior.This should be done in the orchestrators, which is what controls task lifecycle. For example, in the replicated orchestrator:
We would want to modify this code to set the old task's state (not desired state) to
Orphaned. The code here might be a little hard to follow, because the tasks get added to a map that's eventually processed as a batch, with those tasks getting passed toRestart. We could potentially have a separate map for tasks that need to become orphaned, and pass them to the restart manager in the same way, but then set the state toOrphanedafter callingRestart.The global orchestrator would need similar changes.
For network attachment tasks, I'm not entirely sure what the best way is. We could create a simple orchestrator for those that just watches for node deletion events. I think that's the cleanest way, but as a simpler kludge we could handle this in the network allocator.
I don't think any changes in the task reaper or network allocator are necessary, because once a task's state is set to
Orphaned, its network resources are supposed to be freed. But it's definitely worth confirming that this works as expected after the node has been deleted.Uh oh!
There was an error while loading. Please reload this page.
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.
I see that when we remove a node, we delete all tasks for that node from the store. What is the reason to not keep the history around in that case ? Since the service may still be around, doesn't it make sense to keep the task history from that node around ? @aaronlehmann
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.
It was done for global service tasks because otherwise these tasks would stay in the store forever. The task reaper keeps a certain number per node, so there's no provision for removing all the tasks from dead nodes. I'm not sure I see a better way than deleting it immediately, because with the node no longer in the system, we'll never know when the task has shut truly shut down, and is finally safe to delete. Possibly we could use the orphaned state, as discussed above, though if we wanted to be really careful, we would set that state after a delay passes, like we do for unresponsive nodes.
For reference, here's the commit that made the change: 56463e4