{"action":"created","comment":{"url":"https://api.github.com/repos/istio/mixer/pulls/comments/131292297","pull_request_review_id":54259038,"id":131292297,"diff_hunk":"@@ -0,0 +1,160 @@\n+// Copyright 2017 Istio Authors\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+package crd\n+\n+import (\n+\t\"errors\"\n+\t\"strings\"\n+\n+\t\"github.com/ghodss/yaml\"\n+\t\"github.com/golang/glog\"\n+\tmetav1 \"k8s.io/apimachinery/pkg/apis/meta/v1\"\n+\t\"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured\"\n+\t\"k8s.io/apimachinery/pkg/runtime/schema\"\n+\t\"k8s.io/client-go/discovery\"\n+\t\"k8s.io/client-go/dynamic\"\n+\t\"k8s.io/client-go/rest\"\n+)\n+\n+const crdYaml = `\n+apiVersion: apiextensions.k8s.io/v1beta1\n+kind: CustomResourceDefinition\n+metadata:\n+  name: adapters.config.istio.io\n+spec:\n+  group: config.istio.io\n+  version: v1alpha2\n+  names:\n+    plural: adapters\n+    singular: adapter\n+    kind: Adapter\n+---\n+# maybe split it to multiple kinds (i.e. metrics / logs / quotas / monitored resources / principals?)\n+apiVersion: apiextensions.k8s.io/v1beta1\n+kind: CustomResourceDefinition\n+metadata:\n+  name: descriptors.config.istio.io\n+spec:\n+  group: config.istio.io\n+  version: v1alpha2\n+  names:\n+    plural: descriptors\n+    singular: descriptor\n+    kind: Descriptor\n+---\n+apiVersion: apiextensions.k8s.io/v1beta1\n+kind: CustomResourceDefinition\n+metadata:\n+  name: constructors.config.istio.io\n+spec:\n+  group: config.istio.io\n+  version: v1alpha2\n+  names:\n+    plural: constructors\n+    singular: constructor\n+    kind: Constructor\n+---\n+apiVersion: apiextensions.k8s.io/v1beta1\n+kind: CustomResourceDefinition\n+metadata:\n+  name: handlers.config.istio.io\n+spec:\n+  group: config.istio.io\n+  version: v1alpha2\n+  names:\n+    plural: handlers\n+    singular: handler\n+    kind: Handler\n+---\n+apiVersion: apiextensions.k8s.io/v1beta1\n+kind: CustomResourceDefinition\n+metadata:\n+  name: actions.config.istio.io\n+spec:\n+  group: config.istio.io\n+  version: v1alpha2\n+  names:\n+    plural: actions\n+    singular: action\n+    kind: Action\n+---\n+apiVersion: apiextensions.k8s.io/v1beta1\n+kind: CustomResourceDefinition\n+metadata:\n+  name: rules.config.istio.io\n+spec:\n+  group: config.istio.io\n+  version: v1alpha2\n+  names:\n+    plural: rules\n+    singular: rule\n+    kind: Rule\n+`\n+\n+func crdResources() map[string]*unstructured.Unstructured {\n+\tresources := map[string]*unstructured.Unstructured{}\n+\tfor _, y := range strings.Split(crdYaml, \"\\n---\\n\") {\n+\t\tuns := &unstructured.Unstructured{}\n+\t\tif err := yaml.Unmarshal([]byte(y), &uns.Object); err != nil {\n+\t\t\tglog.Errorf(\"Failed to unmarshal: %v\", err)\n+\t\t\tcontinue\n+\t\t}\n+\t\tname := uns.Object[\"metadata\"].(map[string]interface{})[\"name\"].(string)\n+\t\tresources[name] = uns\n+\t}\n+\treturn resources\n+}\n+\n+func getCrdClient(discovery *discovery.DiscoveryClient, config *rest.Config) (*dynamic.ResourceClient, error) {\n+\tgv := &schema.GroupVersion{Group: \"apiextensions.k8s.io\", Version: \"v1beta1\"}\n+\tresources, err := discovery.ServerResourcesForGroupVersion(gv.String())\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tfor _, res := range resources.APIResources {\n+\t\tif res.Kind == \"CustomResourceDefinition\" {\n+\t\t\tconfig.APIPath = \"/apis\"\n+\t\t\tconfig.GroupVersion = gv\n+\t\t\tdynamic, err := dynamic.NewClient(config)\n+\t\t\tif err != nil {\n+\t\t\t\treturn nil, err\n+\t\t\t}\n+\t\t\treturn dynamic.Resource(&res, \"\"), nil\n+\t\t}\n+\t}\n+\treturn nil, errors.New(\"not found\")\n+}\n+\n+func declareCrds(client *dynamic.ResourceClient, crds map[string]*unstructured.Unstructured) error {\n+\tdefs, err := client.List(metav1.ListOptions{})\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tfor _, def := range defs.(*unstructured.UnstructuredList).Items {\n+\t\tname := def.Object[\"metadata\"].(map[string]interface{})[\"name\"].(string)\n+\t\tdelete(crds, name)\n+\t}\n+\tif len(crds) == 0 {\n+\t\treturn nil\n+\t}\n+\tfor _, crd := range crds {\n+\t\tglog.V(7).Infof(\"Declaring %+v\", crd)\n+\t\t_, err := client.Create(crd)","path":"pkg/config/crd/resources.go","position":156,"original_position":154,"commit_id":"74ada027f8d91fa510b904d9aa9a8130188e6b26","original_commit_id":"ad0e5b4197e18f4c2a6f72b1769532fdcc3865e1","user":{"login":"jmuk","id":816093,"avatar_url":"https://avatars3.githubusercontent.com/u/816093?v=4","gravatar_id":"","url":"https://api.github.com/users/jmuk","html_url":"https://github.com/jmuk","followers_url":"https://api.github.com/users/jmuk/followers","following_url":"https://api.github.com/users/jmuk/following{/other_user}","gists_url":"https://api.github.com/users/jmuk/gists{/gist_id}","starred_url":"https://api.github.com/users/jmuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmuk/subscriptions","organizations_url":"https://api.github.com/users/jmuk/orgs","repos_url":"https://api.github.com/users/jmuk/repos","events_url":"https://api.github.com/users/jmuk/events{/privacy}","received_events_url":"https://api.github.com/users/jmuk/received_events","type":"User","site_admin":false},"body":"fixed to pass when the resource definition already existed.\r\n\r\nAlso removed the code path to use this code from `crdwatcher.go`, it won't declare it anymore. Maybe I can remove this file entirely.","created_at":"2017-08-04T00:52:30Z","updated_at":"2017-08-04T00:52:59Z","html_url":"https://github.com/istio/mixer/pull/989#discussion_r131292297","pull_request_url":"https://api.github.com/repos/istio/mixer/pulls/989","_links":{"self":{"href":"https://api.github.com/repos/istio/mixer/pulls/comments/131292297"},"html":{"href":"https://github.com/istio/mixer/pull/989#discussion_r131292297"},"pull_request":{"href":"https://api.github.com/repos/istio/mixer/pulls/989"}}},"pull_request":{"url":"https://api.github.com/repos/istio/mixer/pulls/989","id":133607006,"html_url":"https://github.com/istio/mixer/pull/989","diff_url":"https://github.com/istio/mixer/pull/989.diff","patch_url":"https://github.com/istio/mixer/pull/989.patch","issue_url":"https://api.github.com/repos/istio/mixer/issues/989","number":989,"state":"open","locked":false,"title":"implement Kubernetes CRDs watcher as pkg/config/store interface.","user":{"login":"jmuk","id":816093,"avatar_url":"https://avatars3.githubusercontent.com/u/816093?v=4","gravatar_id":"","url":"https://api.github.com/users/jmuk","html_url":"https://github.com/jmuk","followers_url":"https://api.github.com/users/jmuk/followers","following_url":"https://api.github.com/users/jmuk/following{/other_user}","gists_url":"https://api.github.com/users/jmuk/gists{/gist_id}","starred_url":"https://api.github.com/users/jmuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmuk/subscriptions","organizations_url":"https://api.github.com/users/jmuk/orgs","repos_url":"https://api.github.com/users/jmuk/repos","events_url":"https://api.github.com/users/jmuk/events{/privacy}","received_events_url":"https://api.github.com/users/jmuk/received_events","type":"User","site_admin":false},"body":"This is an inefficient version to consume k8s CRDs as the config\r\ndata -- would be used for the step 1 of #983\n\n<!-- Reviewable:start -->\n---\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/istio/mixer/989)\n<!-- Reviewable:end -->\n","created_at":"2017-08-02T01:45:40Z","updated_at":"2017-08-04T00:52:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"10b8f3fd2bd0c1b46538f473f4ab341dc40f7448","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/istio/mixer/pulls/989/commits","review_comments_url":"https://api.github.com/repos/istio/mixer/pulls/989/comments","review_comment_url":"https://api.github.com/repos/istio/mixer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/istio/mixer/issues/989/comments","statuses_url":"https://api.github.com/repos/istio/mixer/statuses/74ada027f8d91fa510b904d9aa9a8130188e6b26","head":{"label":"jmuk:kubernetes2","ref":"kubernetes2","sha":"74ada027f8d91fa510b904d9aa9a8130188e6b26","user":{"login":"jmuk","id":816093,"avatar_url":"https://avatars3.githubusercontent.com/u/816093?v=4","gravatar_id":"","url":"https://api.github.com/users/jmuk","html_url":"https://github.com/jmuk","followers_url":"https://api.github.com/users/jmuk/followers","following_url":"https://api.github.com/users/jmuk/following{/other_user}","gists_url":"https://api.github.com/users/jmuk/gists{/gist_id}","starred_url":"https://api.github.com/users/jmuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmuk/subscriptions","organizations_url":"https://api.github.com/users/jmuk/orgs","repos_url":"https://api.github.com/users/jmuk/repos","events_url":"https://api.github.com/users/jmuk/events{/privacy}","received_events_url":"https://api.github.com/users/jmuk/received_events","type":"User","site_admin":false},"repo":{"id":91022393,"name":"mixer","full_name":"jmuk/mixer","owner":{"login":"jmuk","id":816093,"avatar_url":"https://avatars3.githubusercontent.com/u/816093?v=4","gravatar_id":"","url":"https://api.github.com/users/jmuk","html_url":"https://github.com/jmuk","followers_url":"https://api.github.com/users/jmuk/followers","following_url":"https://api.github.com/users/jmuk/following{/other_user}","gists_url":"https://api.github.com/users/jmuk/gists{/gist_id}","starred_url":"https://api.github.com/users/jmuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmuk/subscriptions","organizations_url":"https://api.github.com/users/jmuk/orgs","repos_url":"https://api.github.com/users/jmuk/repos","events_url":"https://api.github.com/users/jmuk/events{/privacy}","received_events_url":"https://api.github.com/users/jmuk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jmuk/mixer","description":"Istio's Mixer and its adapters","fork":true,"url":"https://api.github.com/repos/jmuk/mixer","forks_url":"https://api.github.com/repos/jmuk/mixer/forks","keys_url":"https://api.github.com/repos/jmuk/mixer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jmuk/mixer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jmuk/mixer/teams","hooks_url":"https://api.github.com/repos/jmuk/mixer/hooks","issue_events_url":"https://api.github.com/repos/jmuk/mixer/issues/events{/number}","events_url":"https://api.github.com/repos/jmuk/mixer/events","assignees_url":"https://api.github.com/repos/jmuk/mixer/assignees{/user}","branches_url":"https://api.github.com/repos/jmuk/mixer/branches{/branch}","tags_url":"https://api.github.com/repos/jmuk/mixer/tags","blobs_url":"https://api.github.com/repos/jmuk/mixer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jmuk/mixer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jmuk/mixer/git/refs{/sha}","trees_url":"https://api.github.com/repos/jmuk/mixer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jmuk/mixer/statuses/{sha}","languages_url":"https://api.github.com/repos/jmuk/mixer/languages","stargazers_url":"https://api.github.com/repos/jmuk/mixer/stargazers","contributors_url":"https://api.github.com/repos/jmuk/mixer/contributors","subscribers_url":"https://api.github.com/repos/jmuk/mixer/subscribers","subscription_url":"https://api.github.com/repos/jmuk/mixer/subscription","commits_url":"https://api.github.com/repos/jmuk/mixer/commits{/sha}","git_commits_url":"https://api.github.com/repos/jmuk/mixer/git/commits{/sha}","comments_url":"https://api.github.com/repos/jmuk/mixer/comments{/number}","issue_comment_url":"https://api.github.com/repos/jmuk/mixer/issues/comments{/number}","contents_url":"https://api.github.com/repos/jmuk/mixer/contents/{+path}","compare_url":"https://api.github.com/repos/jmuk/mixer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jmuk/mixer/merges","archive_url":"https://api.github.com/repos/jmuk/mixer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jmuk/mixer/downloads","issues_url":"https://api.github.com/repos/jmuk/mixer/issues{/number}","pulls_url":"https://api.github.com/repos/jmuk/mixer/pulls{/number}","milestones_url":"https://api.github.com/repos/jmuk/mixer/milestones{/number}","notifications_url":"https://api.github.com/repos/jmuk/mixer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jmuk/mixer/labels{/name}","releases_url":"https://api.github.com/repos/jmuk/mixer/releases{/id}","deployments_url":"https://api.github.com/repos/jmuk/mixer/deployments","created_at":"2017-05-11T20:50:48Z","updated_at":"2017-05-11T20:50:50Z","pushed_at":"2017-08-04T00:52:57Z","git_url":"git://github.com/jmuk/mixer.git","ssh_url":"git@github.com:jmuk/mixer.git","clone_url":"https://github.com/jmuk/mixer.git","svn_url":"https://github.com/jmuk/mixer","homepage":"","size":14097,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"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":"istio:master","ref":"master","sha":"88718730557ff747a815d08f080765812443a43e","user":{"login":"istio","id":23534644,"avatar_url":"https://avatars1.githubusercontent.com/u/23534644?v=4","gravatar_id":"","url":"https://api.github.com/users/istio","html_url":"https://github.com/istio","followers_url":"https://api.github.com/users/istio/followers","following_url":"https://api.github.com/users/istio/following{/other_user}","gists_url":"https://api.github.com/users/istio/gists{/gist_id}","starred_url":"https://api.github.com/users/istio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/istio/subscriptions","organizations_url":"https://api.github.com/users/istio/orgs","repos_url":"https://api.github.com/users/istio/repos","events_url":"https://api.github.com/users/istio/events{/privacy}","received_events_url":"https://api.github.com/users/istio/received_events","type":"Organization","site_admin":false},"repo":{"id":74177509,"name":"mixer","full_name":"istio/mixer","owner":{"login":"istio","id":23534644,"avatar_url":"https://avatars1.githubusercontent.com/u/23534644?v=4","gravatar_id":"","url":"https://api.github.com/users/istio","html_url":"https://github.com/istio","followers_url":"https://api.github.com/users/istio/followers","following_url":"https://api.github.com/users/istio/following{/other_user}","gists_url":"https://api.github.com/users/istio/gists{/gist_id}","starred_url":"https://api.github.com/users/istio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/istio/subscriptions","organizations_url":"https://api.github.com/users/istio/orgs","repos_url":"https://api.github.com/users/istio/repos","events_url":"https://api.github.com/users/istio/events{/privacy}","received_events_url":"https://api.github.com/users/istio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/istio/mixer","description":"Istio's Mixer and its adapters","fork":false,"url":"https://api.github.com/repos/istio/mixer","forks_url":"https://api.github.com/repos/istio/mixer/forks","keys_url":"https://api.github.com/repos/istio/mixer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/istio/mixer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/istio/mixer/teams","hooks_url":"https://api.github.com/repos/istio/mixer/hooks","issue_events_url":"https://api.github.com/repos/istio/mixer/issues/events{/number}","events_url":"https://api.github.com/repos/istio/mixer/events","assignees_url":"https://api.github.com/repos/istio/mixer/assignees{/user}","branches_url":"https://api.github.com/repos/istio/mixer/branches{/branch}","tags_url":"https://api.github.com/repos/istio/mixer/tags","blobs_url":"https://api.github.com/repos/istio/mixer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/istio/mixer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/istio/mixer/git/refs{/sha}","trees_url":"https://api.github.com/repos/istio/mixer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/istio/mixer/statuses/{sha}","languages_url":"https://api.github.com/repos/istio/mixer/languages","stargazers_url":"https://api.github.com/repos/istio/mixer/stargazers","contributors_url":"https://api.github.com/repos/istio/mixer/contributors","subscribers_url":"https://api.github.com/repos/istio/mixer/subscribers","subscription_url":"https://api.github.com/repos/istio/mixer/subscription","commits_url":"https://api.github.com/repos/istio/mixer/commits{/sha}","git_commits_url":"https://api.github.com/repos/istio/mixer/git/commits{/sha}","comments_url":"https://api.github.com/repos/istio/mixer/comments{/number}","issue_comment_url":"https://api.github.com/repos/istio/mixer/issues/comments{/number}","contents_url":"https://api.github.com/repos/istio/mixer/contents/{+path}","compare_url":"https://api.github.com/repos/istio/mixer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/istio/mixer/merges","archive_url":"https://api.github.com/repos/istio/mixer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/istio/mixer/downloads","issues_url":"https://api.github.com/repos/istio/mixer/issues{/number}","pulls_url":"https://api.github.com/repos/istio/mixer/pulls{/number}","milestones_url":"https://api.github.com/repos/istio/mixer/milestones{/number}","notifications_url":"https://api.github.com/repos/istio/mixer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/istio/mixer/labels{/name}","releases_url":"https://api.github.com/repos/istio/mixer/releases{/id}","deployments_url":"https://api.github.com/repos/istio/mixer/deployments","created_at":"2016-11-19T00:40:17Z","updated_at":"2017-08-03T07:50:28Z","pushed_at":"2017-08-04T00:52:58Z","git_url":"git://github.com/istio/mixer.git","ssh_url":"git@github.com:istio/mixer.git","clone_url":"https://github.com/istio/mixer.git","svn_url":"https://github.com/istio/mixer","homepage":"","size":15465,"stargazers_count":51,"watchers_count":51,"language":"Go","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":65,"mirror_url":null,"open_issues_count":141,"forks":65,"open_issues":141,"watchers":51,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/istio/mixer/pulls/989"},"html":{"href":"https://github.com/istio/mixer/pull/989"},"issue":{"href":"https://api.github.com/repos/istio/mixer/issues/989"},"comments":{"href":"https://api.github.com/repos/istio/mixer/issues/989/comments"},"review_comments":{"href":"https://api.github.com/repos/istio/mixer/pulls/989/comments"},"review_comment":{"href":"https://api.github.com/repos/istio/mixer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/istio/mixer/pulls/989/commits"},"statuses":{"href":"https://api.github.com/repos/istio/mixer/statuses/74ada027f8d91fa510b904d9aa9a8130188e6b26"}}}}
{"actor":{"display_login":"jmuk"}}