{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/origin/pulls/comments/55035669","id":55035669,"diff_hunk":"@@ -0,0 +1,131 @@\n+package clientcmd\n+\n+import (\n+\t\"errors\"\n+\t\"io/ioutil\"\n+\t\"os\"\n+\t\"path/filepath\"\n+\t\"time\"\n+\n+\tkapi \"k8s.io/kubernetes/pkg/api\"\n+\t\"k8s.io/kubernetes/pkg/api/unversioned\"\n+\tkclient \"k8s.io/kubernetes/pkg/client/unversioned\"\n+\t\"k8s.io/kubernetes/pkg/runtime\"\n+)\n+\n+// CachedDiscoveryClient implements the functions that dicovery server-supported API groups,\n+// versions and resources.\n+type CachedDiscoveryClient struct {\n+\tkclient.DiscoveryInterface\n+\n+\t// cacheDirectory is the directory where discovery docs are held.  It must be unique per host:port combination to work well.\n+\tcacheDirectory string\n+\n+\t// ttl is how long the cache should be considered valid\n+\tttl time.Duration\n+}\n+\n+// ServerResourcesForGroupVersion returns the supported resources for a group and version.\n+func (d *CachedDiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (*unversioned.APIResourceList, error) {\n+\tfilename := filepath.Join(d.cacheDirectory, groupVersion, \"serverresources.json\")\n+\tcachedBytes, err := d.getCachedFile(filename)\n+\t// don't fail on errors, we either don't have a file or won't be able to run the cached check. Either way we can fallback.\n+\tif err == nil {\n+\t\tcachedResources := &unversioned.APIResourceList{}\n+\t\tif err := runtime.DecodeInto(kapi.Codecs.UniversalDecoder(), cachedBytes, cachedResources); err == nil {\n+\t\t\treturn cachedResources, nil\n+\t\t}\n+\n+\t}\n+\n+\tliveResources, err := d.DiscoveryInterface.ServerResourcesForGroupVersion(groupVersion)\n+\tif err != nil {\n+\t\treturn liveResources, err\n+\t}\n+\n+\td.writeCachedFile(filename, liveResources)\n+\n+\treturn liveResources, nil\n+}\n+\n+// ServerResources returns the supported resources for all groups and versions.\n+func (d *CachedDiscoveryClient) ServerResources() (map[string]*unversioned.APIResourceList, error) {\n+\tapiGroups, err := d.ServerGroups()\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tgroupVersions := kclient.ExtractGroupVersions(apiGroups)\n+\tresult := map[string]*unversioned.APIResourceList{}\n+\tfor _, groupVersion := range groupVersions {\n+\t\tresources, err := d.ServerResourcesForGroupVersion(groupVersion)\n+\t\tif err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\tresult[groupVersion] = resources\n+\t}\n+\treturn result, nil\n+}\n+\n+func (d *CachedDiscoveryClient) ServerGroups() (*unversioned.APIGroupList, error) {\n+\tfilename := filepath.Join(d.cacheDirectory, \"servergroups.json\")\n+\tcachedBytes, err := d.getCachedFile(filename)\n+\t// don't fail on errors, we either don't have a file or won't be able to run the cached check. Either way we can fallback.\n+\tif err == nil {\n+\t\tcachedGroups := &unversioned.APIGroupList{}\n+\t\tif err := runtime.DecodeInto(kapi.Codecs.UniversalDecoder(), cachedBytes, cachedGroups); err == nil {\n+\t\t\treturn cachedGroups, nil\n+\t\t}\n+\n+\t}\n+\n+\tliveGroups, err := d.DiscoveryInterface.ServerGroups()\n+\tif err != nil {\n+\t\treturn liveGroups, err\n+\t}\n+\n+\td.writeCachedFile(filename, liveGroups)\n+\n+\treturn liveGroups, nil\n+}\n+\n+func (d *CachedDiscoveryClient) getCachedFile(filename string) ([]byte, error) {\n+\t// don't fail on errors, we either don't have a file or won't be able to run the cached check. Either way we can fallback.\n+\tfile, err := os.Open(filename)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tfileInfo, err := file.Stat()\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tif time.Now().After(fileInfo.ModTime().Add(d.ttl)) {\n+\t\treturn nil, errors.New(\"cache expired\")\n+\t}\n+\n+\t// the cache is present and its valid.  Try to read and use it.\n+\tcachedBytes, err := ioutil.ReadAll(file)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\treturn cachedBytes, nil\n+}\n+\n+func (d *CachedDiscoveryClient) writeCachedFile(filename string, obj runtime.Object) error {\n+\tif err := os.MkdirAll(filepath.Dir(filename), 0755); err != nil {\n+\t\treturn err\n+\t}\n+\n+\tbytes, err := runtime.Encode(kapi.Codecs.LegacyCodec(), obj)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\treturn ioutil.WriteFile(filename, bytes, 0755)","path":"pkg/cmd/util/clientcmd/cached_discovery.go","position":128,"original_position":125,"commit_id":"d1f8c14cde3726cb0faf5e4828ba119931fab7e9","original_commit_id":"6fd750b2da198d94d9ca30bbe205c4c68b00079e","user":{"login":"fabianofranz","id":158611,"avatar_url":"https://avatars.githubusercontent.com/u/158611?v=3","gravatar_id":"","url":"https://api.github.com/users/fabianofranz","html_url":"https://github.com/fabianofranz","followers_url":"https://api.github.com/users/fabianofranz/followers","following_url":"https://api.github.com/users/fabianofranz/following{/other_user}","gists_url":"https://api.github.com/users/fabianofranz/gists{/gist_id}","starred_url":"https://api.github.com/users/fabianofranz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabianofranz/subscriptions","organizations_url":"https://api.github.com/users/fabianofranz/orgs","repos_url":"https://api.github.com/users/fabianofranz/repos","events_url":"https://api.github.com/users/fabianofranz/events{/privacy}","received_events_url":"https://api.github.com/users/fabianofranz/received_events","type":"User","site_admin":false},"body":":+1:","created_at":"2016-03-04T14:29:46Z","updated_at":"2016-03-04T14:29:46Z","html_url":"https://github.com/openshift/origin/pull/7661#discussion_r55035669","pull_request_url":"https://api.github.com/repos/openshift/origin/pulls/7661","_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments/55035669"},"html":{"href":"https://github.com/openshift/origin/pull/7661#discussion_r55035669"},"pull_request":{"href":"https://api.github.com/repos/openshift/origin/pulls/7661"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/origin/pulls/7661","id":60897855,"html_url":"https://github.com/openshift/origin/pull/7661","diff_url":"https://github.com/openshift/origin/pull/7661.diff","patch_url":"https://github.com/openshift/origin/pull/7661.patch","issue_url":"https://api.github.com/repos/openshift/origin/issues/7661","number":7661,"state":"open","locked":false,"title":"make all alias correctly","user":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"body":"This updates the `all` alias to actually mean what we want with respect to available resources.  There is refactoring needed upstream for purity, but we can delay that .  This doesn't change behavior of clients against old servers, so our client looks just as ugly if you're hitting an old atomic server.  This doesn't use a cache, but you can see where to plug it.\r\n\r\n@smarterclayton @fabianofranz @liggitt \r\n\r\nAlternative to https://github.com/openshift/origin/pull/7634","created_at":"2016-02-26T20:18:22Z","updated_at":"2016-03-04T14:29:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"72dae84f347c141fe0bf80fa0efa8fdbb8b3006e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/origin/pulls/7661/commits","review_comments_url":"https://api.github.com/repos/openshift/origin/pulls/7661/comments","review_comment_url":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/origin/issues/7661/comments","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/d1f8c14cde3726cb0faf5e4828ba119931fab7e9","head":{"label":"deads2k:fix-all","ref":"fix-all","sha":"d1f8c14cde3726cb0faf5e4828ba119931fab7e9","user":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"repo":{"id":24424126,"name":"origin","full_name":"deads2k/origin","owner":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/deads2k/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":true,"url":"https://api.github.com/repos/deads2k/origin","forks_url":"https://api.github.com/repos/deads2k/origin/forks","keys_url":"https://api.github.com/repos/deads2k/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/deads2k/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/deads2k/origin/teams","hooks_url":"https://api.github.com/repos/deads2k/origin/hooks","issue_events_url":"https://api.github.com/repos/deads2k/origin/issues/events{/number}","events_url":"https://api.github.com/repos/deads2k/origin/events","assignees_url":"https://api.github.com/repos/deads2k/origin/assignees{/user}","branches_url":"https://api.github.com/repos/deads2k/origin/branches{/branch}","tags_url":"https://api.github.com/repos/deads2k/origin/tags","blobs_url":"https://api.github.com/repos/deads2k/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/deads2k/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/deads2k/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/deads2k/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/deads2k/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/deads2k/origin/languages","stargazers_url":"https://api.github.com/repos/deads2k/origin/stargazers","contributors_url":"https://api.github.com/repos/deads2k/origin/contributors","subscribers_url":"https://api.github.com/repos/deads2k/origin/subscribers","subscription_url":"https://api.github.com/repos/deads2k/origin/subscription","commits_url":"https://api.github.com/repos/deads2k/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/deads2k/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/deads2k/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/deads2k/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/deads2k/origin/contents/{+path}","compare_url":"https://api.github.com/repos/deads2k/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/deads2k/origin/merges","archive_url":"https://api.github.com/repos/deads2k/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/deads2k/origin/downloads","issues_url":"https://api.github.com/repos/deads2k/origin/issues{/number}","pulls_url":"https://api.github.com/repos/deads2k/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/deads2k/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/deads2k/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/deads2k/origin/labels{/name}","releases_url":"https://api.github.com/repos/deads2k/origin/releases{/id}","deployments_url":"https://api.github.com/repos/deads2k/origin/deployments","created_at":"2014-09-24T17:02:12Z","updated_at":"2016-01-11T17:58:27Z","pushed_at":"2016-03-04T13:24:53Z","git_url":"git://github.com/deads2k/origin.git","ssh_url":"git@github.com:deads2k/origin.git","clone_url":"https://github.com/deads2k/origin.git","svn_url":"https://github.com/deads2k/origin","homepage":"https://openshift.github.io","size":228327,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"openshift:master","ref":"master","sha":"2270e14fa7f8a6f4af3f5579ce7ead61856109fe","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":22442668,"name":"origin","full_name":"openshift/origin","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":false,"url":"https://api.github.com/repos/openshift/origin","forks_url":"https://api.github.com/repos/openshift/origin/forks","keys_url":"https://api.github.com/repos/openshift/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/origin/teams","hooks_url":"https://api.github.com/repos/openshift/origin/hooks","issue_events_url":"https://api.github.com/repos/openshift/origin/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/origin/events","assignees_url":"https://api.github.com/repos/openshift/origin/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/origin/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/origin/tags","blobs_url":"https://api.github.com/repos/openshift/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/origin/languages","stargazers_url":"https://api.github.com/repos/openshift/origin/stargazers","contributors_url":"https://api.github.com/repos/openshift/origin/contributors","subscribers_url":"https://api.github.com/repos/openshift/origin/subscribers","subscription_url":"https://api.github.com/repos/openshift/origin/subscription","commits_url":"https://api.github.com/repos/openshift/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/origin/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/origin/merges","archive_url":"https://api.github.com/repos/openshift/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/origin/downloads","issues_url":"https://api.github.com/repos/openshift/origin/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/origin/labels{/name}","releases_url":"https://api.github.com/repos/openshift/origin/releases{/id}","deployments_url":"https://api.github.com/repos/openshift/origin/deployments","created_at":"2014-07-30T20:04:05Z","updated_at":"2016-03-04T08:43:05Z","pushed_at":"2016-03-04T14:29:35Z","git_url":"git://github.com/openshift/origin.git","ssh_url":"git@github.com:openshift/origin.git","clone_url":"https://github.com/openshift/origin.git","svn_url":"https://github.com/openshift/origin","homepage":"http://www.openshift.org","size":279776,"stargazers_count":1091,"watchers_count":1091,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":669,"mirror_url":null,"open_issues_count":904,"forks":669,"open_issues":904,"watchers":1091,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/7661"},"html":{"href":"https://github.com/openshift/origin/pull/7661"},"issue":{"href":"https://api.github.com/repos/openshift/origin/issues/7661"},"comments":{"href":"https://api.github.com/repos/openshift/origin/issues/7661/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/origin/pulls/7661/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/origin/pulls/7661/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/origin/statuses/d1f8c14cde3726cb0faf5e4828ba119931fab7e9"}}}}