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

Handle intentionally empty grpc BestOptions #7351

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

rrangith
Copy link
Contributor

@rrangith rrangith commented Oct 4, 2024

What type of PR is this?

/kind bug

Problem

When trying to filter out all options from the gRPC expander side, I noticed that the gRPC expander client on cluster autoscaler would return all the expansion options, rather than none of them.

This is a problem because in some cases I want to filter out all options on the gRPC expander server side, however the cluster-autoscaler client is unfiltering the options when the server returns nothing.

I would expect that if the gRPC expander server returns no best options, CA should fail its scaleup since it has no options available.

Current Behaviour

In the case of nil best options returned from the gRPC expander, the gRPC client returns all original options

if bestOptionsResponse == nil || bestOptionsResponse.Options == nil {
klog.V(4).Info("GRPC returned nil bestOptions, no options filtered")
return expansionOptions
}

Proposed Change

If the grpc expander server returns nil, the client should respect that and also return nil. This is similar to what other expanders do

if len(leastWastedOptions) == 0 {
return nil
}

This change does break things for users who rely on a nil response from the grpc expander server, however this behaviour is very unexpected and I believe it should change to be more predictable

If users want the original behaviour where the client ends up returning all original options, then on the gRPC expander server side they can return an error. Then expander will apply no filtering and return the original expansionOptions.

When the scaleup orchestrator gets an empty best option, it will fail the scaleup as expected

bestOption := o.autoscalingContext.ExpanderStrategy.BestOption(options, nodeInfos)
if bestOption == nil || bestOption.NodeCount <= 0 {
return &status.ScaleUpStatus{
Result: status.ScaleUpNoOptionsAvailable,
PodsRemainUnschedulable: GetRemainingPods(podEquivalenceGroups, skippedNodeGroups),
ConsideredNodeGroups: nodeGroups,
}, nil
}

Testing

I deployed cluster-autoscaler with this change on my cluster and confirmed it does not scaleup when no options are returned, as expected.

Does this PR introduce a user-facing change?

If the gRPC expander server returns nil for its best options, the gRPC expander client will return nil

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Oct 4, 2024
@k8s-ci-robot k8s-ci-robot requested a review from x13n October 4, 2024 20:21
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 4, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @rrangith. 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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 4, 2024
@MaciekPytel
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 Oct 7, 2024
@rrangith
Copy link
Contributor Author

rrangith commented Oct 7, 2024

/assign @MaciekPytel

NodeMap: grpcNodeInfoMap,
})).Return(&tc.mockResponse, tc.errResponse)
resp := g.BestOptions(options, tc.nodeInfo)
if tc.client.grpcClient != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed? It seems like if this happen, the test case haven't been properly initialized, in which case it should fail and not pass silently

Copy link
Contributor Author

@rrangith rrangith Oct 7, 2024

Choose a reason for hiding this comment

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

@MaciekPytel it was for this test case

desc: "Bad gRPC client config",
client: grpcclientstrategy{nil},
nodeInfo: makeFakeNodeInfos(),
mockResponse: protos.BestOptionsResponse{},
errResponse: nil,
, prior to my change, the test was not executing the correct code path since tc.client was never being used, it was always g being used as the client https://github.com/kubernetes/autoscaler/pull/7351/files#diff-5392da3174a0a9693626803662fd3c6871211cfe739ec3b7d6a5efff38e1cae9L272

tc.client was not getting used at all prior to my change, but i fixed it to now get used

the code path being tested is

if g.grpcClient == nil {
klog.Errorf("Incorrect gRPC client config, filtering no options")
return expansionOptions
}
, which is unrelated to my change and I was just fixing the test case since it was broken

@MaciekPytel
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 Oct 14, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MaciekPytel, rrangith

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 Oct 14, 2024
@k8s-ci-robot k8s-ci-robot merged commit 085a2e6 into kubernetes:master Oct 14, 2024
6 checks passed
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. area/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants