Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@haircommander
Copy link
Member

What type of PR is this?

/kind cleanup

/kind dependency-change
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

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?

none

@openshift-ci-robot openshift-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Oct 2, 2020
@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 2, 2020
@haircommander
Copy link
Member Author

/retest

@haircommander haircommander force-pushed the cleanup-func-refactor branch from 289d5e3 to 6da311a Compare October 2, 2020 19:56
@haircommander
Copy link
Member Author

/retest

@haircommander haircommander force-pushed the cleanup-func-refactor branch from 6da311a to 33ad337 Compare October 2, 2020 20:47
@codecov
Copy link

codecov bot commented Oct 2, 2020

Codecov Report

Merging #4241 (8dd12dc) into master (61c8b37) will decrease coverage by 0.04%.
The diff coverage is 26.38%.

@@            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     

@haircommander
Copy link
Member Author

/retest

@haircommander haircommander force-pushed the cleanup-func-refactor branch from 33ad337 to 7f2b2c3 Compare October 5, 2020 20:10
@haircommander
Copy link
Member Author

/retest

@haircommander
Copy link
Member Author

pulled in #4198 to make sure that deferred func is included

Comment on lines 378 to 379
err2 := s.StorageRuntimeServer().DeleteContainer(containerInfo.ID)
if err2 != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err2 := s.StorageRuntimeServer().DeleteContainer(containerInfo.ID)
if err2 != nil {
err := s.StorageRuntimeServer().DeleteContainer(containerInfo.ID); if err != nil {

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 {
Copy link
Collaborator

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)
Copy link
Collaborator

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

@kolyshkin
Copy link
Collaborator

I don't like the last commit much, it seems it complicates things (and decreases visibility) more than improves anything. defer is cheap in Go 1.15+, != nil check is cheap, too.

@haircommander
Copy link
Member Author

I don't like the last commit much, it seems it complicates things (and decreases visibility) more than improves anything. defer is cheap in Go 1.15+, != nil check is cheap, too.

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: err != context.Canceled && err != context.DeadlineExceeded along with the non-nil check, which I think better justifies the PR.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 11, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 12, 2020
@openshift-ci-robot
Copy link

openshift-ci-robot commented Oct 12, 2020

@haircommander: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/openshift-jenkins/integration_crun_cgroupv2 ea01c41 link /test integration_cgroupv2
Details

Instructions 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.

@haircommander
Copy link
Member Author

/retest

Copy link
Contributor

@fidencio fidencio left a 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 {
Copy link
Contributor

@fidencio fidencio Nov 12, 2020

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) ?

Copy link
Member Author

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 :)

@haircommander
Copy link
Member Author

@haircommander
Copy link
Member Author

/retest

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soft suggest "directory" -> "storage"

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)
Copy link
Contributor

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.

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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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())

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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps?

Suggested change
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())

@TomSweeneyRedHat
Copy link
Contributor

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]>
@haircommander
Copy link
Member Author

nits addressed!

@haircommander
Copy link
Member Author

/retest

1 similar comment
@haircommander
Copy link
Member Author

/retest

return nil, errors.Wrap(err, "setting container name and ID")
}

cleanupFuncs := make([]func(), 0)
Copy link
Collaborator

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

Copy link
Member Author

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

Copy link
Collaborator

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?

Copy link
Member Author

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)

@kolyshkin
Copy link
Collaborator

kolyshkin commented Nov 20, 2020

Side note: there is a way that looks nice, does not require defers, named return values, or repeated error checks. It only requires labels and goto.

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 retErr

Surely, wrapping and logging are optional. Basically it is like lots of nested ifs, but without the ugliness of too much nesting.

@haircommander
Copy link
Member Author

/retest

@haircommander
Copy link
Member Author

Side note: there is a way that looks nice, does not require defers, named return values, or repeated error checks. It only requires labels and goto.
....
Surely, wrapping and logging are optional. Basically it is like lots of nested ifs, but without the ugliness of too much nesting.

I'm not sure I want to go down this route, I'm not crazy about gotos and I don't think it really cleans up the code all that much. Right now, this change is pretty small and will be useful later, are there any blocking comments left

@kolyshkin @giuseppe @mrunalp @umohnani8 @saschagrunert @TomSweeneyRedHat

Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@openshift-ci-robot
Copy link

[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

Details Needs approval from an approver in each of these files:
  • OWNERS [haircommander,saschagrunert]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@haircommander
Copy link
Member Author

@mrunalp
Copy link
Member

mrunalp commented Nov 30, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 30, 2020
@haircommander haircommander added this to the 1.20 milestone Nov 30, 2020
@haircommander
Copy link
Member Author

/retest

@openshift-merge-robot
Copy link
Contributor

@haircommander: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-agnostic 8dd12dc link /test e2e-agnostic

Full PR test history. Your PR dashboard.

Details

Instructions 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.

@haircommander
Copy link
Member Author

e2e-gcp passed, force merging instead of wasting more cycles on flakes

@haircommander haircommander merged commit 4dff9dd into cri-o:master Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants