Skip to content

Conversation

@moko-poi
Copy link
Contributor

@moko-poi moko-poi commented Oct 5, 2025

Fixes #8407

Description

This PR fixes the incorrect eviction threshold calculation in Karpenter's allocatable memory computation. Previously, Karpenter used max(evictionSoft, evictionHard) to determine how much memory to reserve for eviction thresholds, but this is inconsistent with kubelet behavior.

According to the Kubernetes documentation, only evictionHard thresholds should impact allocatable capacity, while evictionSoft thresholds are warning-only and should not reserve memory.

Changes:

  • Modified evictionThreshold() function in pkg/providers/instancetype/types.go to use only evictionHard values
  • Updated test cases to expect evictionHard values instead of the maximum of both thresholds
  • Added clear comments explaining the change and referencing the Kubernetes specification

Example:

  • Before: evictionSoft: 1Gi, evictionHard: 500Mi → reserves 1Gi (incorrect)
  • After: evictionSoft: 1Gi, evictionHard: 500Mi → reserves 500Mi (matches kubelet)

How was this change tested?

  • Updated existing unit tests to verify the new behavior
  • Modified test expectations for the three affected test cases that were checking max(evictionSoft, evictionHard) logic
  • Verified that the code compiles successfully with the changes
  • All tests now validate that only evictionHard values are used for allocatable capacity calculation

Does this change impact docs?

  • Yes, PR includes docs updates
  • Yes, issue opened: #
  • No

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@moko-poi moko-poi requested a review from a team as a code owner October 5, 2025 14:40
@netlify
Copy link

netlify bot commented Oct 5, 2025

Deploy Preview for karpenter-docs-prod ready!

Name Link
🔨 Latest commit 06e5403
🔍 Latest deploy log https://app.netlify.com/projects/karpenter-docs-prod/deploys/6915cd645ec6060008b399c8
😎 Deploy Preview https://deploy-preview-8565--karpenter-docs-prod.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@grosser grosser left a comment

Choose a reason for hiding this comment

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

👍

DerekFrank
DerekFrank previously approved these changes Oct 7, 2025
Copy link
Contributor

@DerekFrank DerekFrank left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, lets see if CI passes

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

Preview deployment ready!

Preview URL: https://pr-8565.d18coufmbnnaag.amplifyapp.com

Built from commit 07e8b6419daba4b9450280023c735d5087c927bf

@moko-poi
Copy link
Contributor Author

@DerekFrank
7058ca5
Thank you for reviewing! I've addressed the feedback, so could you please trigger the CI run?

@moko-poi moko-poi requested a review from DerekFrank October 12, 2025 05:22
Copy link
Contributor

@DerekFrank DerekFrank left a comment

Choose a reason for hiding this comment

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

/karpenter snapshot

@github-actions
Copy link
Contributor

Snapshot successfully published to oci://021119463062.dkr.ecr.us-east-1.amazonaws.com/karpenter/snapshot/karpenter:0-7058ca5e1e36954bbc6a098f9142643945a98d48.
To install you must login to the ECR repo with an AWS account:

aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 021119463062.dkr.ecr.us-east-1.amazonaws.com

helm upgrade --install karpenter oci://021119463062.dkr.ecr.us-east-1.amazonaws.com/karpenter/snapshot/karpenter --version "0-7058ca5e1e36954bbc6a098f9142643945a98d48" --namespace "kube-system" --create-namespace \
  --set "settings.clusterName=${CLUSTER_NAME}" \
  --set "settings.interruptionQueue=${CLUSTER_NAME}" \
  --set controller.resources.requests.cpu=1 \
  --set controller.resources.requests.memory=1Gi \
  --set controller.resources.limits.cpu=1 \
  --set controller.resources.limits.memory=1Gi \
  --wait

@DerekFrank
Copy link
Contributor

@moko-poi Looks like there are still CI issues. You should be able to run them locally: https://github.com/aws/karpenter-provider-aws/blob/main/Makefile#L52

@moko-poi
Copy link
Contributor Author

moko-poi commented Nov 4, 2025

@DerekFrank Thanks for the reminder. I've already run the tests locally and pushed the fixes. The CI should pass now. Please let me know if there are any remaining issues.
0fcc0e5

❯ make ci-test                                                                                                                                                                              ─╯
go test ./pkg/... \
		-cover -coverprofile=coverage.out -outputdir=. -coverpkg=./... \
		--ginkgo.focus="" \
		--ginkgo.randomize-all \
		--ginkgo.vv
