Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ambiguous selector check to HPA #112011

Merged
merged 1 commit into from Nov 7, 2022

Conversation

pbeschetnov
Copy link
Contributor

@pbeschetnov pbeschetnov commented Aug 24, 2022

What type of PR is this?

/kind bug

What this PR does / why we need it:

The PR changes Horizontal Pod Autoscaler behavior: TL;DR we're adding logic that if more than one HPAs are operating on the same pod, we stop them.

There are cases when selected Pod sets overlap due to misconfiguration:

Example 1:

Deployment A (with controlling HPA A) has selector:

...
spec:
  selector:
    matchLabels:
      pod: a
...

Deployment B (with controlling HPA B) has selector:

...
spec:
  selector:
    matchLabels:
      pod: b
...

And there is a group of Pods with:

...
labels:
  pod: a
  pod: b
...

Example 2:

HPA A and HPA B point to the same deployment.

As a result:

The same Pods are actuated first by HPA A then by HPA B in an unpredictable way.

Intended behavior:

In this case the HPAs should be disabled and the problem — reported to the user through conditions.

The algorithm to determine these situations is as follows:

  1. For current HPA list the selected pods.
  2. For each pod check whether it is selected by other HPAs too.
  3. If so then set ScalingActive=false and return an error.

Which issue(s) this PR fixes:

Fixes #112027

Special notes for your reviewer:

The BiMultimap from package selectors is used to store all active HPAs' selectors and efficiently find the HPA-references to current pods.

The BiMultimap operates on:

  • objects — or in our case Pods
  • selectors — HPAs with selectors

It supports methods: Put (object), PutSelector — to insert entities; and Select — to get objects by a given selector; ReverseSelect — to get selectors that point to a given object.

Does this PR introduce a user-facing change?

Added selector validation to HorizontalPodAutoscaler: when multiple HPAs select the same set of Pods, scaling now will be disabled for those HPAs with the reason `AmbiguousSelector`. This change also covers a case when multiple HPAs point to the same deployment.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 24, 2022
@k8s-ci-robot
Copy link
Contributor

@pbeschetnov: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 24, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @pbeschetnov. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Aug 24, 2022
pkg/util/selectors/bimulaimap_test.go Outdated Show resolved Hide resolved
pkg/controller/podautoscaler/horizontal_test.go Outdated Show resolved Hide resolved
pkg/controller/podautoscaler/horizontal.go Outdated Show resolved Hide resolved
pkg/controller/podautoscaler/horizontal.go Outdated Show resolved Hide resolved
@pbeschetnov pbeschetnov force-pushed the ambiguous-selectors branch 4 times, most recently from fbd0856 to e6005c3 Compare September 6, 2022 07:55
pkg/controller/podautoscaler/horizontal.go Outdated Show resolved Hide resolved
pkg/controller/podautoscaler/horizontal.go Outdated Show resolved Hide resolved
pkg/controller/podautoscaler/horizontal_test.go Outdated Show resolved Hide resolved
pkg/controller/podautoscaler/horizontal_test.go Outdated Show resolved Hide resolved
pkg/controller/podautoscaler/horizontal_test.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 23, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 26, 2022
@pbetkier
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 26, 2022
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 20, 2022
@pbeschetnov
Copy link
Contributor Author

/retest

1 similar comment
@pbeschetnov
Copy link
Contributor Author

/retest

@pbetkier
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 20, 2022
Copy link
Contributor

@mwielgus mwielgus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@pbeschetnov
Copy link
Contributor Author

/assign @smarterclayton

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Nov 4, 2022
@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 4, 2022
@smarterclayton
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mwielgus, pbeschetnov, pbetkier, smarterclayton

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 4, 2022
@pacoxu
Copy link
Member

pacoxu commented Nov 6, 2022

/retest

1 similar comment
@pacoxu
Copy link
Member

pacoxu commented Nov 7, 2022

/retest

@pacoxu
Copy link
Member

pacoxu commented Nov 7, 2022

/skip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined behaviour when selected pods overlap in HPA
6 participants