{"action":"created","comment":{"url":"https://api.github.com/repos/alibaba/pouch/pulls/comments/236909196","pull_request_review_id":179085533,"id":236909196,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNjkwOTE5Ng==","diff_hunk":"@@ -98,23 +98,31 @@ func (w *watch) add(pack *containerPack) {\n \t\t\texitTime: status.ExitTime(),\n \t\t}\n \n+\t\t// NOTE: cleanup action should be taken only once!\n+\t\tvar cleanupOnce sync.Once\n+\t\tcleanupFunc := func() error {\n+\t\t\tcleanupOnce.Do(func() {\n+\t\t\t\tif _, err := pack.task.Delete(context.Background()); err != nil {\n+\t\t\t\t\tlogrus.Errorf(\"failed to delete task, container id: %s: %v\", pack.id, err)\n+\t\t\t\t}\n+\n+\t\t\t\tif err := pack.container.Delete(context.Background()); err != nil {\n+\t\t\t\t\tlogrus.Errorf(\"failed to delete container, container id: %s: %v\", pack.id, err)\n+\t\t\t\t}\n+\t\t\t})\n+\t\t\treturn nil\n+\t\t}\n+\n \t\tif !pack.skipStopHooks {\n \t\t\tfor _, hook := range w.hooks {\n-\t\t\t\tif err := hook(pack.id, msg); err != nil {\n+\t\t\t\tif err := hook(pack.id, msg, cleanupFunc); err != nil {\n \t\t\t\t\tlogrus.Errorf(\"failed to execute the exit hooks: %v\", err)\n \t\t\t\t\tbreak\n \t\t\t\t}\n \t\t\t}\n \t\t}\n+\t\tcleanupFunc()","path":"ctrd/watch.go","position":37,"original_position":37,"commit_id":"5289b02899f76bf35106c2c857bdb639d4267abb","original_commit_id":"5289b02899f76bf35106c2c857bdb639d4267abb","user":{"login":"HusterWan","id":10414039,"node_id":"MDQ6VXNlcjEwNDE0MDM5","avatar_url":"https://avatars3.githubusercontent.com/u/10414039?v=4","gravatar_id":"","url":"https://api.github.com/users/HusterWan","html_url":"https://github.com/HusterWan","followers_url":"https://api.github.com/users/HusterWan/followers","following_url":"https://api.github.com/users/HusterWan/following{/other_user}","gists_url":"https://api.github.com/users/HusterWan/gists{/gist_id}","starred_url":"https://api.github.com/users/HusterWan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HusterWan/subscriptions","organizations_url":"https://api.github.com/users/HusterWan/orgs","repos_url":"https://api.github.com/users/HusterWan/repos","events_url":"https://api.github.com/users/HusterWan/events{/privacy}","received_events_url":"https://api.github.com/users/HusterWan/received_events","type":"User","site_admin":false},"body":"@zhuangqh I got you!","created_at":"2018-11-28T01:14:39Z","updated_at":"2018-11-28T01:14:39Z","html_url":"https://github.com/alibaba/pouch/pull/2510#discussion_r236909196","pull_request_url":"https://api.github.com/repos/alibaba/pouch/pulls/2510","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/alibaba/pouch/pulls/comments/236909196"},"html":{"href":"https://github.com/alibaba/pouch/pull/2510#discussion_r236909196"},"pull_request":{"href":"https://api.github.com/repos/alibaba/pouch/pulls/2510"}},"in_reply_to_id":236663503},"pull_request":{"url":"https://api.github.com/repos/alibaba/pouch/pulls/2510","id":233898261,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMzODk4MjYx","html_url":"https://github.com/alibaba/pouch/pull/2510","diff_url":"https://github.com/alibaba/pouch/pull/2510.diff","patch_url":"https://github.com/alibaba/pouch/pull/2510.patch","issue_url":"https://api.github.com/repos/alibaba/pouch/issues/2510","number":2510,"state":"open","locked":false,"title":"bugfix: cleanup containerd container before do restart policy","user":{"login":"fuweid","id":17510957,"node_id":"MDQ6VXNlcjE3NTEwOTU3","avatar_url":"https://avatars3.githubusercontent.com/u/17510957?v=4","gravatar_id":"","url":"https://api.github.com/users/fuweid","html_url":"https://github.com/fuweid","followers_url":"https://api.github.com/users/fuweid/followers","following_url":"https://api.github.com/users/fuweid/following{/other_user}","gists_url":"https://api.github.com/users/fuweid/gists{/gist_id}","starred_url":"https://api.github.com/users/fuweid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fuweid/subscriptions","organizations_url":"https://api.github.com/users/fuweid/orgs","repos_url":"https://api.github.com/users/fuweid/repos","events_url":"https://api.github.com/users/fuweid/events{/privacy}","received_events_url":"https://api.github.com/users/fuweid/received_events","type":"User","site_admin":false},"body":"\r\nSigned-off-by: Wei Fu <fuweid89@gmail.com>\r\n\r\n<!-- \r\nPlease make sure you have read and understood the contributing guidelines;\r\nhttps://github.com/alibaba/pouch/blob/master/CONTRIBUTING.md -->\r\n\r\n### Ⅰ. Describe what this PR did\r\n\r\nIf the cleanup action is taken before restart policy, the restart action\r\nwill be failed because new container keeps the same name with the old\r\none. We should cleanup the old one before the restart policy.\r\n\r\nIn order to make it happen, we add the cleanup function in the hooks.\r\n\r\n> NOTE: the cleanup should be done after update status because we should make sure that all the status has been updated in the pouch container store.\r\n\r\n### Ⅱ. Does this pull request fix one issue?\r\n<!--If that, add \"fixes #xxxx\" below in the next line, for example, fixes #15. Otherwise, add \"NONE\" -->\r\n\r\nNONE\r\n\r\n### Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗？)\r\n\r\nno need\r\n\r\n### Ⅳ. Describe how to verify it\r\n\r\nUse the following command and the container should be restarted after exit.\r\n\r\n```\r\nsudo pouch run --restart=always -it busybox sh -c \"exit 1\"\r\n```\r\n\r\nAnd don't break existing case \r\n\r\n### Ⅴ. Special notes for reviews\r\n\r\n\r\n","created_at":"2018-11-27T12:47:30Z","updated_at":"2018-11-28T01:14:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3d3cf868e82f5a00124ccf8a5285f92fe7b208a7","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":684575943,"node_id":"MDU6TGFiZWw2ODQ1NzU5NDM=","url":"https://api.github.com/repos/alibaba/pouch/labels/kind/bug","name":"kind/bug","color":"f77e56","default":false},{"id":722354993,"node_id":"MDU6TGFiZWw3MjIzNTQ5OTM=","url":"https://api.github.com/repos/alibaba/pouch/labels/size/S","name":"size/S","color":"98f2a9","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/alibaba/pouch/pulls/2510/commits","review_comments_url":"https://api.github.com/repos/alibaba/pouch/pulls/2510/comments","review_comment_url":"https://api.github.com/repos/alibaba/pouch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alibaba/pouch/issues/2510/comments","statuses_url":"https://api.github.com/repos/alibaba/pouch/statuses/5289b02899f76bf35106c2c857bdb639d4267abb","head":{"label":"fuweid:bugfix_restart","ref":"bugfix_restart","sha":"5289b02899f76bf35106c2c857bdb639d4267abb","user":{"login":"fuweid","id":17510957,"node_id":"MDQ6VXNlcjE3NTEwOTU3","avatar_url":"https://avatars3.githubusercontent.com/u/17510957?v=4","gravatar_id":"","url":"https://api.github.com/users/fuweid","html_url":"https://github.com/fuweid","followers_url":"https://api.github.com/users/fuweid/followers","following_url":"https://api.github.com/users/fuweid/following{/other_user}","gists_url":"https://api.github.com/users/fuweid/gists{/gist_id}","starred_url":"https://api.github.com/users/fuweid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fuweid/subscriptions","organizations_url":"https://api.github.com/users/fuweid/orgs","repos_url":"https://api.github.com/users/fuweid/repos","events_url":"https://api.github.com/users/fuweid/events{/privacy}","received_events_url":"https://api.github.com/users/fuweid/received_events","type":"User","site_admin":false},"repo":{"id":143372593,"node_id":"MDEwOlJlcG9zaXRvcnkxNDMzNzI1OTM=","name":"pouch","full_name":"fuweid/pouch","private":false,"owner":{"login":"fuweid","id":17510957,"node_id":"MDQ6VXNlcjE3NTEwOTU3","avatar_url":"https://avatars3.githubusercontent.com/u/17510957?v=4","gravatar_id":"","url":"https://api.github.com/users/fuweid","html_url":"https://github.com/fuweid","followers_url":"https://api.github.com/users/fuweid/followers","following_url":"https://api.github.com/users/fuweid/following{/other_user}","gists_url":"https://api.github.com/users/fuweid/gists{/gist_id}","starred_url":"https://api.github.com/users/fuweid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fuweid/subscriptions","organizations_url":"https://api.github.com/users/fuweid/orgs","repos_url":"https://api.github.com/users/fuweid/repos","events_url":"https://api.github.com/users/fuweid/events{/privacy}","received_events_url":"https://api.github.com/users/fuweid/received_events","type":"User","site_admin":false},"html_url":"https://github.com/fuweid/pouch","description":"An Efficient Enterprise-class Rich Container Engine","fork":true,"url":"https://api.github.com/repos/fuweid/pouch","forks_url":"https://api.github.com/repos/fuweid/pouch/forks","keys_url":"https://api.github.com/repos/fuweid/pouch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fuweid/pouch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fuweid/pouch/teams","hooks_url":"https://api.github.com/repos/fuweid/pouch/hooks","issue_events_url":"https://api.github.com/repos/fuweid/pouch/issues/events{/number}","events_url":"https://api.github.com/repos/fuweid/pouch/events","assignees_url":"https://api.github.com/repos/fuweid/pouch/assignees{/user}","branches_url":"https://api.github.com/repos/fuweid/pouch/branches{/branch}","tags_url":"https://api.github.com/repos/fuweid/pouch/tags","blobs_url":"https://api.github.com/repos/fuweid/pouch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fuweid/pouch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fuweid/pouch/git/refs{/sha}","trees_url":"https://api.github.com/repos/fuweid/pouch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fuweid/pouch/statuses/{sha}","languages_url":"https://api.github.com/repos/fuweid/pouch/languages","stargazers_url":"https://api.github.com/repos/fuweid/pouch/stargazers","contributors_url":"https://api.github.com/repos/fuweid/pouch/contributors","subscribers_url":"https://api.github.com/repos/fuweid/pouch/subscribers","subscription_url":"https://api.github.com/repos/fuweid/pouch/subscription","commits_url":"https://api.github.com/repos/fuweid/pouch/commits{/sha}","git_commits_url":"https://api.github.com/repos/fuweid/pouch/git/commits{/sha}","comments_url":"https://api.github.com/repos/fuweid/pouch/comments{/number}","issue_comment_url":"https://api.github.com/repos/fuweid/pouch/issues/comments{/number}","contents_url":"https://api.github.com/repos/fuweid/pouch/contents/{+path}","compare_url":"https://api.github.com/repos/fuweid/pouch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fuweid/pouch/merges","archive_url":"https://api.github.com/repos/fuweid/pouch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fuweid/pouch/downloads","issues_url":"https://api.github.com/repos/fuweid/pouch/issues{/number}","pulls_url":"https://api.github.com/repos/fuweid/pouch/pulls{/number}","milestones_url":"https://api.github.com/repos/fuweid/pouch/milestones{/number}","notifications_url":"https://api.github.com/repos/fuweid/pouch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fuweid/pouch/labels{/name}","releases_url":"https://api.github.com/repos/fuweid/pouch/releases{/id}","deployments_url":"https://api.github.com/repos/fuweid/pouch/deployments","created_at":"2018-08-03T03:23:54Z","updated_at":"2018-11-22T08:11:51Z","pushed_at":"2018-11-27T12:43:30Z","git_url":"git://github.com/fuweid/pouch.git","ssh_url":"git@github.com:fuweid/pouch.git","clone_url":"https://github.com/fuweid/pouch.git","svn_url":"https://github.com/fuweid/pouch","homepage":"https://pouchcontainer.io","size":21053,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"alibaba:master","ref":"master","sha":"f360419cb94d9ee3a25757ba7b64517a2669679e","user":{"login":"alibaba","id":1961952,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5NjE5NTI=","avatar_url":"https://avatars1.githubusercontent.com/u/1961952?v=4","gravatar_id":"","url":"https://api.github.com/users/alibaba","html_url":"https://github.com/alibaba","followers_url":"https://api.github.com/users/alibaba/followers","following_url":"https://api.github.com/users/alibaba/following{/other_user}","gists_url":"https://api.github.com/users/alibaba/gists{/gist_id}","starred_url":"https://api.github.com/users/alibaba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alibaba/subscriptions","organizations_url":"https://api.github.com/users/alibaba/orgs","repos_url":"https://api.github.com/users/alibaba/repos","events_url":"https://api.github.com/users/alibaba/events{/privacy}","received_events_url":"https://api.github.com/users/alibaba/received_events","type":"Organization","site_admin":false},"repo":{"id":102555965,"node_id":"MDEwOlJlcG9zaXRvcnkxMDI1NTU5NjU=","name":"pouch","full_name":"alibaba/pouch","private":false,"owner":{"login":"alibaba","id":1961952,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5NjE5NTI=","avatar_url":"https://avatars1.githubusercontent.com/u/1961952?v=4","gravatar_id":"","url":"https://api.github.com/users/alibaba","html_url":"https://github.com/alibaba","followers_url":"https://api.github.com/users/alibaba/followers","following_url":"https://api.github.com/users/alibaba/following{/other_user}","gists_url":"https://api.github.com/users/alibaba/gists{/gist_id}","starred_url":"https://api.github.com/users/alibaba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alibaba/subscriptions","organizations_url":"https://api.github.com/users/alibaba/orgs","repos_url":"https://api.github.com/users/alibaba/repos","events_url":"https://api.github.com/users/alibaba/events{/privacy}","received_events_url":"https://api.github.com/users/alibaba/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/alibaba/pouch","description":"An Efficient Enterprise-class Rich Container Engine","fork":false,"url":"https://api.github.com/repos/alibaba/pouch","forks_url":"https://api.github.com/repos/alibaba/pouch/forks","keys_url":"https://api.github.com/repos/alibaba/pouch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alibaba/pouch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alibaba/pouch/teams","hooks_url":"https://api.github.com/repos/alibaba/pouch/hooks","issue_events_url":"https://api.github.com/repos/alibaba/pouch/issues/events{/number}","events_url":"https://api.github.com/repos/alibaba/pouch/events","assignees_url":"https://api.github.com/repos/alibaba/pouch/assignees{/user}","branches_url":"https://api.github.com/repos/alibaba/pouch/branches{/branch}","tags_url":"https://api.github.com/repos/alibaba/pouch/tags","blobs_url":"https://api.github.com/repos/alibaba/pouch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alibaba/pouch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alibaba/pouch/git/refs{/sha}","trees_url":"https://api.github.com/repos/alibaba/pouch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alibaba/pouch/statuses/{sha}","languages_url":"https://api.github.com/repos/alibaba/pouch/languages","stargazers_url":"https://api.github.com/repos/alibaba/pouch/stargazers","contributors_url":"https://api.github.com/repos/alibaba/pouch/contributors","subscribers_url":"https://api.github.com/repos/alibaba/pouch/subscribers","subscription_url":"https://api.github.com/repos/alibaba/pouch/subscription","commits_url":"https://api.github.com/repos/alibaba/pouch/commits{/sha}","git_commits_url":"https://api.github.com/repos/alibaba/pouch/git/commits{/sha}","comments_url":"https://api.github.com/repos/alibaba/pouch/comments{/number}","issue_comment_url":"https://api.github.com/repos/alibaba/pouch/issues/comments{/number}","contents_url":"https://api.github.com/repos/alibaba/pouch/contents/{+path}","compare_url":"https://api.github.com/repos/alibaba/pouch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alibaba/pouch/merges","archive_url":"https://api.github.com/repos/alibaba/pouch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alibaba/pouch/downloads","issues_url":"https://api.github.com/repos/alibaba/pouch/issues{/number}","pulls_url":"https://api.github.com/repos/alibaba/pouch/pulls{/number}","milestones_url":"https://api.github.com/repos/alibaba/pouch/milestones{/number}","notifications_url":"https://api.github.com/repos/alibaba/pouch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alibaba/pouch/labels{/name}","releases_url":"https://api.github.com/repos/alibaba/pouch/releases{/id}","deployments_url":"https://api.github.com/repos/alibaba/pouch/deployments","created_at":"2017-09-06T03:01:51Z","updated_at":"2018-11-27T18:22:10Z","pushed_at":"2018-11-27T12:47:31Z","git_url":"git://github.com/alibaba/pouch.git","ssh_url":"git@github.com:alibaba/pouch.git","clone_url":"https://github.com/alibaba/pouch.git","svn_url":"https://github.com/alibaba/pouch","homepage":"https://pouchcontainer.io","size":21032,"stargazers_count":3525,"watchers_count":3525,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":855,"mirror_url":null,"archived":false,"open_issues_count":158,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":855,"open_issues":158,"watchers":3525,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alibaba/pouch/pulls/2510"},"html":{"href":"https://github.com/alibaba/pouch/pull/2510"},"issue":{"href":"https://api.github.com/repos/alibaba/pouch/issues/2510"},"comments":{"href":"https://api.github.com/repos/alibaba/pouch/issues/2510/comments"},"review_comments":{"href":"https://api.github.com/repos/alibaba/pouch/pulls/2510/comments"},"review_comment":{"href":"https://api.github.com/repos/alibaba/pouch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alibaba/pouch/pulls/2510/commits"},"statuses":{"href":"https://api.github.com/repos/alibaba/pouch/statuses/5289b02899f76bf35106c2c857bdb639d4267abb"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"HusterWan"}}