{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/36946553","id":36946553,"diff_hunk":"@@ -0,0 +1,327 @@\n+/*\n+Copyright 2015 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 storage\n+\n+import (\n+\t\"fmt\"\n+\t\"reflect\"\n+\t\"strconv\"\n+\t\"strings\"\n+\t\"sync\"\n+\n+\t\"k8s.io/kubernetes/pkg/client/cache\"\n+\t\"k8s.io/kubernetes/pkg/conversion\"\n+\t\"k8s.io/kubernetes/pkg/runtime\"\n+\t\"k8s.io/kubernetes/pkg/util\"\n+\t\"k8s.io/kubernetes/pkg/watch\"\n+\n+\t\"github.com/golang/glog\"\n+)\n+\n+// CacherConfig contains the configuration for a given Cache.\n+type CacherConfig struct {\n+\t// Maximum size of the history cached in memory.\n+\tCacheCapacity int\n+\n+\t// An underlying storage.Interface.\n+\tStorage Interface\n+\n+\t// The Cache will be caching objects of a given Type and assumes that they\n+\t// are all stored under ResourcePrefix directory in the underlying database.\n+\tType           interface{}\n+\tResourcePrefix string\n+\n+\t// KeyFunc is used to get a key in the underyling storage for a given object.\n+\tKeyFunc func(runtime.Object) (string, error)\n+\n+\t// NewList is a function that creates new empty object storing a list of\n+\t// objects of type Type.\n+\tNewListFunc func() runtime.Object\n+}\n+\n+// Cacher is responsible for serving WATCH and LIST requests for a given\n+// resource from its internal cache and updating its cache in the background\n+// based on the underlying storage contents.\n+type Cacher struct {\n+\tsync.RWMutex\n+\n+\t// Whether Cacher is initialized.\n+\tinitialized sync.WaitGroup\n+\tinitOnce    sync.Once\n+\n+\t// \"sliding window\" of recent changes of objects and the current state.\n+\twatchCache *cache.WatchCache\n+\treflector  *cache.Reflector\n+\n+\t// Registered watchers.\n+\twatcherIdx int\n+\twatchers   map[int]*cacheWatcher\n+\n+\t// Versioner is used to handle resource versions.\n+\tversioner Versioner\n+\n+\t// keyFunc is used to get a key in the underyling storage for a given object.\n+\tkeyFunc func(runtime.Object) (string, error)\n+}\n+\n+func NewCacher(config CacherConfig) *Cacher {\n+\twatchCache := cache.NewWatchCache(config.CacheCapacity)\n+\tlisterWatcher := newCacherListerWatcher(config.Storage, config.ResourcePrefix, config.NewListFunc)\n+\n+\tcacher := &Cacher{\n+\t\tinitialized: sync.WaitGroup{},\n+\t\twatchCache:  watchCache,\n+\t\treflector:   cache.NewReflector(listerWatcher, config.Type, watchCache, 0),\n+\t\twatcherIdx:  0,\n+\t\twatchers:    make(map[int]*cacheWatcher),\n+\t\tversioner:   APIObjectVersioner{},\n+\t\tkeyFunc:     config.KeyFunc,\n+\t}\n+\tcacher.initialized.Add(1)\n+\t// See startCaching method for why explanation on it.\n+\twatchCache.SetOnReplace(func() { cacher.initOnce.Do(func() { cacher.initialized.Done() }); cacher.Unlock() })\n+\twatchCache.SetOnEvent(cacher.processEvent)\n+\n+\tstopCh := util.NeverStop\n+\tgo util.Until(func() { cacher.startCaching(stopCh) }, 0, stopCh)\n+\tcacher.initialized.Wait()\n+\treturn cacher\n+}\n+\n+func (c *Cacher) startCaching(stopChannel <-chan struct{}) {","path":"pkg/storage/cacher.go","position":105,"original_position":105,"commit_id":"b3f427f130fb8825cd7ce2b494e009d4fb82f593","original_commit_id":"b3f427f130fb8825cd7ce2b494e009d4fb82f593","user":{"login":"wojtek-t","id":10743879,"avatar_url":"https://avatars.githubusercontent.com/u/10743879?v=3","gravatar_id":"","url":"https://api.github.com/users/wojtek-t","html_url":"https://github.com/wojtek-t","followers_url":"https://api.github.com/users/wojtek-t/followers","following_url":"https://api.github.com/users/wojtek-t/following{/other_user}","gists_url":"https://api.github.com/users/wojtek-t/gists{/gist_id}","starred_url":"https://api.github.com/users/wojtek-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wojtek-t/subscriptions","organizations_url":"https://api.github.com/users/wojtek-t/orgs","repos_url":"https://api.github.com/users/wojtek-t/repos","events_url":"https://api.github.com/users/wojtek-t/events{/privacy}","received_events_url":"https://api.github.com/users/wojtek-t/received_events","type":"User","site_admin":false},"body":"I exposed StopChannel as part of config.\r\n\r\nHowever, I didn't understand your comment with \"until()\". Do you want me to rename the method or do something else?","created_at":"2015-08-13T07:18:21Z","updated_at":"2015-08-13T07:18:21Z","html_url":"https://github.com/kubernetes/kubernetes/pull/12477#discussion_r36946553","pull_request_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/12477","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/36946553"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/12477#discussion_r36946553"},"pull_request":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/12477"}}},"pull_request":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/12477","id":42020262,"html_url":"https://github.com/kubernetes/kubernetes/pull/12477","diff_url":"https://github.com/kubernetes/kubernetes/pull/12477.diff","patch_url":"https://github.com/kubernetes/kubernetes/pull/12477.patch","issue_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/12477","number":12477,"state":"open","locked":false,"title":"Cacher for watch in apiserver","user":{"login":"wojtek-t","id":10743879,"avatar_url":"https://avatars.githubusercontent.com/u/10743879?v=3","gravatar_id":"","url":"https://api.github.com/users/wojtek-t","html_url":"https://github.com/wojtek-t","followers_url":"https://api.github.com/users/wojtek-t/followers","following_url":"https://api.github.com/users/wojtek-t/following{/other_user}","gists_url":"https://api.github.com/users/wojtek-t/gists{/gist_id}","starred_url":"https://api.github.com/users/wojtek-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wojtek-t/subscriptions","organizations_url":"https://api.github.com/users/wojtek-t/orgs","repos_url":"https://api.github.com/users/wojtek-t/repos","events_url":"https://api.github.com/users/wojtek-t/events{/privacy}","received_events_url":"https://api.github.com/users/wojtek-t/received_events","type":"User","site_admin":false},"body":"Ref #10475\r\n\r\nCacher implements watch and list at the apiserver level.\r\n\r\n@lavalamp @davidopp @nikhiljindal @bprashanth @gmarek @fgrzadkowski \r\n@timothysc @smarterclayton ","created_at":"2015-08-10T13:35:07Z","updated_at":"2015-08-13T07:18:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"14b429dcce32a13fabca880b4c0a916ed53f7b66","assignee":{"login":"bprashanth","id":10927820,"avatar_url":"https://avatars.githubusercontent.com/u/10927820?v=3","gravatar_id":"","url":"https://api.github.com/users/bprashanth","html_url":"https://github.com/bprashanth","followers_url":"https://api.github.com/users/bprashanth/followers","following_url":"https://api.github.com/users/bprashanth/following{/other_user}","gists_url":"https://api.github.com/users/bprashanth/gists{/gist_id}","starred_url":"https://api.github.com/users/bprashanth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bprashanth/subscriptions","organizations_url":"https://api.github.com/users/bprashanth/orgs","repos_url":"https://api.github.com/users/bprashanth/repos","events_url":"https://api.github.com/users/bprashanth/events{/privacy}","received_events_url":"https://api.github.com/users/bprashanth/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/12477/commits","review_comments_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/12477/comments","review_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/12477/comments","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/b3f427f130fb8825cd7ce2b494e009d4fb82f593","head":{"label":"wojtek-t:create_cacher","ref":"create_cacher","sha":"b3f427f130fb8825cd7ce2b494e009d4fb82f593","user":{"login":"wojtek-t","id":10743879,"avatar_url":"https://avatars.githubusercontent.com/u/10743879?v=3","gravatar_id":"","url":"https://api.github.com/users/wojtek-t","html_url":"https://github.com/wojtek-t","followers_url":"https://api.github.com/users/wojtek-t/followers","following_url":"https://api.github.com/users/wojtek-t/following{/other_user}","gists_url":"https://api.github.com/users/wojtek-t/gists{/gist_id}","starred_url":"https://api.github.com/users/wojtek-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wojtek-t/subscriptions","organizations_url":"https://api.github.com/users/wojtek-t/orgs","repos_url":"https://api.github.com/users/wojtek-t/repos","events_url":"https://api.github.com/users/wojtek-t/events{/privacy}","received_events_url":"https://api.github.com/users/wojtek-t/received_events","type":"User","site_admin":false},"repo":{"id":30216785,"name":"kubernetes","full_name":"wojtek-t/kubernetes","owner":{"login":"wojtek-t","id":10743879,"avatar_url":"https://avatars.githubusercontent.com/u/10743879?v=3","gravatar_id":"","url":"https://api.github.com/users/wojtek-t","html_url":"https://github.com/wojtek-t","followers_url":"https://api.github.com/users/wojtek-t/followers","following_url":"https://api.github.com/users/wojtek-t/following{/other_user}","gists_url":"https://api.github.com/users/wojtek-t/gists{/gist_id}","starred_url":"https://api.github.com/users/wojtek-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wojtek-t/subscriptions","organizations_url":"https://api.github.com/users/wojtek-t/orgs","repos_url":"https://api.github.com/users/wojtek-t/repos","events_url":"https://api.github.com/users/wojtek-t/events{/privacy}","received_events_url":"https://api.github.com/users/wojtek-t/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wojtek-t/kubernetes","description":"Container Cluster Manager","fork":true,"url":"https://api.github.com/repos/wojtek-t/kubernetes","forks_url":"https://api.github.com/repos/wojtek-t/kubernetes/forks","keys_url":"https://api.github.com/repos/wojtek-t/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wojtek-t/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wojtek-t/kubernetes/teams","hooks_url":"https://api.github.com/repos/wojtek-t/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/wojtek-t/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/wojtek-t/kubernetes/events","assignees_url":"https://api.github.com/repos/wojtek-t/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/wojtek-t/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/wojtek-t/kubernetes/tags","blobs_url":"https://api.github.com/repos/wojtek-t/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wojtek-t/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wojtek-t/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/wojtek-t/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wojtek-t/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/wojtek-t/kubernetes/languages","stargazers_url":"https://api.github.com/repos/wojtek-t/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/wojtek-t/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/wojtek-t/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/wojtek-t/kubernetes/subscription","commits_url":"https://api.github.com/repos/wojtek-t/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/wojtek-t/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/wojtek-t/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/wojtek-t/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/wojtek-t/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/wojtek-t/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wojtek-t/kubernetes/merges","archive_url":"https://api.github.com/repos/wojtek-t/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wojtek-t/kubernetes/downloads","issues_url":"https://api.github.com/repos/wojtek-t/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/wojtek-t/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/wojtek-t/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/wojtek-t/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wojtek-t/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/wojtek-t/kubernetes/releases{/id}","created_at":"2015-02-03T00:37:55Z","updated_at":"2015-04-30T12:14:58Z","pushed_at":"2015-08-12T12:58:04Z","git_url":"git://github.com/wojtek-t/kubernetes.git","ssh_url":"git@github.com:wojtek-t/kubernetes.git","clone_url":"https://github.com/wojtek-t/kubernetes.git","svn_url":"https://github.com/wojtek-t/kubernetes","homepage":"http://kubernetes.io","size":98711,"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":"0ded91c52177c009e7a4d0f00386ae826f854625","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}","created_at":"2014-06-06T22:56:04Z","updated_at":"2015-08-13T07:15:45Z","pushed_at":"2015-08-13T06:35:03Z","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":345032,"stargazers_count":9673,"watchers_count":9673,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2313,"mirror_url":null,"open_issues_count":1730,"forks":2313,"open_issues":1730,"watchers":9673,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/12477"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/12477"},"issue":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/12477"},"comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/12477/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/12477/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/12477/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/kubernetes/statuses/b3f427f130fb8825cd7ce2b494e009d4fb82f593"}}}}