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

LimitRange calculation should only split Requests for Step Containers #4996

Merged
merged 1 commit into from
Jun 17, 2022

Conversation

skaegi
Copy link
Contributor

@skaegi skaegi commented Jun 16, 2022

Changes

This commit changes how resource requirements are calculated when one or more LimitRanges are present in the namespace where a TaskRun is.

We now will only transform "step" containers and exclude all other app containers (e.g. sidecars and any other containers) when splitting "requests" from LimitRanges.

Existing tests have been fixed to use "Step" containers and two additional tests have been added to verify behavior when a sidecar is present.

Docs have been updated to reflect this change

Cleanup:

  1. When computing the defaultStepRequests if a value "isZero" we do not add it to the result as this is not needed and adds clutter
  2. If the defaultStepRequests object has no entries we do not add it to the resources requirements for a container as this is not needed and adds clutter.

Fixes #4978

/kind bug

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Docs included if any changes are user facing
  • Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been filled in
    (if there are no user facing changes, use release note "NONE")

Release Notes

Only use step containers for limitrange default request calculations

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Jun 16, 2022
@tekton-robot tekton-robot requested review from bobcatfish and jerop June 16, 2022 20:21
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 16, 2022
@skaegi
Copy link
Contributor Author

skaegi commented Jun 16, 2022

/cc @lbernick

@tekton-robot tekton-robot requested a review from lbernick June 16, 2022 20:25
@skaegi skaegi changed the title LimitRange calculation to use only Requests for Step Container LimitRange calculation should only split Requests for Step Containers Jun 16, 2022
@afrittoli
Copy link
Member

/retest

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/internal/limitrange/transformer.go 97.1% 97.5% 0.4

docs/compute-resources.md Outdated Show resolved Hide resolved
pkg/internal/limitrange/transformer_test.go Show resolved Hide resolved
This commit changes how resource requirements are calculated when one or more LimitRanges are present in the namespace where a TaskRun is.

We now will only transform "step" containers and exclude all other app containers (e.g. sidecars and any other containers) when splitting "requests" from LimitRanges.

Existing tests have been fixed to use "Step" containers and two additional tests have been added to verify behavior when a sidecar is present.

Docs have been updated to reflect this change
@skaegi skaegi force-pushed the sidecarfix-limitrange branch from 828ecdd to bbc549b Compare June 17, 2022 14:55
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/internal/limitrange/transformer.go 97.1% 97.5% 0.4

Copy link
Member

@lbernick lbernick left a comment

Choose a reason for hiding this comment

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

thanks Simon!

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lbernick

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 17, 2022
@skaegi
Copy link
Contributor Author

skaegi commented Jun 17, 2022

/test pull-tekton-pipeline-alpha-integration-tests

@skaegi
Copy link
Contributor Author

skaegi commented Jun 17, 2022

/test pull-tekton-pipeline-integration-tests

- the LimitRange minimum resource requests
- the LimitRange default resource requests, divided among the app containers
- the LimitRange default resource requests (for init and Sidecar containers) or the LimitRange default resource requests divided by the number of Step containers (for Step containers)
Copy link
Member

Choose a reason for hiding this comment

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

thank you for clarifying this 👍

Copy link
Contributor Author

@skaegi skaegi Jun 17, 2022

Choose a reason for hiding this comment

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

Lee's new and improved wording not mine ;)

nbContainers := len(p.Spec.Containers)
nbStepContainers := 0
for _, c := range p.Spec.Containers {
if pod.IsContainerStep(c.Name) {
Copy link
Member

Choose a reason for hiding this comment

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

do we need to check for the running containers or any other specific state (not-running) of the container here? or the state of container does not matter at this point since they will be spawned with the configuration being determined here?

Copy link
Member

Choose a reason for hiding this comment

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

alright, so this is only used in pod builder while creating a pod so the state is not relevant here ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The transform happens before the pod spec is applied so the state of the container does not matter at this point. We use the number of step containers to help choose the optimal request size at configuration generation time.

defaultRequests := getDefaultAppContainerRequest(limitRange, nbContainers)
for i := range p.Spec.Containers {
for i, c := range p.Spec.Containers {
var defaultRequests = defaultContainerRequests
Copy link
Member

Choose a reason for hiding this comment

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

I hardly see this way of initializing and declaring a variable, interesting 🙃

}
}
}
}
// return nil if the resource list is empty to avoid setting an empty defaultrequest
Copy link
Member

Choose a reason for hiding this comment

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

NIT: should this be done for the other two other get functions - getDefaultContainerRequest and getDefaultLimits? I havent looked at whether its needed or not but just wondering since we added this here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Glad you noticed ;) They actually already will return nil. The getStepContainerRequest creates an empty request list before trying to populate so this empty check to return nil makes it consistent with the others.

@pritidesai
Copy link
Member

thank you @skaegi, I have one NIT left which can be addressed in a follow up PR if needed.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 17, 2022
@tekton-robot tekton-robot merged commit ec9fa31 into tektoncd:main Jun 17, 2022
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. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

LimitRange Memory and CPU Request Distribution does not handle sidecars correctly
5 participants