{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/63214910","id":63214910,"diff_hunk":"@@ -17,20 +17,59 @@ limitations under the License.\n package persistentvolume\n \n import (\n+\t\"fmt\"\n \t\"time\"\n \n \t\"k8s.io/kubernetes/pkg/api\"\n \t\"k8s.io/kubernetes/pkg/client/cache\"\n \tclientset \"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset\"\n \t\"k8s.io/kubernetes/pkg/cloudprovider\"\n \t\"k8s.io/kubernetes/pkg/controller/framework\"\n+\t\"k8s.io/kubernetes/pkg/conversion\"\n \t\"k8s.io/kubernetes/pkg/runtime\"\n \t\"k8s.io/kubernetes/pkg/volume\"\n \t\"k8s.io/kubernetes/pkg/watch\"\n \n \t\"github.com/golang/glog\"\n )\n \n+// Design:\n+//\n+// The fundamental key to this design is the bi-directional \"pointer\" between\n+// PersistentVolumes (PVs) and PersistentVolumeClaims (PVCs), which is\n+// represented here as pvc.Spec.VolumeName and pv.Spec.ClaimRef. The bi-directionality\n+// is complicated to manage in a transactionless system, but without it we\n+// can't ensure sane behavior in the face of different forms of trouble.  For\n+// example, a rogue HA controller instance could end up racing and making\n+// multiple bindings that are indistinguishable, resulting in potential data\n+// loss.\n+//\n+// This controller supports pre-bound (by the creator) objects in both\n+// directions: a PVC that wants a specific PV or a PV that is reserved for a\n+// specific PVC.\n+//\n+// The binding is two-step process. PV.Spec.ClaimRef is modified first and\n+// PVC.Spec.VolumeName second. At any point of this transaction, the PV or PVC\n+// can be modified by user or other controller or completelly deleted. Also, two\n+// (or more) controllers may try to bind different volumes to different claims\n+// at the same time. The controller must recover from any conflicts that may\n+// arise from these conditions.","path":"pkg/controller/persistentvolume/persistentvolume_controller.go","position":null,"original_position":40,"commit_id":"182b4ea5834b1fa24cac73643ab97fcde3635cec","original_commit_id":"c572ba8afee569c7372c773e8bafcbac26e2fe9a","user":{"login":"thockin","id":5595220,"avatar_url":"https://avatars.githubusercontent.com/u/5595220?v=3","gravatar_id":"","url":"https://api.github.com/users/thockin","html_url":"https://github.com/thockin","followers_url":"https://api.github.com/users/thockin/followers","following_url":"https://api.github.com/users/thockin/following{/other_user}","gists_url":"https://api.github.com/users/thockin/gists{/gist_id}","starred_url":"https://api.github.com/users/thockin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thockin/subscriptions","organizations_url":"https://api.github.com/users/thockin/orgs","repos_url":"https://api.github.com/users/thockin/repos","events_url":"https://api.github.com/users/thockin/events{/privacy}","received_events_url":"https://api.github.com/users/thockin/received_events","type":"User","site_admin":false},"body":"Well there *is* precedence, sort of.  This controller is all about binding claims.  Claims are the subject, PVs are the object.  A PV might be reserved for claimA, but claimA gets to decide whether it wants that PV (by way of the pre-binding or PV selector (eventually)).  So \"precedence\" is with the PVClaim.  We're happy to leave a PV \"pending\" (I think it is actually \"available\" but only for a claim of a given namespace+name) but we'll try like hell to not leave a claim \"pending\" (hence auto-provisioning).","created_at":"2016-05-13T16:49:42Z","updated_at":"2016-05-13T16:49:42Z","html_url":"https://github.com/kubernetes/kubernetes/pull/24331#discussion_r63214910","pull_request_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/24331","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/63214910"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/24331#discussion_r63214910"},"pull_request":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/24331"}}},"pull_request":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/24331","id":66654802,"html_url":"https://github.com/kubernetes/kubernetes/pull/24331","diff_url":"https://github.com/kubernetes/kubernetes/pull/24331.diff","patch_url":"https://github.com/kubernetes/kubernetes/pull/24331.patch","issue_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/24331","number":24331,"state":"open","locked":false,"title":"Refactor persistent volume controller","user":{"login":"jsafrane","id":1745006,"avatar_url":"https://avatars.githubusercontent.com/u/1745006?v=3","gravatar_id":"","url":"https://api.github.com/users/jsafrane","html_url":"https://github.com/jsafrane","followers_url":"https://api.github.com/users/jsafrane/followers","following_url":"https://api.github.com/users/jsafrane/following{/other_user}","gists_url":"https://api.github.com/users/jsafrane/gists{/gist_id}","starred_url":"https://api.github.com/users/jsafrane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsafrane/subscriptions","organizations_url":"https://api.github.com/users/jsafrane/orgs","repos_url":"https://api.github.com/users/jsafrane/repos","events_url":"https://api.github.com/users/jsafrane/events{/privacy}","received_events_url":"https://api.github.com/users/jsafrane/received_events","type":"User","site_admin":false},"body":"Here is complete persistent controller as designed in https://github.com/pmorie/pv-haxxz/blob/master/controller.go\r\n\r\nIt's feature complete and compatible with current binder/recycler/provisioner. No new features, it *should* be much more stable and predictable.\r\n\r\nTesting\r\n--\r\nThe unit test framework is quite complicated, still it was necessary to reach reasonable coverage (78% in `persistentvolume_controller.go`). The untested part are error cases, which are quite hard to test in reasonable way - sure, I can inject a VersionConflictError on any object update and check the error bubbles up to appropriate places, but the real test would be to run `syncClaim`/`syncVolume` again and check it recovers appropriately from the error in the next periodic sync. That's the hard part.\r\n\r\nOrganization\r\n---\r\nThe PR starts with `rm -rf kubernetes/pkg/controller/persistentvolume`. I find it easier to read when I see only the new controller without old pieces scattered around.\r\n[`types.go` from the old controller is reused to speed up matching a bit, the code looks solid and has 95% unit test coverage].\r\n\r\nI tried to split the PR into smaller patches, let me know what you think.\r\n\r\n~~TODO~~\r\n--\r\n\r\n* ~~Missing: provisioning, recycling~~.\r\n* ~~Fix integration tests~~\r\n* ~~Fix e2e tests~~\r\n\r\n@kubernetes/sig-storage\r\n\r\n<!-- Reviewable:start -->\r\n---\r\nThis change is [<img src=\"http://reviewable.k8s.io/review_button.svg\" height=\"35\" align=\"absmiddle\" alt=\"Reviewable\"/>](http://reviewable.k8s.io/reviews/kubernetes/kubernetes/24331)\r\n<!-- Reviewable:end -->\r\n\r\nFixes #15632\r\n","created_at":"2016-04-15T14:49:19Z","updated_at":"2016-05-13T16:49:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"36da6e83a00aa505d587e4fcd304a24aa2f6921e","assignee":{"login":"thockin","id":5595220,"avatar_url":"https://avatars.githubusercontent.com/u/5595220?v=3","gravatar_id":"","url":"https://api.github.com/users/thockin","html_url":"https://github.com/thockin","followers_url":"https://api.github.com/users/thockin/followers","following_url":"https://api.github.com/users/thockin/following{/other_user}","gists_url":"https://api.github.com/users/thockin/gists{/gist_id}","starred_url":"https://api.github.com/users/thockin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thockin/subscriptions","organizations_url":"https://api.github.com/users/thockin/orgs","repos_url":"https://api.github.com/users/thockin/repos","events_url":"https://api.github.com/users/thockin/events{/privacy}","received_events_url":"https://api.github.com/users/thockin/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/24331/commits","review_comments_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/24331/comments","review_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/24331/comments","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/182b4ea5834b1fa24cac73643ab97fcde3635cec","head":{"label":"jsafrane:devel/refactor-binder","ref":"devel/refactor-binder","sha":"182b4ea5834b1fa24cac73643ab97fcde3635cec","user":{"login":"jsafrane","id":1745006,"avatar_url":"https://avatars.githubusercontent.com/u/1745006?v=3","gravatar_id":"","url":"https://api.github.com/users/jsafrane","html_url":"https://github.com/jsafrane","followers_url":"https://api.github.com/users/jsafrane/followers","following_url":"https://api.github.com/users/jsafrane/following{/other_user}","gists_url":"https://api.github.com/users/jsafrane/gists{/gist_id}","starred_url":"https://api.github.com/users/jsafrane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsafrane/subscriptions","organizations_url":"https://api.github.com/users/jsafrane/orgs","repos_url":"https://api.github.com/users/jsafrane/repos","events_url":"https://api.github.com/users/jsafrane/events{/privacy}","received_events_url":"https://api.github.com/users/jsafrane/received_events","type":"User","site_admin":false},"repo":{"id":33241093,"name":"kubernetes","full_name":"jsafrane/kubernetes","owner":{"login":"jsafrane","id":1745006,"avatar_url":"https://avatars.githubusercontent.com/u/1745006?v=3","gravatar_id":"","url":"https://api.github.com/users/jsafrane","html_url":"https://github.com/jsafrane","followers_url":"https://api.github.com/users/jsafrane/followers","following_url":"https://api.github.com/users/jsafrane/following{/other_user}","gists_url":"https://api.github.com/users/jsafrane/gists{/gist_id}","starred_url":"https://api.github.com/users/jsafrane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsafrane/subscriptions","organizations_url":"https://api.github.com/users/jsafrane/orgs","repos_url":"https://api.github.com/users/jsafrane/repos","events_url":"https://api.github.com/users/jsafrane/events{/privacy}","received_events_url":"https://api.github.com/users/jsafrane/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jsafrane/kubernetes","description":"Container Cluster Manager from Google","fork":true,"url":"https://api.github.com/repos/jsafrane/kubernetes","forks_url":"https://api.github.com/repos/jsafrane/kubernetes/forks","keys_url":"https://api.github.com/repos/jsafrane/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jsafrane/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jsafrane/kubernetes/teams","hooks_url":"https://api.github.com/repos/jsafrane/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/jsafrane/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/jsafrane/kubernetes/events","assignees_url":"https://api.github.com/repos/jsafrane/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/jsafrane/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/jsafrane/kubernetes/tags","blobs_url":"https://api.github.com/repos/jsafrane/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jsafrane/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jsafrane/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/jsafrane/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jsafrane/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/jsafrane/kubernetes/languages","stargazers_url":"https://api.github.com/repos/jsafrane/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/jsafrane/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/jsafrane/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/jsafrane/kubernetes/subscription","commits_url":"https://api.github.com/repos/jsafrane/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/jsafrane/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/jsafrane/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/jsafrane/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/jsafrane/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/jsafrane/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jsafrane/kubernetes/merges","archive_url":"https://api.github.com/repos/jsafrane/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jsafrane/kubernetes/downloads","issues_url":"https://api.github.com/repos/jsafrane/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/jsafrane/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/jsafrane/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/jsafrane/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jsafrane/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/jsafrane/kubernetes/releases{/id}","deployments_url":"https://api.github.com/repos/jsafrane/kubernetes/deployments","created_at":"2015-04-01T10:16:41Z","updated_at":"2016-01-15T18:08:52Z","pushed_at":"2016-05-13T15:40:11Z","git_url":"git://github.com/jsafrane/kubernetes.git","ssh_url":"git@github.com:jsafrane/kubernetes.git","clone_url":"https://github.com/jsafrane/kubernetes.git","svn_url":"https://github.com/jsafrane/kubernetes","homepage":"http://kubernetes.io","size":191556,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kubernetes:master","ref":"master","sha":"bb3f5b1768f3bf6c81914c5bb1d7e846561fdc31","user":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"repo":{"id":20580498,"name":"kubernetes","full_name":"kubernetes/kubernetes","owner":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kubernetes/kubernetes","description":"Container Cluster Manager from Google","fork":false,"url":"https://api.github.com/repos/kubernetes/kubernetes","forks_url":"https://api.github.com/repos/kubernetes/kubernetes/forks","keys_url":"https://api.github.com/repos/kubernetes/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kubernetes/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kubernetes/kubernetes/teams","hooks_url":"https://api.github.com/repos/kubernetes/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/kubernetes/kubernetes/events","assignees_url":"https://api.github.com/repos/kubernetes/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/kubernetes/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/kubernetes/kubernetes/tags","blobs_url":"https://api.github.com/repos/kubernetes/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kubernetes/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kubernetes/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/kubernetes/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/kubernetes/kubernetes/languages","stargazers_url":"https://api.github.com/repos/kubernetes/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/kubernetes/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/kubernetes/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/kubernetes/kubernetes/subscription","commits_url":"https://api.github.com/repos/kubernetes/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/kubernetes/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/kubernetes/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/kubernetes/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kubernetes/kubernetes/merges","archive_url":"https://api.github.com/repos/kubernetes/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kubernetes/kubernetes/downloads","issues_url":"https://api.github.com/repos/kubernetes/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/kubernetes/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/kubernetes/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kubernetes/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/kubernetes/kubernetes/releases{/id}","deployments_url":"https://api.github.com/repos/kubernetes/kubernetes/deployments","created_at":"2014-06-06T22:56:04Z","updated_at":"2016-05-13T16:31:37Z","pushed_at":"2016-05-13T16:30:31Z","git_url":"git://github.com/kubernetes/kubernetes.git","ssh_url":"git@github.com:kubernetes/kubernetes.git","clone_url":"https://github.com/kubernetes/kubernetes.git","svn_url":"https://github.com/kubernetes/kubernetes","homepage":"http://kubernetes.io","size":395178,"stargazers_count":14358,"watchers_count":14358,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":4316,"mirror_url":null,"open_issues_count":3611,"forks":4316,"open_issues":3611,"watchers":14358,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/24331"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/24331"},"issue":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/24331"},"comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/24331/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/24331/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/24331/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/kubernetes/statuses/182b4ea5834b1fa24cac73643ab97fcde3635cec"}}}}