{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/91210134","pull_request_review_id":11719847,"id":91210134,"diff_hunk":"@@ -306,6 +317,50 @@ func (dc *DeploymentController) handleErr(err error, key interface{}) {\n \tdc.queue.Forget(key)\n }\n \n+// classifyReplicaSets uses NewReplicaSetControllerRefManager to classify ReplicaSets\n+// and adopts them if their labels match the Deployment but are missing the reference.\n+// It also removes the controllerRef for ReplicaSets, whose labels no longer matches\n+// the deployment.\n+func (dc *DeploymentController) classifyReplicaSets(deployment *extensions.Deployment) error {\n+\trsList, err := dc.rsLister.ReplicaSets(deployment.Namespace).List(labels.Everything())\n+\tif err != nil {\n+\t\tglog.Errorf(\"Error getting ReplicaSets for deployment %q: %v\", deployment.Name, err)\n+\t\treturn err\n+\t}\n+\n+\tdeploymentSelector, err := unversioned.LabelSelectorAsSelector(deployment.Spec.Selector)\n+\tif err != nil {\n+\t\treturn fmt.Errorf(\"deployment %s/%s has invalid label selector: %v\", deployment.Namespace, deployment.Name, err)\n+\t}\n+\tcm := controller.NewReplicaSetControllerRefManager(dc.rsControl, deployment.ObjectMeta, deploymentSelector, getDeploymentKind())\n+\tmatchesAndControlled, matchesNeedsController, controlledDoesNotMatch := cm.Classify(rsList)\n+\tfor _, replicaSet := range matchesNeedsController {\n+\t\terr := cm.AdoptReplicaSet(replicaSet)\n+\t\t// continue to next RS if adoption fails.\n+\t\tif err != nil {\n+\t\t\t// If the RS no longer exists, don't even log the error.\n+\t\t\tif !errors.IsNotFound(err) {\n+\t\t\t\tutilruntime.HandleError(err)\n+\t\t\t}\n+\t\t} else {\n+\t\t\tmatchesAndControlled = append(matchesAndControlled, replicaSet)\n+\t\t}\n+\t}\n+\t// remove the controllerRef for the RS that no longer have matching labels\n+\tvar errlist []error\n+\tfor _, replicaSet := range controlledDoesNotMatch {","path":"pkg/controller/deployment/deployment_controller.go","position":91,"original_position":91,"commit_id":"a115dab2308aaca36a5c9d14bff136ba06454e06","original_commit_id":"a115dab2308aaca36a5c9d14bff136ba06454e06","user":{"login":"kargakis","id":3900799,"avatar_url":"https://avatars.githubusercontent.com/u/3900799?v=3","gravatar_id":"","url":"https://api.github.com/users/kargakis","html_url":"https://github.com/kargakis","followers_url":"https://api.github.com/users/kargakis/followers","following_url":"https://api.github.com/users/kargakis/following{/other_user}","gists_url":"https://api.github.com/users/kargakis/gists{/gist_id}","starred_url":"https://api.github.com/users/kargakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kargakis/subscriptions","organizations_url":"https://api.github.com/users/kargakis/orgs","repos_url":"https://api.github.com/users/kargakis/repos","events_url":"https://api.github.com/users/kargakis/events{/privacy}","received_events_url":"https://api.github.com/users/kargakis/received_events","type":"User","site_admin":false},"body":"I believe we should discourage selectors changes in controllers but allow changes to enable advanced use-cases (Blue-Green deployments is one). That being said I am not sure what changing a label selector for an app means semantically for the app. Should we treat a change to a new non-overlapping selector (non-overlapping to its previous self) , a new history for the Deployment (what happens now probably by accident) or should we continue maintaining the old history which doesn't match with the new selector anymore? \r\n\r\ncc: @smarterclayton @bgrant0607 ","created_at":"2016-12-07T01:23:37Z","updated_at":"2016-12-07T01:23:38Z","html_url":"https://github.com/kubernetes/kubernetes/pull/35676#discussion_r91210134","pull_request_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/35676","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/91210134"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/35676#discussion_r91210134"},"pull_request":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/35676"}}},"pull_request":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/35676","id":91143903,"html_url":"https://github.com/kubernetes/kubernetes/pull/35676","diff_url":"https://github.com/kubernetes/kubernetes/pull/35676.diff","patch_url":"https://github.com/kubernetes/kubernetes/pull/35676.patch","issue_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/35676","number":35676,"state":"open","locked":false,"title":"ReplicaSet has onwer ref of the Deployment that created it","user":{"login":"krmayankk","id":16662068,"avatar_url":"https://avatars.githubusercontent.com/u/16662068?v=3","gravatar_id":"","url":"https://api.github.com/users/krmayankk","html_url":"https://github.com/krmayankk","followers_url":"https://api.github.com/users/krmayankk/followers","following_url":"https://api.github.com/users/krmayankk/following{/other_user}","gists_url":"https://api.github.com/users/krmayankk/gists{/gist_id}","starred_url":"https://api.github.com/users/krmayankk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krmayankk/subscriptions","organizations_url":"https://api.github.com/users/krmayankk/orgs","repos_url":"https://api.github.com/users/krmayankk/repos","events_url":"https://api.github.com/users/krmayankk/events{/privacy}","received_events_url":"https://api.github.com/users/krmayankk/received_events","type":"User","site_admin":false},"body":"**What this PR does / why we need it**:\nThis enabled garbage collection for ReplicaSets and ensures they are owned by their respective Deployment objects.\n\nfixes https://github.com/kubernetes/kubernetes/issues/33845\n\nThis is an initial PR to get feedback. Will update this quickly with unit tests if this seems like in the right direction\n\n<!-- Reviewable:start -->\n\n---\n\nThis change is [<img src=\"https://reviewable.kubernetes.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.kubernetes.io/reviews/kubernetes/kubernetes/35676)\n\n<!-- Reviewable:end -->\n","created_at":"2016-10-27T07:04:27Z","updated_at":"2016-12-07T01:23:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e4335f71acc8112e488a91fb4908e5dea98df596","assignee":{"login":"caesarxuchao","id":2823529,"avatar_url":"https://avatars.githubusercontent.com/u/2823529?v=3","gravatar_id":"","url":"https://api.github.com/users/caesarxuchao","html_url":"https://github.com/caesarxuchao","followers_url":"https://api.github.com/users/caesarxuchao/followers","following_url":"https://api.github.com/users/caesarxuchao/following{/other_user}","gists_url":"https://api.github.com/users/caesarxuchao/gists{/gist_id}","starred_url":"https://api.github.com/users/caesarxuchao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caesarxuchao/subscriptions","organizations_url":"https://api.github.com/users/caesarxuchao/orgs","repos_url":"https://api.github.com/users/caesarxuchao/repos","events_url":"https://api.github.com/users/caesarxuchao/events{/privacy}","received_events_url":"https://api.github.com/users/caesarxuchao/received_events","type":"User","site_admin":false},"assignees":[{"login":"caesarxuchao","id":2823529,"avatar_url":"https://avatars.githubusercontent.com/u/2823529?v=3","gravatar_id":"","url":"https://api.github.com/users/caesarxuchao","html_url":"https://github.com/caesarxuchao","followers_url":"https://api.github.com/users/caesarxuchao/followers","following_url":"https://api.github.com/users/caesarxuchao/following{/other_user}","gists_url":"https://api.github.com/users/caesarxuchao/gists{/gist_id}","starred_url":"https://api.github.com/users/caesarxuchao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caesarxuchao/subscriptions","organizations_url":"https://api.github.com/users/caesarxuchao/orgs","repos_url":"https://api.github.com/users/caesarxuchao/repos","events_url":"https://api.github.com/users/caesarxuchao/events{/privacy}","received_events_url":"https://api.github.com/users/caesarxuchao/received_events","type":"User","site_admin":false},{"login":"kargakis","id":3900799,"avatar_url":"https://avatars.githubusercontent.com/u/3900799?v=3","gravatar_id":"","url":"https://api.github.com/users/kargakis","html_url":"https://github.com/kargakis","followers_url":"https://api.github.com/users/kargakis/followers","following_url":"https://api.github.com/users/kargakis/following{/other_user}","gists_url":"https://api.github.com/users/kargakis/gists{/gist_id}","starred_url":"https://api.github.com/users/kargakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kargakis/subscriptions","organizations_url":"https://api.github.com/users/kargakis/orgs","repos_url":"https://api.github.com/users/kargakis/repos","events_url":"https://api.github.com/users/kargakis/events{/privacy}","received_events_url":"https://api.github.com/users/kargakis/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/kubernetes/kubernetes/milestones/31","html_url":"https://github.com/kubernetes/kubernetes/milestones/v1.6","labels_url":"https://api.github.com/repos/kubernetes/kubernetes/milestones/31/labels","id":2130587,"number":31,"title":"v1.6","description":null,"creator":{"login":"saad-ali","id":10052848,"avatar_url":"https://avatars.githubusercontent.com/u/10052848?v=3","gravatar_id":"","url":"https://api.github.com/users/saad-ali","html_url":"https://github.com/saad-ali","followers_url":"https://api.github.com/users/saad-ali/followers","following_url":"https://api.github.com/users/saad-ali/following{/other_user}","gists_url":"https://api.github.com/users/saad-ali/gists{/gist_id}","starred_url":"https://api.github.com/users/saad-ali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saad-ali/subscriptions","organizations_url":"https://api.github.com/users/saad-ali/orgs","repos_url":"https://api.github.com/users/saad-ali/repos","events_url":"https://api.github.com/users/saad-ali/events{/privacy}","received_events_url":"https://api.github.com/users/saad-ali/received_events","type":"User","site_admin":false},"open_issues":203,"closed_issues":66,"state":"open","created_at":"2016-11-12T00:35:38Z","updated_at":"2016-12-06T19:06:28Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/35676/commits","review_comments_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/35676/comments","review_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/35676/comments","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/a115dab2308aaca36a5c9d14bff136ba06454e06","head":{"label":"krmayankk:contr-ref","ref":"contr-ref","sha":"a115dab2308aaca36a5c9d14bff136ba06454e06","user":{"login":"krmayankk","id":16662068,"avatar_url":"https://avatars.githubusercontent.com/u/16662068?v=3","gravatar_id":"","url":"https://api.github.com/users/krmayankk","html_url":"https://github.com/krmayankk","followers_url":"https://api.github.com/users/krmayankk/followers","following_url":"https://api.github.com/users/krmayankk/following{/other_user}","gists_url":"https://api.github.com/users/krmayankk/gists{/gist_id}","starred_url":"https://api.github.com/users/krmayankk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krmayankk/subscriptions","organizations_url":"https://api.github.com/users/krmayankk/orgs","repos_url":"https://api.github.com/users/krmayankk/repos","events_url":"https://api.github.com/users/krmayankk/events{/privacy}","received_events_url":"https://api.github.com/users/krmayankk/received_events","type":"User","site_admin":false},"repo":{"id":68579074,"name":"kubernetes","full_name":"krmayankk/kubernetes","owner":{"login":"krmayankk","id":16662068,"avatar_url":"https://avatars.githubusercontent.com/u/16662068?v=3","gravatar_id":"","url":"https://api.github.com/users/krmayankk","html_url":"https://github.com/krmayankk","followers_url":"https://api.github.com/users/krmayankk/followers","following_url":"https://api.github.com/users/krmayankk/following{/other_user}","gists_url":"https://api.github.com/users/krmayankk/gists{/gist_id}","starred_url":"https://api.github.com/users/krmayankk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krmayankk/subscriptions","organizations_url":"https://api.github.com/users/krmayankk/orgs","repos_url":"https://api.github.com/users/krmayankk/repos","events_url":"https://api.github.com/users/krmayankk/events{/privacy}","received_events_url":"https://api.github.com/users/krmayankk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/krmayankk/kubernetes","description":"Production-Grade Container Scheduling and Management","fork":true,"url":"https://api.github.com/repos/krmayankk/kubernetes","forks_url":"https://api.github.com/repos/krmayankk/kubernetes/forks","keys_url":"https://api.github.com/repos/krmayankk/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/krmayankk/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/krmayankk/kubernetes/teams","hooks_url":"https://api.github.com/repos/krmayankk/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/krmayankk/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/krmayankk/kubernetes/events","assignees_url":"https://api.github.com/repos/krmayankk/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/krmayankk/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/krmayankk/kubernetes/tags","blobs_url":"https://api.github.com/repos/krmayankk/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/krmayankk/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/krmayankk/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/krmayankk/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/krmayankk/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/krmayankk/kubernetes/languages","stargazers_url":"https://api.github.com/repos/krmayankk/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/krmayankk/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/krmayankk/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/krmayankk/kubernetes/subscription","commits_url":"https://api.github.com/repos/krmayankk/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/krmayankk/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/krmayankk/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/krmayankk/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/krmayankk/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/krmayankk/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/krmayankk/kubernetes/merges","archive_url":"https://api.github.com/repos/krmayankk/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/krmayankk/kubernetes/downloads","issues_url":"https://api.github.com/repos/krmayankk/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/krmayankk/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/krmayankk/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/krmayankk/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/krmayankk/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/krmayankk/kubernetes/releases{/id}","deployments_url":"https://api.github.com/repos/krmayankk/kubernetes/deployments","created_at":"2016-09-19T07:12:32Z","updated_at":"2016-09-19T07:13:08Z","pushed_at":"2016-12-02T06:16:47Z","git_url":"git://github.com/krmayankk/kubernetes.git","ssh_url":"git@github.com:krmayankk/kubernetes.git","clone_url":"https://github.com/krmayankk/kubernetes.git","svn_url":"https://github.com/krmayankk/kubernetes","homepage":"http://kubernetes.io","size":357064,"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":"6abb4723571fc6b9e4dc05807511569dfc865f83","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":"Production-Grade Container Scheduling and Management","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}","deployments_url":"https://api.github.com/repos/kubernetes/kubernetes/deployments","created_at":"2014-06-06T22:56:04Z","updated_at":"2016-12-07T01:18:16Z","pushed_at":"2016-12-07T01:16:37Z","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":661052,"stargazers_count":18937,"watchers_count":18937,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":6297,"mirror_url":null,"open_issues_count":5393,"forks":6297,"open_issues":5393,"watchers":18937,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/35676"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/35676"},"issue":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/35676"},"comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/35676/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/35676/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/35676/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/kubernetes/statuses/a115dab2308aaca36a5c9d14bff136ba06454e06"}}}}
{"actor":{"display_login":"kargakis"}}