{"action":"created","comment":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/147979778","pull_request_review_id":73149709,"id":147979778,"diff_hunk":"@@ -520,6 +486,57 @@ func (a *HorizontalController) reconcileAutoscaler(hpav1Shared *autoscalingv1.Ho\n \treturn a.updateStatusIfNeeded(hpaStatusOriginal, hpa)\n }\n \n+// normalizeDesiredReplicas takes the metrics desired replicas value and normalizes it based on the appropriate conditions (i.e. < maxReplicas, >\n+// minReplicas, etc...)\n+func (a *HorizontalController) normalizeDesiredReplicas(hpa *autoscalingv2.HorizontalPodAutoscaler, currentReplicas int32, prenormalizedDesiredReplicas int32) (int32, error) {\n+\tvar minReplicas int32\n+\tif hpa.Spec.MinReplicas != nil {\n+\t\tminReplicas = *hpa.Spec.MinReplicas\n+\t} else {\n+\t\tminReplicas = 0\n+\t}\n+\n+\tdesiredReplicas, err := convertDesiredReplicasWithRules(currentReplicas, prenormalizedDesiredReplicas, minReplicas, hpa.Spec.MaxReplicas)\n+\tif err != nil {\n+\t\treturn -1, err\n+\t}\n+\n+\tif desiredReplicas < prenormalizedDesiredReplicas {\n+\t\tsetCondition(hpa, autoscalingv2.ScalingLimited, v1.ConditionTrue, \"TooManyReplicas\", \"the desired replica count is above the maximum number of allowed replicas\")\n+\t} else if desiredReplicas > prenormalizedDesiredReplicas {\n+\t\tsetCondition(hpa, autoscalingv2.ScalingLimited, v1.ConditionTrue, \"TooFewReplicas\", \"the desired replica count is below the minimum number of allowed replicas\")\n+\t} else {\n+\t\tsetCondition(hpa, autoscalingv2.ScalingLimited, v1.ConditionFalse, \"DesiredWithinRange\", \"the desired replica count is within the acceptable range\")\n+\t}\n+\n+\treturn desiredReplicas, nil\n+}\n+\n+func convertDesiredReplicasWithRules(currentReplicas, desiredReplicas, hpaMinReplicas, hpaMaxReplicas int32) (int32, error) {\n+\t// Do not upscale too much to prevent incorrect rapid increase of the number of master replicas caused by\n+\t// bogus CPU usage report from heapster/kubelet (like in issue #32304).\n+\tscaleUpLimit := calculateScaleUpLimit(currentReplicas)\n+\n+\tminimumAllowedReplicas := int32(math.Max(float64(hpaMinReplicas), 1.0))","path":"pkg/controller/podautoscaler/horizontal.go","position":85,"original_position":85,"commit_id":"06086561531c113c5d970ca2667b26944a978e10","original_commit_id":"06086561531c113c5d970ca2667b26944a978e10","user":{"login":"mattjmcnaughton","id":3269376,"avatar_url":"https://avatars3.githubusercontent.com/u/3269376?v=4","gravatar_id":"","url":"https://api.github.com/users/mattjmcnaughton","html_url":"https://github.com/mattjmcnaughton","followers_url":"https://api.github.com/users/mattjmcnaughton/followers","following_url":"https://api.github.com/users/mattjmcnaughton/following{/other_user}","gists_url":"https://api.github.com/users/mattjmcnaughton/gists{/gist_id}","starred_url":"https://api.github.com/users/mattjmcnaughton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattjmcnaughton/subscriptions","organizations_url":"https://api.github.com/users/mattjmcnaughton/orgs","repos_url":"https://api.github.com/users/mattjmcnaughton/repos","events_url":"https://api.github.com/users/mattjmcnaughton/events{/privacy}","received_events_url":"https://api.github.com/users/mattjmcnaughton/received_events","type":"User","site_admin":false},"body":"Ah great to know! Agreed Go should have `Max/Min` functions for ints...","created_at":"2017-10-31T12:41:16Z","updated_at":"2017-10-31T12:43:08Z","html_url":"https://github.com/kubernetes/kubernetes/pull/54701#discussion_r147979778","pull_request_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/54701","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments/147979778"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/54701#discussion_r147979778"},"pull_request":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/54701"}},"in_reply_to_id":147828708},"pull_request":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/54701","id":149191343,"html_url":"https://github.com/kubernetes/kubernetes/pull/54701","diff_url":"https://github.com/kubernetes/kubernetes/pull/54701.diff","patch_url":"https://github.com/kubernetes/kubernetes/pull/54701.patch","issue_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/54701","number":54701,"state":"open","locked":false,"title":"Refactor `reconcileAutoscaler` method in hpa","user":{"login":"mattjmcnaughton","id":3269376,"avatar_url":"https://avatars3.githubusercontent.com/u/3269376?v=4","gravatar_id":"","url":"https://api.github.com/users/mattjmcnaughton","html_url":"https://github.com/mattjmcnaughton","followers_url":"https://api.github.com/users/mattjmcnaughton/followers","following_url":"https://api.github.com/users/mattjmcnaughton/following{/other_user}","gists_url":"https://api.github.com/users/mattjmcnaughton/gists{/gist_id}","starred_url":"https://api.github.com/users/mattjmcnaughton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattjmcnaughton/subscriptions","organizations_url":"https://api.github.com/users/mattjmcnaughton/orgs","repos_url":"https://api.github.com/users/mattjmcnaughton/repos","events_url":"https://api.github.com/users/mattjmcnaughton/events{/privacy}","received_events_url":"https://api.github.com/users/mattjmcnaughton/received_events","type":"User","site_admin":false},"body":"**What this PR does / why we need it**:\r\n\r\nThere have been a couple of recent bugs in the \"normalizing\" part of the\r\n`reconcileAutoscaler` method. This part of the code base is responsible\r\nfor, among other things, taking the suggested desired replicas based on\r\nthe metrics, ensuring it conforms to certain conditions, and updating it\r\nif it does not. Isolate the part that converts the desired replicas\r\nbased on a given set of rules into its own function.\r\n\r\nWe are refactoring this part of the code base to make the logic simpler\r\nand to make it easier to write unit tests.\r\n\r\n**Which issue this PR fixes**: \r\nFixes #53728\r\n\r\n**Release note**:\r\n```release-note\r\nNONE\r\n```\r\n","created_at":"2017-10-27T13:37:13Z","updated_at":"2017-10-31T12:43:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3ef0fc4bdbd14d153939514f842d165bc7b58ed8","assignee":{"login":"DirectXMan12","id":119737,"avatar_url":"https://avatars1.githubusercontent.com/u/119737?v=4","gravatar_id":"","url":"https://api.github.com/users/DirectXMan12","html_url":"https://github.com/DirectXMan12","followers_url":"https://api.github.com/users/DirectXMan12/followers","following_url":"https://api.github.com/users/DirectXMan12/following{/other_user}","gists_url":"https://api.github.com/users/DirectXMan12/gists{/gist_id}","starred_url":"https://api.github.com/users/DirectXMan12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirectXMan12/subscriptions","organizations_url":"https://api.github.com/users/DirectXMan12/orgs","repos_url":"https://api.github.com/users/DirectXMan12/repos","events_url":"https://api.github.com/users/DirectXMan12/events{/privacy}","received_events_url":"https://api.github.com/users/DirectXMan12/received_events","type":"User","site_admin":false},"assignees":[{"login":"DirectXMan12","id":119737,"avatar_url":"https://avatars1.githubusercontent.com/u/119737?v=4","gravatar_id":"","url":"https://api.github.com/users/DirectXMan12","html_url":"https://github.com/DirectXMan12","followers_url":"https://api.github.com/users/DirectXMan12/followers","following_url":"https://api.github.com/users/DirectXMan12/following{/other_user}","gists_url":"https://api.github.com/users/DirectXMan12/gists{/gist_id}","starred_url":"https://api.github.com/users/DirectXMan12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirectXMan12/subscriptions","organizations_url":"https://api.github.com/users/DirectXMan12/orgs","repos_url":"https://api.github.com/users/DirectXMan12/repos","events_url":"https://api.github.com/users/DirectXMan12/events{/privacy}","received_events_url":"https://api.github.com/users/DirectXMan12/received_events","type":"User","site_admin":false},{"login":"mwielgus","id":11994812,"avatar_url":"https://avatars2.githubusercontent.com/u/11994812?v=4","gravatar_id":"","url":"https://api.github.com/users/mwielgus","html_url":"https://github.com/mwielgus","followers_url":"https://api.github.com/users/mwielgus/followers","following_url":"https://api.github.com/users/mwielgus/following{/other_user}","gists_url":"https://api.github.com/users/mwielgus/gists{/gist_id}","starred_url":"https://api.github.com/users/mwielgus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwielgus/subscriptions","organizations_url":"https://api.github.com/users/mwielgus/orgs","repos_url":"https://api.github.com/users/mwielgus/repos","events_url":"https://api.github.com/users/mwielgus/events{/privacy}","received_events_url":"https://api.github.com/users/mwielgus/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/54701/commits","review_comments_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/54701/comments","review_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/54701/comments","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/06086561531c113c5d970ca2667b26944a978e10","head":{"label":"mattjmcnaughton:mattjmcnaughton/53728-clean-up-reconcileAutoscaling","ref":"mattjmcnaughton/53728-clean-up-reconcileAutoscaling","sha":"06086561531c113c5d970ca2667b26944a978e10","user":{"login":"mattjmcnaughton","id":3269376,"avatar_url":"https://avatars3.githubusercontent.com/u/3269376?v=4","gravatar_id":"","url":"https://api.github.com/users/mattjmcnaughton","html_url":"https://github.com/mattjmcnaughton","followers_url":"https://api.github.com/users/mattjmcnaughton/followers","following_url":"https://api.github.com/users/mattjmcnaughton/following{/other_user}","gists_url":"https://api.github.com/users/mattjmcnaughton/gists{/gist_id}","starred_url":"https://api.github.com/users/mattjmcnaughton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattjmcnaughton/subscriptions","organizations_url":"https://api.github.com/users/mattjmcnaughton/orgs","repos_url":"https://api.github.com/users/mattjmcnaughton/repos","events_url":"https://api.github.com/users/mattjmcnaughton/events{/privacy}","received_events_url":"https://api.github.com/users/mattjmcnaughton/received_events","type":"User","site_admin":false},"repo":{"id":42689997,"name":"kubernetes","full_name":"mattjmcnaughton/kubernetes","owner":{"login":"mattjmcnaughton","id":3269376,"avatar_url":"https://avatars3.githubusercontent.com/u/3269376?v=4","gravatar_id":"","url":"https://api.github.com/users/mattjmcnaughton","html_url":"https://github.com/mattjmcnaughton","followers_url":"https://api.github.com/users/mattjmcnaughton/followers","following_url":"https://api.github.com/users/mattjmcnaughton/following{/other_user}","gists_url":"https://api.github.com/users/mattjmcnaughton/gists{/gist_id}","starred_url":"https://api.github.com/users/mattjmcnaughton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattjmcnaughton/subscriptions","organizations_url":"https://api.github.com/users/mattjmcnaughton/orgs","repos_url":"https://api.github.com/users/mattjmcnaughton/repos","events_url":"https://api.github.com/users/mattjmcnaughton/events{/privacy}","received_events_url":"https://api.github.com/users/mattjmcnaughton/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mattjmcnaughton/kubernetes","description":"Container Cluster Manager from Google","fork":true,"url":"https://api.github.com/repos/mattjmcnaughton/kubernetes","forks_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/forks","keys_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/teams","hooks_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/events","assignees_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/tags","blobs_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/languages","stargazers_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/subscription","commits_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/merges","archive_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/downloads","issues_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/releases{/id}","deployments_url":"https://api.github.com/repos/mattjmcnaughton/kubernetes/deployments","created_at":"2015-09-18T00:25:15Z","updated_at":"2016-01-27T21:52:42Z","pushed_at":"2017-10-27T13:35:09Z","git_url":"git://github.com/mattjmcnaughton/kubernetes.git","ssh_url":"git@github.com:mattjmcnaughton/kubernetes.git","clone_url":"https://github.com/mattjmcnaughton/kubernetes.git","svn_url":"https://github.com/mattjmcnaughton/kubernetes","homepage":"http://kubernetes.io","size":495042,"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,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kubernetes:master","ref":"master","sha":"b00c15f1a40162d46fc4b96f4e6714f20aef9e6c","user":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars2.githubusercontent.com/u/13629408?v=4","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://avatars2.githubusercontent.com/u/13629408?v=4","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":"2017-10-31T12:04:42Z","pushed_at":"2017-10-31T12:31:41Z","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":734669,"stargazers_count":28335,"watchers_count":28335,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10144,"mirror_url":null,"archived":false,"open_issues_count":5492,"forks":10144,"open_issues":5492,"watchers":28335,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/54701"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/54701"},"issue":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/54701"},"comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/54701/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/54701/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/54701/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/kubernetes/statuses/06086561531c113c5d970ca2667b26944a978e10"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"mattjmcnaughton"}}