{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb-operator/pulls/comments/237377767","pull_request_review_id":179658216,"id":237377767,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNzM3Nzc2Nw==","diff_hunk":"@@ -0,0 +1,109 @@\n+// Copyright 2018 PingCAP, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+package member\n+\n+import (\n+\t\"github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1\"\n+\t\"github.com/pingcap/tidb-operator/pkg/controller\"\n+\t\"github.com/pingcap/tidb-operator/pkg/label\"\n+\t\"k8s.io/apimachinery/pkg/api/errors\"\n+\tcorelisters \"k8s.io/client-go/listers/core/v1\"\n+)\n+\n+const (\n+\tskipReasonOrphanPodsCleanerIsNotPDOrTiKV  = \"orphan pods cleaner: member type is not pd or tikv\"\n+\tskipReasonOrphanPodsCleanerPVCNameIsEmpty = \"orphan pods cleaner: pvcName is empty\"\n+\tskipReasonOrphanPodsCleanerPVCIsFound     = \"orphan pods cleaner: pvc is found\"\n+)\n+\n+// OrphanPodsCleaner implements the logic for cleaning the orphan pods(has no pvc)\n+type OrphanPodsCleaner interface {\n+\tClean(*v1alpha1.TidbCluster) (map[string]string, error)\n+}\n+\n+type orphanPodsCleaner struct {\n+\tpodLister  corelisters.PodLister\n+\tpodControl controller.PodControlInterface\n+\tpvcLister  corelisters.PersistentVolumeClaimLister\n+}\n+\n+// NewOrphanPodsCleaner returns a OrphanPodsCleaner\n+func NewOrphanPodsCleaner(podLister corelisters.PodLister,\n+\tpodControl controller.PodControlInterface,\n+\tpvcLister corelisters.PersistentVolumeClaimLister) OrphanPodsCleaner {\n+\treturn &orphanPodsCleaner{podLister, podControl, pvcLister}\n+}\n+\n+func (opc *orphanPodsCleaner) Clean(tc *v1alpha1.TidbCluster) (map[string]string, error) {\n+\tns := tc.GetNamespace()\n+\t// for unit test\n+\tskipReason := map[string]string{}\n+\n+\tselector, err := label.New().Instance(tc.GetLabels()[label.InstanceLabelKey]).Selector()\n+\tif err != nil {\n+\t\treturn skipReason, err\n+\t}\n+\tpods, err := opc.podLister.Pods(ns).List(selector)\n+\tif err != nil {\n+\t\treturn skipReason, err\n+\t}\n+\n+\tfor _, pod := range pods {\n+\t\tpodName := pod.GetName()\n+\t\tl := label.Label(pod.Labels)\n+\t\tif !(l.IsPD() || l.IsTiKV()) {\n+\t\t\tskipReason[podName] = skipReasonOrphanPodsCleanerIsNotPDOrTiKV\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\tvar pvcName string\n+\t\tfor _, vol := range pod.Spec.Volumes {\n+\t\t\tif vol.PersistentVolumeClaim != nil {\n+\t\t\t\tpvcName = vol.PersistentVolumeClaim.ClaimName\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t}\n+\t\tif pvcName == \"\" {\n+\t\t\tskipReason[podName] = skipReasonOrphanPodsCleanerPVCNameIsEmpty\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\t_, err := opc.pvcLister.PersistentVolumeClaims(ns).Get(pvcName)\n+\t\tif err == nil {\n+\t\t\tskipReason[podName] = skipReasonOrphanPodsCleanerPVCIsFound\n+\t\t\tcontinue\n+\t\t}\n+\t\tif !errors.IsNotFound(err) {\n+\t\t\treturn skipReason, err","path":"pkg/manager/member/orphan_pods_cleaner.go","position":88,"original_position":88,"commit_id":"2553379ef2b03a31b5f8c17a4e3baffa207edd96","original_commit_id":"2553379ef2b03a31b5f8c17a4e3baffa207edd96","user":{"login":"weekface","id":9758,"node_id":"MDQ6VXNlcjk3NTg=","avatar_url":"https://avatars2.githubusercontent.com/u/9758?v=4","gravatar_id":"","url":"https://api.github.com/users/weekface","html_url":"https://github.com/weekface","followers_url":"https://api.github.com/users/weekface/followers","following_url":"https://api.github.com/users/weekface/following{/other_user}","gists_url":"https://api.github.com/users/weekface/gists{/gist_id}","starred_url":"https://api.github.com/users/weekface/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weekface/subscriptions","organizations_url":"https://api.github.com/users/weekface/orgs","repos_url":"https://api.github.com/users/weekface/repos","events_url":"https://api.github.com/users/weekface/events{/privacy}","received_events_url":"https://api.github.com/users/weekface/received_events","type":"User","site_admin":false},"body":"If there is an error, return directly.\r\nIs this reasonable?","created_at":"2018-11-29T07:37:09Z","updated_at":"2018-11-29T07:37:10Z","html_url":"https://github.com/pingcap/tidb-operator/pull/201#discussion_r237377767","pull_request_url":"https://api.github.com/repos/pingcap/tidb-operator/pulls/201","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb-operator/pulls/comments/237377767"},"html":{"href":"https://github.com/pingcap/tidb-operator/pull/201#discussion_r237377767"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb-operator/pulls/201"}},"in_reply_to_id":237374623},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb-operator/pulls/201","id":234188383,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM0MTg4Mzgz","html_url":"https://github.com/pingcap/tidb-operator/pull/201","diff_url":"https://github.com/pingcap/tidb-operator/pull/201.diff","patch_url":"https://github.com/pingcap/tidb-operator/pull/201.patch","issue_url":"https://api.github.com/repos/pingcap/tidb-operator/issues/201","number":201,"state":"open","locked":false,"title":"Orphan pods cleaner","user":{"login":"weekface","id":9758,"node_id":"MDQ6VXNlcjk3NTg=","avatar_url":"https://avatars2.githubusercontent.com/u/9758?v=4","gravatar_id":"","url":"https://api.github.com/users/weekface","html_url":"https://github.com/weekface","followers_url":"https://api.github.com/users/weekface/followers","following_url":"https://api.github.com/users/weekface/following{/other_user}","gists_url":"https://api.github.com/users/weekface/gists{/gist_id}","starred_url":"https://api.github.com/users/weekface/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weekface/subscriptions","organizations_url":"https://api.github.com/users/weekface/orgs","repos_url":"https://api.github.com/users/weekface/repos","events_url":"https://api.github.com/users/weekface/events{/privacy}","received_events_url":"https://api.github.com/users/weekface/received_events","type":"User","site_admin":false},"body":"- add orphan pods cleaner: delete the pod if its pvc is not exist\r\n- add unit tests to orphan pods cleaner\r\n- only delete one defer deleting pvc when scale out\r\n- e2e: set upgrade timeout duration to 10 minutes(upgrading all 5 tikvs may need more than 5 minutes)\r\n\r\n@tennix @xiaojingchen PTAL","created_at":"2018-11-28T08:33:55Z","updated_at":"2018-11-29T07:37:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"034541a9ca3900cd478413c5bca6402880072502","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb-operator/pulls/201/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb-operator/pulls/201/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb-operator/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb-operator/issues/201/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb-operator/statuses/2553379ef2b03a31b5f8c17a4e3baffa207edd96","head":{"label":"weekface:orphan-pods-cleaner","ref":"orphan-pods-cleaner","sha":"2553379ef2b03a31b5f8c17a4e3baffa207edd96","user":{"login":"weekface","id":9758,"node_id":"MDQ6VXNlcjk3NTg=","avatar_url":"https://avatars2.githubusercontent.com/u/9758?v=4","gravatar_id":"","url":"https://api.github.com/users/weekface","html_url":"https://github.com/weekface","followers_url":"https://api.github.com/users/weekface/followers","following_url":"https://api.github.com/users/weekface/following{/other_user}","gists_url":"https://api.github.com/users/weekface/gists{/gist_id}","starred_url":"https://api.github.com/users/weekface/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weekface/subscriptions","organizations_url":"https://api.github.com/users/weekface/orgs","repos_url":"https://api.github.com/users/weekface/repos","events_url":"https://api.github.com/users/weekface/events{/privacy}","received_events_url":"https://api.github.com/users/weekface/received_events","type":"User","site_admin":false},"repo":{"id":144795399,"node_id":"MDEwOlJlcG9zaXRvcnkxNDQ3OTUzOTk=","name":"tidb-operator","full_name":"weekface/tidb-operator","private":false,"owner":{"login":"weekface","id":9758,"node_id":"MDQ6VXNlcjk3NTg=","avatar_url":"https://avatars2.githubusercontent.com/u/9758?v=4","gravatar_id":"","url":"https://api.github.com/users/weekface","html_url":"https://github.com/weekface","followers_url":"https://api.github.com/users/weekface/followers","following_url":"https://api.github.com/users/weekface/following{/other_user}","gists_url":"https://api.github.com/users/weekface/gists{/gist_id}","starred_url":"https://api.github.com/users/weekface/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weekface/subscriptions","organizations_url":"https://api.github.com/users/weekface/orgs","repos_url":"https://api.github.com/users/weekface/repos","events_url":"https://api.github.com/users/weekface/events{/privacy}","received_events_url":"https://api.github.com/users/weekface/received_events","type":"User","site_admin":false},"html_url":"https://github.com/weekface/tidb-operator","description":"TiDB operator creates and manages TiDB clusters running in Kubernetes","fork":true,"url":"https://api.github.com/repos/weekface/tidb-operator","forks_url":"https://api.github.com/repos/weekface/tidb-operator/forks","keys_url":"https://api.github.com/repos/weekface/tidb-operator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/weekface/tidb-operator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/weekface/tidb-operator/teams","hooks_url":"https://api.github.com/repos/weekface/tidb-operator/hooks","issue_events_url":"https://api.github.com/repos/weekface/tidb-operator/issues/events{/number}","events_url":"https://api.github.com/repos/weekface/tidb-operator/events","assignees_url":"https://api.github.com/repos/weekface/tidb-operator/assignees{/user}","branches_url":"https://api.github.com/repos/weekface/tidb-operator/branches{/branch}","tags_url":"https://api.github.com/repos/weekface/tidb-operator/tags","blobs_url":"https://api.github.com/repos/weekface/tidb-operator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/weekface/tidb-operator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/weekface/tidb-operator/git/refs{/sha}","trees_url":"https://api.github.com/repos/weekface/tidb-operator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/weekface/tidb-operator/statuses/{sha}","languages_url":"https://api.github.com/repos/weekface/tidb-operator/languages","stargazers_url":"https://api.github.com/repos/weekface/tidb-operator/stargazers","contributors_url":"https://api.github.com/repos/weekface/tidb-operator/contributors","subscribers_url":"https://api.github.com/repos/weekface/tidb-operator/subscribers","subscription_url":"https://api.github.com/repos/weekface/tidb-operator/subscription","commits_url":"https://api.github.com/repos/weekface/tidb-operator/commits{/sha}","git_commits_url":"https://api.github.com/repos/weekface/tidb-operator/git/commits{/sha}","comments_url":"https://api.github.com/repos/weekface/tidb-operator/comments{/number}","issue_comment_url":"https://api.github.com/repos/weekface/tidb-operator/issues/comments{/number}","contents_url":"https://api.github.com/repos/weekface/tidb-operator/contents/{+path}","compare_url":"https://api.github.com/repos/weekface/tidb-operator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/weekface/tidb-operator/merges","archive_url":"https://api.github.com/repos/weekface/tidb-operator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/weekface/tidb-operator/downloads","issues_url":"https://api.github.com/repos/weekface/tidb-operator/issues{/number}","pulls_url":"https://api.github.com/repos/weekface/tidb-operator/pulls{/number}","milestones_url":"https://api.github.com/repos/weekface/tidb-operator/milestones{/number}","notifications_url":"https://api.github.com/repos/weekface/tidb-operator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/weekface/tidb-operator/labels{/name}","releases_url":"https://api.github.com/repos/weekface/tidb-operator/releases{/id}","deployments_url":"https://api.github.com/repos/weekface/tidb-operator/deployments","created_at":"2018-08-15T02:25:54Z","updated_at":"2018-11-28T07:55:20Z","pushed_at":"2018-11-28T08:24:24Z","git_url":"git://github.com/weekface/tidb-operator.git","ssh_url":"git@github.com:weekface/tidb-operator.git","clone_url":"https://github.com/weekface/tidb-operator.git","svn_url":"https://github.com/weekface/tidb-operator","homepage":"","size":49038,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"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":1,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"acf99fd04a3741e56b5e76cc073825e844fe85f0","user":{"login":"pingcap","id":11855343,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExODU1MzQz","avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":143867478,"node_id":"MDEwOlJlcG9zaXRvcnkxNDM4Njc0Nzg=","name":"tidb-operator","full_name":"pingcap/tidb-operator","private":false,"owner":{"login":"pingcap","id":11855343,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExODU1MzQz","avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/pingcap/tidb-operator","description":"TiDB operator creates and manages TiDB clusters running in Kubernetes","fork":false,"url":"https://api.github.com/repos/pingcap/tidb-operator","forks_url":"https://api.github.com/repos/pingcap/tidb-operator/forks","keys_url":"https://api.github.com/repos/pingcap/tidb-operator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb-operator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb-operator/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb-operator/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb-operator/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb-operator/events","assignees_url":"https://api.github.com/repos/pingcap/tidb-operator/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb-operator/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb-operator/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb-operator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb-operator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb-operator/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb-operator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb-operator/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb-operator/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb-operator/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb-operator/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb-operator/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb-operator/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb-operator/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb-operator/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb-operator/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb-operator/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb-operator/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb-operator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb-operator/merges","archive_url":"https://api.github.com/repos/pingcap/tidb-operator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb-operator/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb-operator/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb-operator/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb-operator/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb-operator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb-operator/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb-operator/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tidb-operator/deployments","created_at":"2018-08-07T12:04:33Z","updated_at":"2018-11-28T07:14:11Z","pushed_at":"2018-11-29T03:35:24Z","git_url":"git://github.com/pingcap/tidb-operator.git","ssh_url":"git@github.com:pingcap/tidb-operator.git","clone_url":"https://github.com/pingcap/tidb-operator.git","svn_url":"https://github.com/pingcap/tidb-operator","homepage":"","size":48974,"stargazers_count":191,"watchers_count":191,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":44,"mirror_url":null,"archived":false,"open_issues_count":20,"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":44,"open_issues":20,"watchers":191,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb-operator/pulls/201"},"html":{"href":"https://github.com/pingcap/tidb-operator/pull/201"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb-operator/issues/201"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb-operator/issues/201/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb-operator/pulls/201/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb-operator/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb-operator/pulls/201/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb-operator/statuses/2553379ef2b03a31b5f8c17a4e3baffa207edd96"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"weekface"}}