This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
istio-ratelimit-operator is a Kubernetes operator that simplifies rate limiting configuration for Istio service mesh. It manages:
- Global rate limiting: Requires external envoy/ratelimit service (Redis-backed)
- Local rate limiting: Per-pod rate limiting without external dependencies
The operator creates and manages Istio EnvoyFilters that configure Envoy proxies (in gateways or sidecars) to connect to rate limit services.
# Build
make build # Build manager binary to bin/manager
make manifests # Generate CRD manifests and RBAC
make generate # Generate DeepCopy methods
# Test
make test # Run unit tests with coverage
go test ./pkg/... -v # Run specific package tests
go test ./pkg/global/config/... -run TestBuildGateway # Run single test
# Lint
make lint # Run golangci-lint (installs v1.50.1 if missing)
# Run locally
make run # Run controller against current kubeconfig cluster
make install # Install CRDs into cluster
# Docker
make docker-build IMG=<tag> # Build container imageLocated in api/v1alpha1/, the operator manages 5 CRDs in the ratelimit.zufardhiyaulhaq.com group:
| CRD | Purpose |
|---|---|
GlobalRateLimitConfig |
Configures global ratelimit connection settings (domain, service address, failure mode). Creates EnvoyFilter for HTTP filter config. |
GlobalRateLimit |
Defines rate limit rules (matcher actions, limits). References a GlobalRateLimitConfig. Creates EnvoyFilter for route-level actions. |
RateLimitService |
Deploys envoy/ratelimit service (Deployment, Service, ConfigMaps). Aggregates GlobalRateLimit rules into ratelimit config. |
LocalRateLimitConfig |
Configures local (per-pod) ratelimit settings. Creates EnvoyFilter. |
LocalRateLimit |
Defines local rate limit rules. References a LocalRateLimitConfig. |
GlobalRateLimitConfig ─────────────────────────────────→ EnvoyFilter (HTTP filter patch)
│
│ (referenced by)
▼
GlobalRateLimit ───────────────────────────────────────→ EnvoyFilter (route patch)
│
│ (aggregated by)
▼
RateLimitService ──→ Deployment + Service + ConfigMaps (envoy/ratelimit service)
internal/controller/: Kubernetes controllers using controller-runtimepkg/global/config/: Builds EnvoyFilters for GlobalRateLimitConfig (gateway/sidecar variants)pkg/global/ratelimit/: Builds EnvoyFilters for GlobalRateLimit route actionspkg/local/config/: Builds EnvoyFilters for LocalRateLimitConfigpkg/local/ratelimit/: Builds EnvoyFilters for LocalRateLimitpkg/service/: Builders for RateLimitService resources (Deployment, Service, ConfigMaps)pkg/utils/version.go: Istio version mapping for EnvoyFilter compatibility
The operator creates version-specific EnvoyFilters for each Istio version specified in spec.selector.istio_version. EnvoyFilter names follow the pattern {name}-{version} (e.g., my-config-1.25). Supported versions are in pkg/utils/version.go.
Both Global and Local configs support two context types:
gateway: Targets Istio ingress gatewaysidecar: Targets application sidecars
Unit tests use the standard Go testing library with testify assertions. Test files follow the *_test.go convention and are colocated with source files.
E2E tests use Python scripts in e2e/scripts/ and run against k3d clusters with real Istio installations. See Makefile targets like e2e.global.gateway.
The operator is deployed via Helm chart in charts/istio-ratelimit-operator/. CRDs are in crds/crds.yaml. After CRD changes, regenerate with make manifests and copy to the chart.