Open
Conversation
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 5e73238 | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
713b891 to
90f2dfe
Compare
90f2dfe to
e0350aa
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
[Disruption] Add memory pressure injection
Summary
What: Adds a new
memoryPressuredisruption kind that allows injecting controlled memory pressure on targeted pods by allocating memory inside the target's cgroup until a specified percentage of the memory limit is consumed.Why: The chaos-controller already supports CPU pressure, disk pressure, and disk failure disruptions, but lacked the ability to simulate memory pressure scenarios. This is critical for testing application resilience to OOM conditions, memory-constrained environments, and memory-based autoscaling behaviors.
How: Memory is consumed by joining the target's cgroup and using
mmap(2)withMAP_POPULATEto allocate anonymous memory pages that are immediately backed by physical memory. Allocation can be instantaneous or gradually ramped over a configurable duration. A two-tier architecture (pressure injector + stress subprocess) mirrors the existing CPU pressure pattern.Changes
Domain Logic (
api/v1beta1/):MemoryPressureSpectype withtargetPercent(required, 1-100%) andrampDuration(optional) fieldsGenerateArgs()andExplain()methods for CLI arg generation and human-readable explanationsParseTargetPercent()helper accepting both"76%"and"76"formatsDisruptionSpecextended withMemoryPressurefield, wired into all validation rules (exclusivity with NodeFailure/ContainerFailure/PodReplacement, onInit incompatibility, container specificity check, pulse compatibility)DisruptionKindPicker,DisruptionCount, andExplainupdated for the new kindzz_generated.deepcopy.go)Injector (
injector/):memoryPressureInjector— orchestrator that parses the spec, spawns a background stress process, and manages its lifecycle (inject/clean)memoryStressInjector— in-process stress worker that joins the target cgroup, readsmemory.max/memory.current(cgroupv2) ormemory.limit_in_bytes/memory.usage_in_bytes(cgroupv1), computes the allocation delta, and consumes memory via mmap in configurable ramp stepsmemory_alloc_linux.go(realsyscall.MmapwithMAP_POPULATE) andmemory_alloc_other.go(stub returning error)MemoryStressArgsBuilderinterface + mock for testabilityCLI (
cli/injector/):memory-pressurecobra subcommand with--target-percentand--ramp-durationflagsmemory-stresscobra subcommand (subprocess) with--target-percentand--ramp-durationflagsmain.goTypes (
types/):DisruptionKindMemoryPressureandDisruptionKindMemoryStressconstantsDisruptionKindMemoryPressureadded toDisruptionKindNamessliceSafemode (
safemode/):Memorysafemode struct implementing theSafemodeinterfaceAddAllSafemodeObjectswhenMemoryPressureis presentE2E Tests (
controllers/):controllers/memory_pressure_test.gowith comprehensive scenarios:controllers/cpu_pressure_test.go:ExecuteRemoteCommandhelper (andremotecommand/spdystreamdependencies)CHAOSPLT-212)Unit Tests:
api/v1beta1/memory_pressure_test.go— Validate, GenerateArgs, Explaininjector/memory_pressure_test.go— Inject (success, invalid percent, background error), Clean (no-op, after inject)Documentation:
docs/memory_disruption.md— Full user-facing documentation (spec, examples, cgroup behavior, troubleshooting)docs/disruption_catalogue.md— Comprehensive disruption cataloguedocs/README.md— Updated with memory pressure linkCLAUDE.md— Project-level AI coding guidelinesVendor / Dependencies:
github.com/moby/spdystreamandgithub.com/mxk/go-flowratefromgo.mod(no longer needed after removingremotecommandusage in tests)moby/spdystream,mxk/go-flowrate,x/net/websocket,k8s.io/apimachinery/pkg/util/httpstream,k8s.io/apimachinery/pkg/util/portforward,k8s.io/apimachinery/pkg/util/proxy,k8s.io/apimachinery/pkg/util/remotecommand,k8s.io/client-go/tools/remotecommand,k8s.io/client-go/transport/spdy,k8s.io/client-go/transport/websocket,k8s.io/client-go/util/execTesting
Unit Tests:
MemoryPressureSpec.Validate()— valid percentages, edge cases (0%, 101%, "abc"), ramp durationMemoryPressureSpec.GenerateArgs()— with and without ramp durationMemoryPressureSpec.Explain()— immediate vs ramped descriptionsmemoryPressureInjector.Inject()— successful injection, invalid percent, background process errorsmemoryPressureInjector.Clean()— no-op when no process, proper stop after injectionE2E Tests:
Breaking Changes
No breaking changes.
memoryPressureis a new optional field onDisruptionSpec.Dependencies
github.com/moby/spdystream v0.5.0(indirect, no longer needed)github.com/mxk/go-flowrate(indirect, no longer needed)Checklist
linux/!linux)