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

Pass the whole VPA into cappingRecommendationProcessor.Apply() #7527

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adrianmoisey
Copy link
Member

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

The current log message for when no container is found is very misleading and can cause confusion.

This passes the entire VPA object into that function, in order for it to create a log file with the relevant VPA name in it.

It kinda feels like surgery with a scalpel, any alternative approaches would be appreciated.

Take a look at #7491 to see the confusion it can cause.

Which issue(s) this PR fixes:

Fixes #7491

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

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


The current log message for when no container is found is very
misleading and can cause confusion.

This passes the entire VPA object into that function, in order for it to
create a log file with the relevant VPA name in it.

It kinda feels like surgery with a scalpel, any alternative approaches
would be appreciated.
@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 23, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: adrianmoisey
Once this PR has been reviewed and has the lgtm label, please assign voelzmo for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 23, 2024
pod *apiv1.Pod) (*vpa_types.RecommendedPodResources, ContainerToAnnotationsMap, error) {
// TODO: Annotate if request enforced by maintaining proportion with limit and allowed limit range is in conflict with policy.

policy := vpa.Spec.ResourcePolicy.DeepCopy()
Copy link
Member

@omerap12 omerap12 Nov 23, 2024

Choose a reason for hiding this comment

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

Can we check for some edge cases ( just to avoid panic )?

if vpa == nil {
    return nil, nil, fmt.Errorf("cannot process nil vpa")
    }
if pod == nil {
    return nil, nil, fmt.Errorf("cannot process nil pod")
    }
if vpa.Status.Recommendation == nil {
        return nil, nil, nil  // This matches existing behavior for no recommendation
    }

pod *v1.Pod) (*vpa_types.RecommendedPodResources, ContainerToAnnotationsMap, error) {
recommendation := podRecommendation

Copy link
Member

Choose a reason for hiding this comment

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

Same for here ( not sure if needed but just my opinion ):

if vpa == nil {
      return nil, nil, fmt.Errorf("cannot process nil vpa")
  }
if vpa.Status.Recommendation == nil {
    return nil, nil, nil
}

Copy link
Member

@omerap12 omerap12 left a comment

Choose a reason for hiding this comment

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

If my comments make sense to you, we could add more unit tests to cover those edge cases. For example:

func TestApplyWithNilVPA(t *testing.T) {
    pod := test.Pod().WithName("pod1").AddContainer(test.Container().WithName("ctr-name").Get()).Get()
    processor := NewCappingRecommendationProcessor(&fakeLimitRangeCalculator{})
    
    res, annotations, err := processor.Apply(nil, pod)
    assert.Error(t, err)
    assert.Nil(t, res)
    assert.Nil(t, annotations)
}

func TestApplyWithNilPod(t *testing.T) {
    vpa := test.VerticalPodAutoscaler().WithContainer("container").Get()
    processor := NewCappingRecommendationProcessor(&fakeLimitRangeCalculator{})
    
    res, annotations, err := processor.Apply(vpa, nil)
    assert.Error(t, err)
    assert.Nil(t, res)
    assert.Nil(t, annotations)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VPA wrongly determine container name?
3 participants