-
Notifications
You must be signed in to change notification settings - Fork 1.1k
server: refactor handling of cleanup funcs #4241
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
server: refactor handling of cleanup funcs #4241
Conversation
|
/retest |
289d5e3 to
6da311a
Compare
|
/retest |
6da311a to
33ad337
Compare
Codecov Report
@@ Coverage Diff @@
## master #4241 +/- ##
==========================================
- Coverage 39.26% 39.22% -0.05%
==========================================
Files 112 112
Lines 8839 8819 -20
==========================================
- Hits 3471 3459 -12
+ Misses 4982 4973 -9
- Partials 386 387 +1 |
|
/retest |
33ad337 to
7f2b2c3
Compare
|
/retest |
|
pulled in #4198 to make sure that deferred func is included |
server/container_create_linux.go
Outdated
| err2 := s.StorageRuntimeServer().DeleteContainer(containerInfo.ID) | ||
| if err2 != nil { |
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.
| err2 := s.StorageRuntimeServer().DeleteContainer(containerInfo.ID) | |
| if err2 != nil { | |
| err := s.StorageRuntimeServer().DeleteContainer(containerInfo.ID); if err != nil { |
server/container_create.go
Outdated
| defer func() { | ||
| if retErr != nil { | ||
| log.Infof(ctx, "createCtr: removing container ID %s from runtime", ctr.ID()) | ||
| if err2 := s.Runtime().DeleteContainer(newContainer); err2 != nil { |
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.
doesn't have to be err2.
| } | ||
| defer func() { | ||
| if retErr != nil { | ||
| log.Infof(ctx, "createCtrLinux: deleting container %s from storage", containerInfo.ID) |
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.
the function is named createSandboxContainer
|
I don't like the last commit much, it seems it complicates things (and decreases visibility) more than improves anything. |
Yeah, it's cheap, but doing it so many times is not needed. The main purpose of this PR is preparing for a larger refactor that requires we not cleanup when the error is not a context timeout. That'll add two extra checks: |
7f2b2c3 to
ea01c41
Compare
|
@haircommander: The following test failed, say
DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
ea01c41 to
6e724c4
Compare
|
/retest |
fidencio
left a comment
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.
LGTM, there's a nitpick comment, but feel free to ignore it.
| // cleaning up a failed sandbox creation. | ||
| // We don't need to create the file, as there will be no | ||
| // sandbox to restore | ||
| if !s.created { |
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.
Isn't this the same case as the one pointed out by @kolyshkin here: #4258 (review) ?
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'll rebase on #4241 once it merges :)
6e724c4 to
7244e40
Compare
|
this is ready @fidencio @umohnani8 @mrunalp @kolyshkin @giuseppe @saschagrunert |
|
/retest |
server/container_create.go
Outdated
| log.Infof(ctx, "createCtr: deleting container %s from storage", ctr.ID()) | ||
| err2 := s.StorageRuntimeServer().DeleteContainer(ctr.ID()) | ||
| if err2 != nil { | ||
| log.Warnf(ctx, "Failed to cleanup container directory: %v", err2) |
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.
soft suggest "directory" -> "storage"
server/sandbox_run_linux.go
Outdated
| cleanupFuncs = append(cleanupFuncs, func() { | ||
| log.Infof(ctx, "runSandbox: unmounting shmPath for sandbox %s", sbox.ID()) | ||
| if err2 := unix.Unmount(shmPath, unix.MNT_DETACH); err2 != nil { | ||
| log.Warnf(ctx, "failed to unmount shm for pod: %v", err2) |
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.
you say "for pod" here, but "for sandbox" at line 543? I'd be consistent.
server/sandbox_run_linux.go
Outdated
| cleanupFuncs = append(cleanupFuncs, func() { | ||
| log.Infof(ctx, "runSandbox: deleting pod ID %s from idIndex", sbox.ID()) | ||
| if err := s.PodIDIndex().Delete(sbox.ID()); err != nil { | ||
| log.Warnf(ctx, "couldn't delete pod id %s from idIndex", sbox.ID()) |
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.
| log.Warnf(ctx, "couldn't delete pod id %s from idIndex", sbox.ID()) | |
| log.Warnf(ctx, "couldn't delete pod ID %s from idIndex", sbox.ID()) |
server/sandbox_run_linux.go
Outdated
| log.Errorf(ctx, "error stopping network on cleanup: %v", err2) | ||
| } | ||
| cleanupFuncs = append(cleanupFuncs, func() { | ||
| log.Infof(ctx, "runSandbox: in not manageNSLifecycle, stopping network for sandbox %s", sb.ID()) |
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.
Perhaps?
| log.Infof(ctx, "runSandbox: in not manageNSLifecycle, stopping network for sandbox %s", sb.ID()) | |
| log.Infof(ctx, "runSandbox: is not in manageNSLifecycle, stopping network for sandbox %s", sb.ID()) |
|
done picking. Just a few suggestions for consideration, only message near the end that was badly formed and should really be reworked. |
Signed-off-by: Peter Hunt <[email protected]>
|
nits addressed! |
|
/retest |
1 similar comment
|
/retest |
| return nil, errors.Wrap(err, "setting container name and ID") | ||
| } | ||
|
|
||
| cleanupFuncs := make([]func(), 0) |
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 think , 0 is redundant
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.
you need to specify a length when initializing a slice
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.
Right, I always forget about this.
cleanupFuncs := []func(){}maybe?
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.
is there any reason that is better than using make (which feels more idiomatic to me)
|
Side note: there is a way that looks nice, does not require Something like this (pseudocode): var retErr error
err: = do_a(); if err != nil {
retErr = errors.Wrap(err, "failed to do a")
goto undo_a
}
if err := do_b(); err != nil {
retErr = errors.Wrap(err, "failed to do b")
goto undo_b
}
if err := do_c(); err != nil {
retErr = errors.Wrap(err, "failed to do c")
goto undo_c
}
return nil
undo_c:
undo_c()
undo_b:
undo_b()
undo_a:
undo_a()
log(retErr)
return retErrSurely, wrapping and logging are optional. Basically it is like lots of nested |
|
/retest |
I'm not sure I want to go down this route, I'm not crazy about @kolyshkin @giuseppe @mrunalp @umohnani8 @saschagrunert @TomSweeneyRedHat |
saschagrunert
left a comment
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.
LGTM
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: haircommander, saschagrunert The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm |
|
/retest |
|
@haircommander: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
e2e-gcp passed, force merging instead of wasting more cycles on flakes |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
it doesn't make very much sense to have so many deferred funcs queued, and check retErr each time
instead, we can check retErr once, and loop through a slice of cleanupFuncs
this also carries #4240 to avoid a merge conflict
Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?