?   	github.com/aws/karpenter-provider-aws/pkg/apis	[no test files]
ok  	github.com/aws/karpenter-provider-aws/pkg/apis/v1	14.585s	coverage: 4.1% of statements in ./...
?   	github.com/aws/karpenter-provider-aws/pkg/aws	[no test files]
ok  	github.com/aws/karpenter-provider-aws/pkg/batcher	13.118s	coverage: 6.2% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/cache	0.328s	coverage: 0.7% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/cloudprovider	47.276s	coverage: 49.5% of statements in ./...
	github.com/aws/karpenter-provider-aws/pkg/cloudprovider/events		coverage: 0.0% of statements
	github.com/aws/karpenter-provider-aws/pkg/controllers		coverage: 0.0% of statements
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/capacityreservation/capacitytype	7.752s	coverage: 6.9% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/capacityreservation/expiration	7.463s	coverage: 8.3% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/interruption	9.282s	coverage: 9.3% of statements in ./...
	github.com/aws/karpenter-provider-aws/pkg/controllers/interruption/events		coverage: 0.0% of statements
	github.com/aws/karpenter-provider-aws/pkg/controllers/interruption/messages		coverage: 0.0% of statements
	github.com/aws/karpenter-provider-aws/pkg/controllers/interruption/messages/noop		coverage: 0.0% of statements
	github.com/aws/karpenter-provider-aws/pkg/controllers/interruption/messages/rebalancerecommendation		coverage: 0.0% of statements
	github.com/aws/karpenter-provider-aws/pkg/controllers/interruption/messages/scheduledchange		coverage: 0.0% of statements
	github.com/aws/karpenter-provider-aws/pkg/controllers/interruption/messages/spotinterruption		coverage: 0.0% of statements
	github.com/aws/karpenter-provider-aws/pkg/controllers/interruption/messages/statechange		coverage: 0.0% of statements
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/metrics	8.872s	coverage: 19.2% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/nodeclaim/garbagecollection	9.603s	coverage: 12.3% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/nodeclaim/tagging	14.283s	coverage: 10.0% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/nodeclass	32.071s	coverage: 38.9% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/nodeclass/garbagecollection	7.968s	coverage: 11.5% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/nodeclass/hash	8.103s	coverage: 9.1% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/providers/instancetype	4.627s	coverage: 11.2% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/providers/instancetype/capacity	7.538s	coverage: 14.6% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/providers/pricing	4.622s	coverage: 9.7% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/providers/ssm/invalidation	4.284s	coverage: 9.5% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/controllers/providers/version	4.650s	coverage: 6.8% of statements in ./...
	github.com/aws/karpenter-provider-aws/pkg/errors		coverage: 0.0% of statements
	github.com/aws/karpenter-provider-aws/pkg/fake		coverage: 0.0% of statements
ok  	github.com/aws/karpenter-provider-aws/pkg/operator	5.748s	coverage: 1.8% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/operator/options	0.376s	coverage: 1.1% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/amifamily	5.106s	coverage: 12.6% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/amifamily/bootstrap	0.887s	coverage: 0.2% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/amifamily/bootstrap/mime	0.613s	coverage: 0.7% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/capacityreservation	4.594s	coverage: 6.6% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/instance	8.176s	coverage: 31.5% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/instance/filter	1.293s	coverage: 2.8% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/instanceprofile	8.839s	coverage: 10.2% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/instancetype	20.108s	coverage: 37.3% of statements in ./...
	github.com/aws/karpenter-provider-aws/pkg/providers/instancetype/offering		coverage: 0.0% of statements
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/launchtemplate	171.026s	coverage: 48.7% of statements in ./...
	github.com/aws/karpenter-provider-aws/pkg/providers/pricing		coverage: 0.0% of statements
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/securitygroup	4.700s	coverage: 8.6% of statements in ./...
	github.com/aws/karpenter-provider-aws/pkg/providers/sqs		coverage: 0.0% of statements
	github.com/aws/karpenter-provider-aws/pkg/providers/ssm		coverage: 0.0% of statements
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/subnet	5.008s	coverage: 8.4% of statements in ./...
ok  	github.com/aws/karpenter-provider-aws/pkg/providers/version	5.906s	coverage: 5.9% of statements in ./...
	github.com/aws/karpenter-provider-aws/pkg/test		coverage: 0.0% of statements
	github.com/aws/karpenter-provider-aws/pkg/utils		coverage: 0.0% of statements
go tool cover -html coverage.out -o coverage.html

@moko-poi moko-poi requested a review from DerekFrank November 4, 2025 16:18
@coveralls
Copy link

coveralls commented Nov 6, 2025

Pull Request Test Coverage Report for Build 20976572512

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 67.537%

Totals Coverage Status
Change from base Build 20928962768: 0.1%
Covered Lines: 7814
Relevant Lines: 11570

💛 - Coveralls

@DerekFrank
Copy link
Contributor

@moko-poi Could you rebase so we can get this merged?

@moko-poi moko-poi force-pushed the fix/issue-8407-eviction-threshold-math branch from 0fcc0e5 to 06e5403 Compare November 13, 2025 12:21
@moko-poi
Copy link
Contributor Author

@DerekFrank Rebased! Ready for review.

@moko-poi
Copy link
Contributor Author

@DerekFrank @grosser @sumukha-radhakrishna
Hi! Just wanted to gently follow up on this PR. Would appreciate any feedback when you have a chance. Thanks!

@jigisha620 jigisha620 force-pushed the fix/issue-8407-eviction-threshold-math branch from 06e5403 to 07e8b64 Compare January 13, 2026 23:37
Copy link
Contributor

@jigisha620 jigisha620 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@jigisha620 jigisha620 merged commit 33f14b4 into aws:main Jan 13, 2026
15 checks passed
saurav-agarwalla pushed a commit to saurav-agarwalla/karpenter-provider-aws that referenced this pull request Jan 22, 2026
RafalSumislawski pushed a commit to RafalSumislawski/karpenter-provider-aws that referenced this pull request Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

max(evictionSoft, evictionHard) math is wrong

6 participants