{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/40525702","id":40525702,"diff_hunk":"@@ -0,0 +1,98 @@\n+/*\n+Copyright 2014 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 priorities\n+\n+import (\n+\t\"github.com/golang/glog\"\n+\t\"k8s.io/kubernetes/pkg/api\"\n+\t\"k8s.io/kubernetes/pkg/labels\"\n+\t\"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm\"\n+)\n+\n+type ServiceAffinity struct {\n+\tserviceLister algorithm.ServiceLister\n+}\n+\n+func NewServiceAffinityPriority(serviceLister algorithm.ServiceLister) algorithm.PriorityFunction {\n+\tserviceAffinity := &ServiceAffinity{\n+\t\tserviceLister: serviceLister,\n+\t}\n+\treturn serviceAffinity.CalculateAffinityPriority\n+}\n+\n+// CalculateAffinityPriority affiliates a pod to the existing services' pods\n+// that matches the labels indicated in affinitySelector.\n+// The more existing pods to affiliate deployed on, the higher priority the node gets.\n+func (s *ServiceAffinity) CalculateAffinityPriority(pod *api.Pod, podLister algorithm.PodLister, nodeLister algorithm.NodeLister) (algorithm.HostPriorityList, error) {\n+\tvar maxCount int\n+\tcounts := map[string]int{}\n+\taffinitySelector := labels.Set(pod.Spec.AffinitySelector)\n+\n+\t// Logically, we should match pod's affinitySelector with services' selectors.\n+\t// Then, to find services' pods, we need to match pods' labels with services'\n+\t// selectors. Finally, calculate the priorties with affinitySelector and the\n+\t// found pods' labels.\n+\t// As a result of optimization, we match the pod's affinitySelector with\n+\t// existing pods' labels here.\n+\tallPods, err := podLister.List(labels.Everything())\n+\tif err != nil {\n+\t\tglog.V(10).Infof(\"PodLister Error\")\n+\t\treturn nil, err\n+\t}\n+\n+\tif len(allPods) > 0 {\n+\t\tfor _, onePod := range allPods {\n+\t\t\t// Only match pods in the same namespace\n+\t\t\tif onePod.Namespace != pod.Namespace {\n+\t\t\t\tcontinue\n+\t\t\t}\n+\n+\t\t\t// match affinitySelector with every pod's labels.\n+\t\t\t// Every matched label will add to the node's priority\n+\t\t\tfor key, val := range onePod.ObjectMeta.Labels {","path":"plugin/pkg/scheduler/algorithm/priorities/service_affinity.go","position":66,"original_position":66,"commit_id":"68228fd073cdb2dfcaca771a8b136630ebf6b24a","original_commit_id":"68228fd073cdb2dfcaca771a8b136630ebf6b24a","user":{"login":"davidopp","id":8264113,"avatar_url":"https://avatars.githubusercontent.com/u/8264113?v=3","gravatar_id":"","url":"https://api.github.com/users/davidopp","html_url":"https://github.com/davidopp","followers_url":"https://api.github.com/users/davidopp/followers","following_url":"https://api.github.com/users/davidopp/following{/other_user}","gists_url":"https://api.github.com/users/davidopp/gists{/gist_id}","starred_url":"https://api.github.com/users/davidopp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidopp/subscriptions","organizations_url":"https://api.github.com/users/davidopp/orgs","repos_url":"https://api.github.com/users/davidopp/repos","events_url":"https://api.github.com/users/davidopp/events{/privacy}","received_events_url":"https://api.github.com/users/davidopp/received_events","type":"User","site_admin":false},"body":"should this instead be\r\nif affinitySelector.Matches(labels.Set(onePod.ObjectMeta.Labels) {\r\n   counts[onePod.Spec.NodeName]++\r\n   ...\r\n}\r\n?\r\n","created_at":"2015-09-28T08:02:07Z","updated_at":"2015-09-28T08:02:07Z","html_url":"https://github.com/kubernetes/kubernetes/pull/14485#discussion_r40525702","pull_request_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/14485","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/40525702"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/14485#discussion_r40525702"},"pull_request":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/14485"}}},"pull_request":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/14485","id":45887275,"html_url":"https://github.com/kubernetes/kubernetes/pull/14485","diff_url":"https://github.com/kubernetes/kubernetes/pull/14485.diff","patch_url":"https://github.com/kubernetes/kubernetes/pull/14485.patch","issue_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/14485","number":14485,"state":"open","locked":false,"title":"WIP: affinity priority for pods","user":{"login":"kevin-wangzefeng","id":6914660,"avatar_url":"https://avatars.githubusercontent.com/u/6914660?v=3","gravatar_id":"","url":"https://api.github.com/users/kevin-wangzefeng","html_url":"https://github.com/kevin-wangzefeng","followers_url":"https://api.github.com/users/kevin-wangzefeng/followers","following_url":"https://api.github.com/users/kevin-wangzefeng/following{/other_user}","gists_url":"https://api.github.com/users/kevin-wangzefeng/gists{/gist_id}","starred_url":"https://api.github.com/users/kevin-wangzefeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevin-wangzefeng/subscriptions","organizations_url":"https://api.github.com/users/kevin-wangzefeng/orgs","repos_url":"https://api.github.com/users/kevin-wangzefeng/repos","events_url":"https://api.github.com/users/kevin-wangzefeng/events{/privacy}","received_events_url":"https://api.github.com/users/kevin-wangzefeng/received_events","type":"User","site_admin":false},"body":"Ref **#14484 Proposal: Affinity Priority for pods of different RC/services**","created_at":"2015-09-24T11:43:47Z","updated_at":"2015-09-28T08:02:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"552dd014b097e1f7953026e6ab0e0271123f0b6b","assignee":{"login":"davidopp","id":8264113,"avatar_url":"https://avatars.githubusercontent.com/u/8264113?v=3","gravatar_id":"","url":"https://api.github.com/users/davidopp","html_url":"https://github.com/davidopp","followers_url":"https://api.github.com/users/davidopp/followers","following_url":"https://api.github.com/users/davidopp/following{/other_user}","gists_url":"https://api.github.com/users/davidopp/gists{/gist_id}","starred_url":"https://api.github.com/users/davidopp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidopp/subscriptions","organizations_url":"https://api.github.com/users/davidopp/orgs","repos_url":"https://api.github.com/users/davidopp/repos","events_url":"https://api.github.com/users/davidopp/events{/privacy}","received_events_url":"https://api.github.com/users/davidopp/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/14485/commits","review_comments_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/14485/comments","review_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/14485/comments","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/68228fd073cdb2dfcaca771a8b136630ebf6b24a","head":{"label":"kevin-wangzefeng:service-sort-affinity","ref":"service-sort-affinity","sha":"68228fd073cdb2dfcaca771a8b136630ebf6b24a","user":{"login":"kevin-wangzefeng","id":6914660,"avatar_url":"https://avatars.githubusercontent.com/u/6914660?v=3","gravatar_id":"","url":"https://api.github.com/users/kevin-wangzefeng","html_url":"https://github.com/kevin-wangzefeng","followers_url":"https://api.github.com/users/kevin-wangzefeng/followers","following_url":"https://api.github.com/users/kevin-wangzefeng/following{/other_user}","gists_url":"https://api.github.com/users/kevin-wangzefeng/gists{/gist_id}","starred_url":"https://api.github.com/users/kevin-wangzefeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevin-wangzefeng/subscriptions","organizations_url":"https://api.github.com/users/kevin-wangzefeng/orgs","repos_url":"https://api.github.com/users/kevin-wangzefeng/repos","events_url":"https://api.github.com/users/kevin-wangzefeng/events{/privacy}","received_events_url":"https://api.github.com/users/kevin-wangzefeng/received_events","type":"User","site_admin":false},"repo":{"id":40229810,"name":"kubernetes","full_name":"kevin-wangzefeng/kubernetes","owner":{"login":"kevin-wangzefeng","id":6914660,"avatar_url":"https://avatars.githubusercontent.com/u/6914660?v=3","gravatar_id":"","url":"https://api.github.com/users/kevin-wangzefeng","html_url":"https://github.com/kevin-wangzefeng","followers_url":"https://api.github.com/users/kevin-wangzefeng/followers","following_url":"https://api.github.com/users/kevin-wangzefeng/following{/other_user}","gists_url":"https://api.github.com/users/kevin-wangzefeng/gists{/gist_id}","starred_url":"https://api.github.com/users/kevin-wangzefeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevin-wangzefeng/subscriptions","organizations_url":"https://api.github.com/users/kevin-wangzefeng/orgs","repos_url":"https://api.github.com/users/kevin-wangzefeng/repos","events_url":"https://api.github.com/users/kevin-wangzefeng/events{/privacy}","received_events_url":"https://api.github.com/users/kevin-wangzefeng/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kevin-wangzefeng/kubernetes","description":"Container Cluster Manager from Google","fork":true,"url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes","forks_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/forks","keys_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/teams","hooks_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/events","assignees_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/tags","blobs_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/languages","stargazers_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/subscription","commits_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/merges","archive_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/downloads","issues_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/kevin-wangzefeng/kubernetes/releases{/id}","created_at":"2015-08-05T06:55:22Z","updated_at":"2015-09-09T13:30:56Z","pushed_at":"2015-09-26T10:34:13Z","git_url":"git://github.com/kevin-wangzefeng/kubernetes.git","ssh_url":"git@github.com:kevin-wangzefeng/kubernetes.git","clone_url":"https://github.com/kevin-wangzefeng/kubernetes.git","svn_url":"https://github.com/kevin-wangzefeng/kubernetes","homepage":"http://kubernetes.io","size":110655,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"kubernetes:master","ref":"master","sha":"70d94fac9dad9e8e2104100a76b4d4bacfb27b93","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-09-28T07:56:13Z","pushed_at":"2015-09-28T06:39:55Z","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":438069,"stargazers_count":10468,"watchers_count":10468,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2606,"mirror_url":null,"open_issues_count":1908,"forks":2606,"open_issues":1908,"watchers":10468,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/14485"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/14485"},"issue":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/14485"},"comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/14485/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/14485/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/14485/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/kubernetes/statuses/68228fd073cdb2dfcaca771a8b136630ebf6b24a"}}}}