{"action":"created","comment":{"url":"https://api.github.com/repos/istio/istio/pulls/comments/182298176","pull_request_review_id":113065263,"id":182298176,"diff_hunk":"@@ -0,0 +1,158 @@\n+// Copyright 2018 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 clusterregistry\n+\n+import (\n+\t\"fmt\"\n+\t\"strings\"\n+\t\"time\"\n+\n+\tkubeinformers \"k8s.io/client-go/informers\"\n+\t\"k8s.io/client-go/kubernetes\"\n+\t// \"k8s.io/client-go/tools/clientcmd\"\n+\tcorev1 \"k8s.io/api/core/v1\"\n+\t\"k8s.io/apimachinery/pkg/util/runtime\"\n+\t\"k8s.io/client-go/tools/cache\"\n+\n+\t\"istio.io/istio/pkg/log\"\n+)\n+\n+const (\n+\tmcLabel      = \"config.istio.io/multiClusterConfig\"\n+\tmcAnnotation = \"config.istio.io/clusterName\"\n+)\n+\n+// Controller is the controller implementation for Secret resources\n+type Controller struct {\n+\tkubeclientset kubernetes.Interface\n+\tnamespace     string\n+\tsecretsSynced cache.InformerSynced\n+\tcs            *ClusterStore\n+}\n+\n+// NewController returns a new secret controller\n+func NewController(\n+\tkubeclientset kubernetes.Interface,\n+\tkubeInformerFactory kubeinformers.SharedInformerFactory,\n+\tnamespace string,\n+\tcs *ClusterStore) *Controller {\n+\n+\tsecretsInformer := kubeInformerFactory.Core().V1().Secrets()\n+\n+\tcontroller := &Controller{\n+\t\tkubeclientset: kubeclientset,\n+\t\tnamespace:     namespace,\n+\t\tsecretsSynced: secretsInformer.Informer().HasSynced,\n+\t\tcs:            cs,\n+\t}\n+\n+\tlog.Info(\"Setting up event handlers\")\n+\tsecretsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{\n+\t\tAddFunc:    controller.secretAdd,\n+\t\tDeleteFunc: controller.secretDelete,\n+\t})\n+\n+\treturn controller\n+}\n+\n+// Run starts the controller until it receves a message over stopCh\n+func (c *Controller) Run(stopCh <-chan struct{}) error {\n+\tdefer runtime.HandleCrash()\n+\n+\t// Start the informer factories to begin populating the informer caches\n+\tlog.Info(\"Starting Secrets controller\")\n+\n+\t// Wait for the caches to be synced before starting workers\n+\tlog.Info(\"Waiting for informer caches to sync\")\n+\tif ok := cache.WaitForCacheSync(stopCh, c.secretsSynced); !ok {\n+\t\treturn fmt.Errorf(\"failed to wait for caches to sync\")\n+\t}\n+\n+\t<-stopCh\n+\tlog.Info(\"Shutting down workers\")\n+\n+\treturn nil\n+}\n+\n+func checkSecret(s *corev1.Secret) bool {\n+\tlv, ok := s.Labels[mcLabel]\n+\tif !ok {\n+\t\treturn false\n+\t}\n+\tif strings.ToLower(lv) != \"true\" {\n+\t\treturn false\n+\t}\n+\t_, ok = s.ObjectMeta.Annotations[mcAnnotation]\n+\n+\treturn ok\n+}\n+\n+func addMemberCluster(s *corev1.Secret, cs *ClusterStore) {\n+\tcs.storeLock.Lock()\n+\tdefer cs.storeLock.Unlock()\n+\t// Check if there is already a cluster member with the specified\n+\tif _, ok := cs.clientConfigs[s.ObjectMeta.Annotations[mcAnnotation]]; !ok {\n+\t\tlog.Infof(\"Adding new cluster member: %s\", s.ObjectMeta.Annotations[mcAnnotation])\n+\t\t// cs.store[s.ObjectMeta.Annotations[mcAnnotation]] = s.Data[s.ObjectMeta.Annotations[mcAnnotation]]\n+\t}\n+\tlog.Infof(\"Number of clusters in the cluster store: %d\", len(cs.clientConfigs))\n+}\n+\n+func deleteMemberCluster(s *corev1.Secret, cs *ClusterStore) {\n+\tcs.storeLock.Lock()\n+\tdefer cs.storeLock.Unlock()\n+\t// Check if there is a cluster member with the specified name\n+\tif _, ok := cs.clientConfigs[s.ObjectMeta.Annotations[mcAnnotation]]; ok {\n+\t\tlog.Infof(\"Deleting cluster member: %s\", s.ObjectMeta.Annotations[mcAnnotation])\n+\t\tdelete(cs.clientConfigs, s.ObjectMeta.Annotations[mcAnnotation])\n+\t}\n+\tlog.Infof(\"Number of clusters in the cluster store: %d\", len(cs.clientConfigs))\n+}\n+","path":"pilot/pkg/config/clusterregistry/secretcontroller.go","position":123,"original_position":123,"commit_id":"c963322585ac56f04762e2e3c67ce0d4ba505959","original_commit_id":"c963322585ac56f04762e2e3c67ce0d4ba505959","user":{"login":"sbezverk","id":16273360,"avatar_url":"https://avatars3.githubusercontent.com/u/16273360?v=4","gravatar_id":"","url":"https://api.github.com/users/sbezverk","html_url":"https://github.com/sbezverk","followers_url":"https://api.github.com/users/sbezverk/followers","following_url":"https://api.github.com/users/sbezverk/following{/other_user}","gists_url":"https://api.github.com/users/sbezverk/gists{/gist_id}","starred_url":"https://api.github.com/users/sbezverk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbezverk/subscriptions","organizations_url":"https://api.github.com/users/sbezverk/orgs","repos_url":"https://api.github.com/users/sbezverk/repos","events_url":"https://api.github.com/users/sbezverk/events{/privacy}","received_events_url":"https://api.github.com/users/sbezverk/received_events","type":"User","site_admin":false},"body":"Sure thing will add it.","created_at":"2018-04-18T03:12:04Z","updated_at":"2018-04-18T03:12:05Z","html_url":"https://github.com/istio/istio/pull/5017#discussion_r182298176","pull_request_url":"https://api.github.com/repos/istio/istio/pulls/5017","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/istio/istio/pulls/comments/182298176"},"html":{"href":"https://github.com/istio/istio/pull/5017#discussion_r182298176"},"pull_request":{"href":"https://api.github.com/repos/istio/istio/pulls/5017"}},"in_reply_to_id":182297370},"pull_request":{"url":"https://api.github.com/repos/istio/istio/pulls/5017","id":182265804,"html_url":"https://github.com/istio/istio/pull/5017","diff_url":"https://github.com/istio/istio/pull/5017.diff","patch_url":"https://github.com/istio/istio/pull/5017.patch","issue_url":"https://api.github.com/repos/istio/istio/issues/5017","number":5017,"state":"open","locked":false,"title":"Add secret controller for multicluster","user":{"login":"sbezverk","id":16273360,"avatar_url":"https://avatars3.githubusercontent.com/u/16273360?v=4","gravatar_id":"","url":"https://api.github.com/users/sbezverk","html_url":"https://github.com/sbezverk","followers_url":"https://api.github.com/users/sbezverk/followers","following_url":"https://api.github.com/users/sbezverk/following{/other_user}","gists_url":"https://api.github.com/users/sbezverk/gists{/gist_id}","starred_url":"https://api.github.com/users/sbezverk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbezverk/subscriptions","organizations_url":"https://api.github.com/users/sbezverk/orgs","repos_url":"https://api.github.com/users/sbezverk/repos","events_url":"https://api.github.com/users/sbezverk/events{/privacy}","received_events_url":"https://api.github.com/users/sbezverk/received_events","type":"User","site_admin":false},"body":"WIP\r\n\r\nThis PR does NOT change existing workflow for multicluster. It just adds a controller which will be wathcing for Secrets with specific label and annotation in the specific namespace.\r\nUpon detecting Add or Delete of such Secret object, the controller will add or delete an element in clientConfigs map.","created_at":"2018-04-17T19:10:23Z","updated_at":"2018-04-18T03:12:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a11447fc6bb01a25641489b1ff970e73b4d5094","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":491318011,"url":"https://api.github.com/repos/istio/istio/labels/cla:%20yes","name":"cla: yes","color":"bfdadc","default":false},{"id":780123031,"url":"https://api.github.com/repos/istio/istio/labels/do-not-merge/hold","name":"do-not-merge/hold","color":"bfdadc","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/istio/istio/pulls/5017/commits","review_comments_url":"https://api.github.com/repos/istio/istio/pulls/5017/comments","review_comment_url":"https://api.github.com/repos/istio/istio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/istio/istio/issues/5017/comments","statuses_url":"https://api.github.com/repos/istio/istio/statuses/c963322585ac56f04762e2e3c67ce0d4ba505959","head":{"label":"sbezverk:refactor_to_secret_only","ref":"refactor_to_secret_only","sha":"c963322585ac56f04762e2e3c67ce0d4ba505959","user":{"login":"sbezverk","id":16273360,"avatar_url":"https://avatars3.githubusercontent.com/u/16273360?v=4","gravatar_id":"","url":"https://api.github.com/users/sbezverk","html_url":"https://github.com/sbezverk","followers_url":"https://api.github.com/users/sbezverk/followers","following_url":"https://api.github.com/users/sbezverk/following{/other_user}","gists_url":"https://api.github.com/users/sbezverk/gists{/gist_id}","starred_url":"https://api.github.com/users/sbezverk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbezverk/subscriptions","organizations_url":"https://api.github.com/users/sbezverk/orgs","repos_url":"https://api.github.com/users/sbezverk/repos","events_url":"https://api.github.com/users/sbezverk/events{/privacy}","received_events_url":"https://api.github.com/users/sbezverk/received_events","type":"User","site_admin":false},"repo":{"id":127927671,"name":"istio","full_name":"sbezverk/istio","owner":{"login":"sbezverk","id":16273360,"avatar_url":"https://avatars3.githubusercontent.com/u/16273360?v=4","gravatar_id":"","url":"https://api.github.com/users/sbezverk","html_url":"https://github.com/sbezverk","followers_url":"https://api.github.com/users/sbezverk/followers","following_url":"https://api.github.com/users/sbezverk/following{/other_user}","gists_url":"https://api.github.com/users/sbezverk/gists{/gist_id}","starred_url":"https://api.github.com/users/sbezverk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbezverk/subscriptions","organizations_url":"https://api.github.com/users/sbezverk/orgs","repos_url":"https://api.github.com/users/sbezverk/repos","events_url":"https://api.github.com/users/sbezverk/events{/privacy}","received_events_url":"https://api.github.com/users/sbezverk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sbezverk/istio","description":"An open platform to connect, manage, and secure microservices.","fork":true,"url":"https://api.github.com/repos/sbezverk/istio","forks_url":"https://api.github.com/repos/sbezverk/istio/forks","keys_url":"https://api.github.com/repos/sbezverk/istio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sbezverk/istio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sbezverk/istio/teams","hooks_url":"https://api.github.com/repos/sbezverk/istio/hooks","issue_events_url":"https://api.github.com/repos/sbezverk/istio/issues/events{/number}","events_url":"https://api.github.com/repos/sbezverk/istio/events","assignees_url":"https://api.github.com/repos/sbezverk/istio/assignees{/user}","branches_url":"https://api.github.com/repos/sbezverk/istio/branches{/branch}","tags_url":"https://api.github.com/repos/sbezverk/istio/tags","blobs_url":"https://api.github.com/repos/sbezverk/istio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sbezverk/istio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sbezverk/istio/git/refs{/sha}","trees_url":"https://api.github.com/repos/sbezverk/istio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sbezverk/istio/statuses/{sha}","languages_url":"https://api.github.com/repos/sbezverk/istio/languages","stargazers_url":"https://api.github.com/repos/sbezverk/istio/stargazers","contributors_url":"https://api.github.com/repos/sbezverk/istio/contributors","subscribers_url":"https://api.github.com/repos/sbezverk/istio/subscribers","subscription_url":"https://api.github.com/repos/sbezverk/istio/subscription","commits_url":"https://api.github.com/repos/sbezverk/istio/commits{/sha}","git_commits_url":"https://api.github.com/repos/sbezverk/istio/git/commits{/sha}","comments_url":"https://api.github.com/repos/sbezverk/istio/comments{/number}","issue_comment_url":"https://api.github.com/repos/sbezverk/istio/issues/comments{/number}","contents_url":"https://api.github.com/repos/sbezverk/istio/contents/{+path}","compare_url":"https://api.github.com/repos/sbezverk/istio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sbezverk/istio/merges","archive_url":"https://api.github.com/repos/sbezverk/istio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sbezverk/istio/downloads","issues_url":"https://api.github.com/repos/sbezverk/istio/issues{/number}","pulls_url":"https://api.github.com/repos/sbezverk/istio/pulls{/number}","milestones_url":"https://api.github.com/repos/sbezverk/istio/milestones{/number}","notifications_url":"https://api.github.com/repos/sbezverk/istio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sbezverk/istio/labels{/name}","releases_url":"https://api.github.com/repos/sbezverk/istio/releases{/id}","deployments_url":"https://api.github.com/repos/sbezverk/istio/deployments","created_at":"2018-04-03T15:16:14Z","updated_at":"2018-04-03T15:16:20Z","pushed_at":"2018-04-18T01:08:30Z","git_url":"git://github.com/sbezverk/istio.git","ssh_url":"git@github.com:sbezverk/istio.git","clone_url":"https://github.com/sbezverk/istio.git","svn_url":"https://github.com/sbezverk/istio","homepage":"https://istio.io","size":30451,"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,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"istio:master","ref":"master","sha":"1a50ba3f246a4837ecb008256fb510976c9f61b7","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":74175805,"name":"istio","full_name":"istio/istio","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/istio","description":"An open platform to connect, manage, and secure microservices.","fork":false,"url":"https://api.github.com/repos/istio/istio","forks_url":"https://api.github.com/repos/istio/istio/forks","keys_url":"https://api.github.com/repos/istio/istio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/istio/istio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/istio/istio/teams","hooks_url":"https://api.github.com/repos/istio/istio/hooks","issue_events_url":"https://api.github.com/repos/istio/istio/issues/events{/number}","events_url":"https://api.github.com/repos/istio/istio/events","assignees_url":"https://api.github.com/repos/istio/istio/assignees{/user}","branches_url":"https://api.github.com/repos/istio/istio/branches{/branch}","tags_url":"https://api.github.com/repos/istio/istio/tags","blobs_url":"https://api.github.com/repos/istio/istio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/istio/istio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/istio/istio/git/refs{/sha}","trees_url":"https://api.github.com/repos/istio/istio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/istio/istio/statuses/{sha}","languages_url":"https://api.github.com/repos/istio/istio/languages","stargazers_url":"https://api.github.com/repos/istio/istio/stargazers","contributors_url":"https://api.github.com/repos/istio/istio/contributors","subscribers_url":"https://api.github.com/repos/istio/istio/subscribers","subscription_url":"https://api.github.com/repos/istio/istio/subscription","commits_url":"https://api.github.com/repos/istio/istio/commits{/sha}","git_commits_url":"https://api.github.com/repos/istio/istio/git/commits{/sha}","comments_url":"https://api.github.com/repos/istio/istio/comments{/number}","issue_comment_url":"https://api.github.com/repos/istio/istio/issues/comments{/number}","contents_url":"https://api.github.com/repos/istio/istio/contents/{+path}","compare_url":"https://api.github.com/repos/istio/istio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/istio/istio/merges","archive_url":"https://api.github.com/repos/istio/istio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/istio/istio/downloads","issues_url":"https://api.github.com/repos/istio/istio/issues{/number}","pulls_url":"https://api.github.com/repos/istio/istio/pulls{/number}","milestones_url":"https://api.github.com/repos/istio/istio/milestones{/number}","notifications_url":"https://api.github.com/repos/istio/istio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/istio/istio/labels{/name}","releases_url":"https://api.github.com/repos/istio/istio/releases{/id}","deployments_url":"https://api.github.com/repos/istio/istio/deployments","created_at":"2016-11-18T23:57:21Z","updated_at":"2018-04-18T02:59:19Z","pushed_at":"2018-04-18T02:51:55Z","git_url":"git://github.com/istio/istio.git","ssh_url":"git@github.com:istio/istio.git","clone_url":"https://github.com/istio/istio.git","svn_url":"https://github.com/istio/istio","homepage":"https://istio.io","size":30599,"stargazers_count":7286,"watchers_count":7286,"language":"Go","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":959,"mirror_url":null,"archived":false,"open_issues_count":783,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":959,"open_issues":783,"watchers":7286,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/istio/istio/pulls/5017"},"html":{"href":"https://github.com/istio/istio/pull/5017"},"issue":{"href":"https://api.github.com/repos/istio/istio/issues/5017"},"comments":{"href":"https://api.github.com/repos/istio/istio/issues/5017/comments"},"review_comments":{"href":"https://api.github.com/repos/istio/istio/pulls/5017/comments"},"review_comment":{"href":"https://api.github.com/repos/istio/istio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/istio/istio/pulls/5017/commits"},"statuses":{"href":"https://api.github.com/repos/istio/istio/statuses/c963322585ac56f04762e2e3c67ce0d4ba505959"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"sbezverk"}}