{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/62288244","id":62288244,"diff_hunk":"@@ -0,0 +1,979 @@\n+/*\n+Copyright 2016 The Kubernetes Authors All rights reserved.\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+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+See the License for the specific language governing permissions and\n+limitations under the License.\n+*/\n+\n+package persistentvolume\n+\n+import (\n+\t\"fmt\"\n+\t\"reflect\"\n+\t\"strconv\"\n+\t\"strings\"\n+\t\"sync\"\n+\t\"sync/atomic\"\n+\t\"testing\"\n+\t\"time\"\n+\n+\t\"github.com/golang/glog\"\n+\n+\t\"k8s.io/kubernetes/pkg/api\"\n+\t\"k8s.io/kubernetes/pkg/api/resource\"\n+\t\"k8s.io/kubernetes/pkg/api/testapi\"\n+\t\"k8s.io/kubernetes/pkg/client/cache\"\n+\tclientset \"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset\"\n+\t\"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake\"\n+\t\"k8s.io/kubernetes/pkg/client/record\"\n+\t\"k8s.io/kubernetes/pkg/client/testing/core\"\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/types\"\n+\t\"k8s.io/kubernetes/pkg/util/diff\"\n+\tvol \"k8s.io/kubernetes/pkg/volume\"\n+)\n+\n+// This is a unit test framework for persistent volume controller.\n+// It fills the controller with test claims/volumes and can simulate these\n+// scenarios:\n+// 1) Call syncClaim/syncVolume once.\n+// 2) Call syncClaim/syncVolume several times (both simulating \"claim/volume\n+//    modified\" events and periodic sync), until the controller settles down and\n+//    does not modify anything.\n+// 3) Simulate almost real API server/etcd and call add/update/delete\n+//    volume/claim.\n+// In all these scenarions, when the test finishes, the framework can compare\n+// resulting claims/volumes with list of expected claims/volumes and report\n+// differences.\n+\n+// controllerTest contains single controller test input.\n+// Each test has initial set of volumes and claims that are filled into the\n+// controller before the test starts. The test then contains a reference to\n+// function to call as actual test. Available functions are:\n+//   - testSyncClaim - calls syncClaim on the first claim in initialClaims.\n+//   - testSyncClaimError - calls syncClaim on the first claim in initialClaims\n+//                          and expects an error to be returned.\n+//   - testSyncVolume - calls syncVolume on the first volume in initialVolumes.\n+//   - any custom function for specialized tests.\n+// The test then contains list of volumes/claims that are expected at the end\n+// of the test and list of generated events.\n+type controllerTest struct {\n+\t// Name of the test, for logging\n+\tname string\n+\t// Initial content of controller volume cache.\n+\tinitialVolumes []*api.PersistentVolume\n+\t// Expected content of controller volume cache at the end of the test.\n+\texpectedVolumes []*api.PersistentVolume\n+\t// Initial content of controller claim cache.\n+\tinitialClaims []*api.PersistentVolumeClaim\n+\t// Expected content of controller claim cache at the end of the test.\n+\texpectedClaims []*api.PersistentVolumeClaim\n+\t// Expected events - any event with prefix will pass, we don't check full\n+\t// event message.\n+\texpectedEvents []string\n+\t// Errors to produce on matching action\n+\terrors []reactorError\n+\t// Function to call as the test.\n+\ttest testCall\n+}\n+\n+type testCall func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error\n+\n+const testNamespace = \"default\"\n+const versionConflictError = \"VersionError\"\n+const mockPluginName = \"MockVolumePlugin\"\n+\n+var noevents = []string{}\n+var noerrors = []reactorError{}\n+\n+// volumeReactor is a core.Reactor that simulates etcd and API server. It\n+// stores:\n+// - Latest version of claims volumes saved by the controller.\n+// - Queue of all saves (to simulate \"volume/claim updated\" events). This queue\n+//   contains all itermediate state of an object - e.g. a claim.VolumeName\n+//   is updated first and claim.Phase second. This queue will then contain both\n+//   updates as separate entries.\n+// - Nr. of changes since the last call to volumeReactor.syncAll().","path":"pkg/controller/persistentvolume/persistentvolume_framework_test.go","position":107,"original_position":107,"commit_id":"b5702412edba971dcf6f02e39182c805a3dac739","original_commit_id":"b5702412edba971dcf6f02e39182c805a3dac739","user":{"login":"pmorie","id":366488,"avatar_url":"https://avatars.githubusercontent.com/u/366488?v=3","gravatar_id":"","url":"https://api.github.com/users/pmorie","html_url":"https://github.com/pmorie","followers_url":"https://api.github.com/users/pmorie/followers","following_url":"https://api.github.com/users/pmorie/following{/other_user}","gists_url":"https://api.github.com/users/pmorie/gists{/gist_id}","starred_url":"https://api.github.com/users/pmorie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmorie/subscriptions","organizations_url":"https://api.github.com/users/pmorie/orgs","repos_url":"https://api.github.com/users/pmorie/repos","events_url":"https://api.github.com/users/pmorie/events{/privacy}","received_events_url":"https://api.github.com/users/pmorie/received_events","type":"User","site_admin":false},"body":"number","created_at":"2016-05-06T04:43:08Z","updated_at":"2016-05-06T04:43:08Z","html_url":"https://github.com/kubernetes/kubernetes/pull/24331#discussion_r62288244","pull_request_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/24331","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/62288244"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/24331#discussion_r62288244"},"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 ","created_at":"2016-04-15T14:49:19Z","updated_at":"2016-05-06T04:43:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cf4568948970998fa503667b1d9b98f1bc8874e1","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/b5702412edba971dcf6f02e39182c805a3dac739","head":{"label":"jsafrane:devel/refactor-binder","ref":"devel/refactor-binder","sha":"b5702412edba971dcf6f02e39182c805a3dac739","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-05T12:11:57Z","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":187435,"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":"c79c5864e767e6b973f5866f4bd8f0b48866aa18","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-06T03:55:58Z","pushed_at":"2016-05-06T04:40:32Z","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":391259,"stargazers_count":14234,"watchers_count":14234,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":4256,"mirror_url":null,"open_issues_count":3611,"forks":4256,"open_issues":3611,"watchers":14234,"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/b5702412edba971dcf6f02e39182c805a3dac739"}}}}