Sign inSign up

bliskner/memory-allocator

By bliskner

•Updated 6 months ago

very simple golang container/tool for testing memory quotas and limits in kubernetes / OpenShift

Image
Developer tools
0

2.6K

bliskner/memory-allocator repository overview

⁠Memory Tester

Memory quota testing tool for containers. Static Go binary, minimal size.

⁠Overview

Memory Tester is a lightweight application designed to test memory quota limits in containers and Kubernetes/OpenShift clusters. It helps validate resource quotas and observe OOMKilled behavior when container memory allocations exceed configured limits.

⁠Image Features

  • Static Compilation: Built with CGO_ENABLED=0, single binary with no external dependencies
  • Minimal Size: Uses scratch base image - essentially zero base layer
  • Security: Minimal attack surface with no shell, package manager, or libraries
  • OCI Compatible: Works with any container runtime (Docker, Podman, containerd)

⁠Quick Start

⁠Local Testing
# Run with CLI flag
podman run -it bliskner/memory-tester:latest --allocate=256M

# Run with environment variable
podman run -it -e ALLOCATE=1G bliskner/memory-tester:latest

# Run with short format
podman run -it bliskner/memory-tester:latest -a 512M

⁠Trivy Security Scan

trivy image --image-src podman bliskner/memory-tester:latest

2026-04-13T09:27:26+02:00	INFO	[vuln] Vulnerability scanning is enabled
2026-04-13T09:27:26+02:00	INFO	[secret] Secret scanning is enabled
2026-04-13T09:27:26+02:00	INFO	[secret] If your scanning is slow, please try '--scanners vuln' to disable secret scanning
2026-04-13T09:27:26+02:00	INFO	[secret] Please see also https://trivy.dev/dev/docs/scanner/secret#recommendation for faster secret detection
2026-04-13T09:27:26+02:00	INFO	Number of language-specific files	num=1
2026-04-13T09:27:26+02:00	INFO	[gobinary] Detecting vulnerabilities...

Report Summary

┌───────────────┬──────────┬─────────────────┬─────────┐
│    Target     │   Type   │ Vulnerabilities │ Secrets │
├───────────────┼──────────┼─────────────────┼─────────┤
│ memory-tester │ gobinary │        0        │    -    │
└───────────────┴──────────┴─────────────────┴─────────┘
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)

⁠OpenShift Deployment

⁠Basic Deployment
# Deploy with default settings
oc new-app bliskner/memory-tester:latest --name=memory-tester

# Deploy with memory allocation
oc new-app bliskner/memory-tester:latest --name=memory-tester -e ALLOCATE=256M

# Deploy with memory limits (triggers OOMKilled if allocation exceeds limit)
oc new-app bliskner/memory-tester:latest --name=memory-tester \
  -e ALLOCATE=512M --limits=memory=256Mi
⁠Verify Deployment
# Check pod status
oc get pods -l app=memory-tester

# View logs
oc logs -l app=memory-tester

# Check for OOMKilled
oc describe pod memory-tester-xxxxx | grep -A 3 "State:"

⁠Kubernetes Deployment

⁠Basic Deployment
# Create deployment
kubectl create deployment memory-tester --image=bliskner/memory-tester:latest

# Set memory allocation
kubectl set env deployment/memory-tester ALLOCATE=256M

# Scale if needed
kubectl scale deployment memory-tester --replicas=1
⁠With Memory Limits
# Edit deployment to add resource limits
kubectl edit deployment memory-tester

# Add to spec.containers[].resources:
resources:
  limits:
    memory: 256Mi
  requests:
    memory: 128Mi
⁠Verify Deployment
# Check pod status
kubectl get pods -l app=memory-tester

# View logs
kubectl logs -l app=memory-tester

# Check for OOMKilled
kubectl describe pod memory-tester-xxxxx

⁠Rootless Container Considerations

OpenShift and other Kubernetes distributions run containers with random UIDs for security. The image works correctly in rootless environments:

  • OpenShift: Container runs with auto-assigned UID (e.g., 1000640000)
  • Memory Allocation: Works normally - memory allocation is namespace-scoped, not UID-dependent
  • Security: No privileged access required

⁠Usage Examples

⁠CLI Flags
./memory-tester --allocate=256M
./memory-tester --allocate=1G
./memory-tester -a 512M
./memory-tester --allocate=1024
⁠Environment Variables
ALLOCATE=256M ./memory-tester
ALLOCATE=1G ./memory-tester
⁠Priority

CLI flags take precedence over environment variables:

ALLOCATE=1G ./memory-tester --allocate=256M
# Result: 256M will be allocated
⁠Memory Formats
FormatExampleBytes
Bytes10241,024
Kilobytes512K, 512KB524,288
Megabytes256M, 256MB268,435,456
Gigabytes1G, 1GB1,073,741,824
Terabytes1T, 1TB1,099,511,627,776

⁠Makefile Commands

# Build static binary
make build

# Build container image
make image

# Run local tests
make test

# Rebuild image without cache
make clean

⁠Environment Variables

VariableDescriptionDefault
IMAGE_NAMEContainer image namememory-tester
IMAGE_TAGContainer image tag2026-04-13
ALLOCATEMemory to allocate-

⁠License

MIT

Tag summary

Content type

Image

Digest

sha256:c09accf42…

Size

1.6 MB

Last updated

6 months ago

docker pull bliskner/memory-allocator