-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(admission-controller): separate CPU/Memory requests and limits for Auto-Instrumentation Init Containers #41048
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
Open
puretension
wants to merge
4
commits into
DataDog:main
Choose a base branch
from
puretension:feat/separate-init-container-requests-limits-38831
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b66f82c
feat(admission-controller): separate CPU/Memory requests and limits f…
puretension 04c93ed
fix: use BindEnvAndSetDefault for init container resource configs
puretension ac8cd17
fix: separate requests and limits auto-calculation logic
puretension aef56c2
Merge branch 'main' into feat/separate-init-container-requests-limits…
puretension File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -397,38 +397,42 @@ func initContainerResourceRequirements(pod *corev1.Pod, conf initResourceRequire | |
| } | ||
| podRequirements := podSumRessourceRequirements(pod) | ||
| insufficientResourcesMessage := "The overall pod's containers limit is too low" | ||
|
|
||
| for _, k := range [2]corev1.ResourceName{corev1.ResourceCPU, corev1.ResourceMemory} { | ||
| if q, ok := conf[k]; ok { | ||
| requirements.Limits[k] = q | ||
| requirements.Requests[k] = q | ||
| } else { | ||
| if maxPodLim, ok := podRequirements.Limits[k]; ok { | ||
| // If the pod before adding instrumentation init containers would have had a limits smaller than | ||
| // a certain amount, we just don't do anything, for two reasons: | ||
| // 1. The init containers need quite a lot of memory/CPU in order to not OOM or initialize in reasonnable time | ||
| // 2. The APM libraries themselves will increase footprint of the container by a | ||
| // non trivial amount, and we don't want to cause issues for constrained apps | ||
| switch k { | ||
| case corev1.ResourceMemory: | ||
| if minimumMemoryLimit.Cmp(maxPodLim) == 1 { | ||
| decision.skipInjection = true | ||
| insufficientResourcesMessage += fmt.Sprintf(", %v pod_limit=%v needed=%v", k, maxPodLim.String(), minimumMemoryLimit.String()) | ||
| } | ||
| case corev1.ResourceCPU: | ||
| if minimumCPULimit.Cmp(maxPodLim) == 1 { | ||
| decision.skipInjection = true | ||
| insufficientResourcesMessage += fmt.Sprintf(", %v pod_limit=%v needed=%v", k, maxPodLim.String(), minimumCPULimit.String()) | ||
| // Check if explicit requests/limits are configured | ||
| if req, hasReq := conf.requests[k]; hasReq { | ||
| requirements.Requests[k] = req | ||
| } | ||
| if lim, hasLim := conf.limits[k]; hasLim { | ||
| requirements.Limits[k] = lim | ||
| } | ||
|
|
||
| // If neither requests nor limits are configured, use auto-calculation | ||
| if _, hasReq := conf.requests[k]; !hasReq { | ||
| if _, hasLim := conf.limits[k]; !hasLim { | ||
| if maxPodLim, ok := podRequirements.Limits[k]; ok { | ||
| // Check minimum requirements | ||
| switch k { | ||
| case corev1.ResourceMemory: | ||
| if minimumMemoryLimit.Cmp(maxPodLim) == 1 { | ||
| decision.skipInjection = true | ||
| insufficientResourcesMessage += fmt.Sprintf(", %v pod_limit=%v needed=%v", k, maxPodLim.String(), minimumMemoryLimit.String()) | ||
| } | ||
| case corev1.ResourceCPU: | ||
| if minimumCPULimit.Cmp(maxPodLim) == 1 { | ||
| decision.skipInjection = true | ||
| insufficientResourcesMessage += fmt.Sprintf(", %v pod_limit=%v needed=%v", k, maxPodLim.String(), minimumCPULimit.String()) | ||
| } | ||
| } | ||
| default: | ||
| // We don't support other resources | ||
| requirements.Limits[k] = maxPodLim | ||
| } | ||
| if maxPodReq, ok := podRequirements.Requests[k]; ok { | ||
|
||
| requirements.Requests[k] = maxPodReq | ||
| } | ||
| requirements.Limits[k] = maxPodLim | ||
| } | ||
| if maxPodReq, ok := podRequirements.Requests[k]; ok { | ||
| requirements.Requests[k] = maxPodReq | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if decision.skipInjection { | ||
| log.Debug(insufficientResourcesMessage) | ||
| decision.message = insufficientResourcesMessage | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
releasenotes/notes/separate-init-container-requests-limits-38831-5974c05b90677e00.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Each section from every release note are combined when the | ||
| # CHANGELOG.rst is rendered. So the text needs to be worded so that | ||
| # it does not depend on any information only available in another | ||
| # section. This may mean repeating some details, but each section | ||
| # must be readable independently of the other. | ||
| # | ||
| # Each section note must be formatted as reStructuredText. | ||
| --- | ||
| features: | ||
| - | | ||
| Add support for separate CPU/Memory requests and limits for auto-instrumentation init containers. | ||
| New environment variables allow independent configuration of requests and limits: | ||
|
|
||
| * ``DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_INIT_REQUESTS_CPU`` | ||
| * ``DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_INIT_REQUESTS_MEMORY`` | ||
| * ``DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_INIT_LIMITS_CPU`` | ||
| * ``DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_INIT_LIMITS_MEMORY`` | ||
|
|
||
| This resolves OOMKilled issues while maintaining scheduling efficiency by allowing | ||
| low requests for scheduling and higher limits for initialization spikes. | ||
| Existing ``DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_INIT_RESOURCES_*`` | ||
| environment variables continue to work for backward compatibility. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only auto-calculates when BOTH requests AND limits are missing. What if user only sets one value? Can you clarify in the comment or doc for this case.