operation-cache-controller
CLAUDE.md2 starsChanged 5 months agoMITView on GitHub
The Operation Cache Controller is a Kubernetes operator built with kubebuilder v4 framework that manages operations and caches the outcome of those operations. It provisions resources, pre-provisions resources for future use (caching), and manages the lifecycle of resources and cache. The controller manages four main Custom Resource Definitions (CRDs) in the controller.azure.github.com API group: The project follows a handler-based reconciliation pattern with clear separation of concerns: The main reconcilers are located in internal/controller/: - RequirementReconciler - Creates Cache and Operation…
We split this CLAUDE.md into the rules it gives an agent
11 rules. About 0 are common, 5 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 38
Finalizers: All CRDs except Cache use finalizers for cleanup
- Distinctive: line 111
Integration Tests: Use envtest for lightweight K8s API server testing
- Distinctive: line 116
All handler interfaces are mocked for testing:
- Very specific: line 163
CRD Changes: Update api/v1alpha1/*_types.go with kubebuilder markers
- Very specific: line 164
Generate Code: Run make manifests generate to update CRDs and DeepCopy methods
- Very specific: line 166
Controller Updates: Update reconciler in internal/controller/ to call new handler methods
- Distinctive: line 167
Testing: Add unit tests for handlers and integration tests for controllers
- Very specific: line 168
Mocks: Run go generate ./... to update mock interfaces
- Very specific: line 171
Use structured logging with keys from internal/log/
- Very specific: line 172
Check controller metrics at :8443/metrics endpoint
- Distinctive: line 175
Check field indexes if queries are slow
≈ “Common” is an estimate: at least 1 in 5 of the 25,680 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
The Operation Cache Controller is a Kubernetes operator built with kubebuilder v4 framework that manages operations and caches the outcome of those operations. It provisions resources, pre-provisions resources for future use (caching), and manages the lifecycle of resources and cache.
Architecture
The controller manages four main Custom Resource Definitions (CRDs) in the controller.azure.github.com API group:
- Requirement - User-defined specifications for required applications with optional caching
- Operation - Represents the deployment operation based on requirements
- AppDeployment - Manages provision and teardown jobs for actual resource deployment
- Cache - Stores pre-provisioned resources with cache duration and auto-count features
Controller Architecture Pattern
The project follows a handler-based reconciliation pattern with clear separation of concerns:
Controller (Reconciler) → Handler Interface → Handler Implementation
↓
Helper UtilitiesThe main reconcilers are located in internal/controller/:
RequirementReconciler- Creates Cache and Operation CRs from Requirement specsOperationReconciler- Creates/deletes AppDeployment CRs from Operation specsAppDeploymentReconciler- Creates provision/teardown Kubernetes JobsCacheReconciler- Manages cached resource lifecycle
Each controller uses:
- Sequential operations: Reconciliation operations are executed in order using
internal/utils/reconciler/operations.go - Handler interfaces: Business logic is separated into mockable handler interfaces in
internal/handler/ - High concurrency: 50-100 concurrent reconciles per controller
- Finalizers: All CRDs except Cache use finalizers for cleanup
- Field indexers: Efficient queries for owned resources
Key Relationships and Data Flow
- Requirements own Operations (unless acquired from cache)
- Operations own multiple AppDeployments
- AppDeployments own Kubernetes Jobs
- Caches own multiple Operations (for pre-provisioning)
Cache Hit Flow: Requirement → finds cached Operation → acquires it → Ready immediately Cache Miss Flow: Requirement → creates Operation → creates AppDeployments → creates Jobs → provisions resources
Common Development Commands
Building and Testing
make build- Build the manager binary (runs manifests, generate, fmt, vet first)make run- Run the controller locallymake test- Run unit tests with coverage (excludes e2e/integration)make test-integration- Run integration tests with envtest K8s API servermake test-e2e- Run end-to-end tests (requires Kind cluster)
Running Specific Tests
go test ./internal/controller/...- Run controller tests onlygo test ./internal/handler/...- Run handler tests onlygo test -run TestRequirementReconciler_Reconcile- Run specific testgo test -v ./internal/controller/requirement_controller_test.go- Run with verbose output
Code Quality
make fmt- Format Go code with gofmtmake vet- Run go vet to catch suspicious constructsmake lint- Run golangci-lint with project configuration (18 linters enabled)make lint-fix- Auto-fix linting issues where possible
Code Generation and Mocks
make generate- Generate DeepCopy methods using controller-gen v0.17.2make manifests- Generate CRDs, RBAC, and webhook configurationsgo generate ./...- Generate mocks for handler interfaces using mockgen
Docker and Deployment
make docker-build- Build Docker image (useIMG=name:tagto specify image)make docker-push- Push Docker image to registrymake install- Install CRDs into Kubernetes cluster using kustomize v5.6.0make deploy- Deploy controller to Kubernetes clustermake build-installer- Generate consolidated YAML indist/install.yaml
Key Files and Directories
api/v1alpha1/- CRD type definitions with kubebuilder markersinternal/controller/- Controller reconciler implementations (4 controllers)internal/handler/- Business logic handlers for each CRD type with mockable interfacesinternal/utils/controller/- Controller helper utilities for CRDsinternal/utils/reconciler/- Common reconciliation patterns and operation sequencinginternal/utils/rand/- Random string generation utilitiesinternal/utils/ptr/- Pointer helper utilitiesinternal/log/- Logging constants and structured logging keysconfig/- Kubernetes manifests and kustomization filestest/e2e/- End-to-end tests using sigs.k8s.io/e2e-frameworktest/integration/- Integration tests using envtesttest/utils/- Common test utilities and resource buildersdoc/arch/- Architecture documentation with detailed diagrams (6 files)
Development Environment Requirements
- Go: v1.26.0+ (as specified in go.mod and Dockerfile; toolchain pinned to go1.26.3)
- Docker: For building container images
- Kind: For running E2E tests locally
- Tools: controller-gen v0.17.2, kustomize v5.6.0, golangci-lint v2.12.2 (auto-installed via Makefile)
Testing Strategy
Test Structure
- Unit Tests: 22 test files using Ginkgo v2 + Gomega framework
- Integration Tests: Use envtest for lightweight K8s API server testing
- E2E Tests: Require Kind cluster, test full deployment lifecycle in
operation-cache-controller-systemnamespace - Mock Generation: Uses go.uber.org/mock with
//go:generate mockgendirectives
Mock Interfaces
All handler interfaces are mocked for testing:
internal/handler/mocks/mock_requirement.gointernal/handler/mocks/mock_operation.gointernal/handler/mocks/mock_cache.gointernal/handler/mocks/mock_appdeployment.go
Testing Patterns
- Controllers use envtest suite in
internal/controller/suite_test.go - Handlers are unit tested with mocked Kubernetes clients
- Coverage reports generated in
cover.out
Linting Configuration
The project uses golangci-lint with custom configuration in .golangci.yml. Key enabled linters include:
- Error handling: errcheck, staticcheck, govet
- Code quality: gocyclo, dupl, goconst, revive
- Style: gofmt, goimports, misspell
- Performance: prealloc, ineffassign
- Testing: ginkgolinter
- Go 1.22+: copyloopvar
Some linters are disabled for specific paths (api/ and internal/ have relaxed line length requirements).
Important Constants and Patterns
Labels and Annotations
operation-cache-controller.azure.github.com/cache-key- Cache key label for groupingoperation.controller.azure.com/acquired- Operation acquisition timestamp annotationoperation-cache-controller.azure.github.com/cache-mode- Cache mode annotation
Finalizers
finalizer.operation.controller.azure.com- Operation cleanup finalizerfinalizer.appdeployment.devinfra.goms.io- AppDeployment cleanup finalizer
Resource Naming Patterns
- Max length: 63 characters (Kubernetes limit)
- Format:
{type}-{hash}for generated names (e.g.,cache-a31acb88) - Operation IDs are unique across the cluster
Requeue Intervals
- Default reconciliation: 10 seconds
- Requirement check: 10 minutes
- Cache check: 60 seconds
Development Workflow
Adding New Features
- CRD Changes: Update
api/v1alpha1/*_types.gowith kubebuilder markers - Generate Code: Run
make manifests generateto update CRDs and DeepCopy methods - Handler Logic: Implement business logic in
internal/handler/with interface-first approach - Controller Updates: Update reconciler in
internal/controller/to call new handler methods - Testing: Add unit tests for handlers and integration tests for controllers
- Mocks: Run
go generate ./...to update mock interfaces
Debugging Tips
- Use structured logging with keys from
internal/log/ - Check controller metrics at
:8443/metricsendpoint - Examine finalizers if resources aren't deleting
- Review owner references for cascade deletion issues
- Check field indexes if queries are slow
RBAC Considerations
- Controllers have full CRUD on all 4 CRDs
- AppDeployment controller has full access to batch/jobs
- Metrics endpoint requires authentication
- Generated RBAC includes admin/editor/viewer roles for each CRD
Key Kubebuilder Patterns
Controller Configuration
- High concurrency: 50-100 reconciles per controller
- Field indexers for efficient child resource queries
- Named controllers with clear reconciliation strategies
- Status subresources for optimistic concurrency control
Resource Management
- Owner references enable cascade deletion
- Finalizers ensure external resource cleanup
- PrintColumns provide useful kubectl output
- Webhooks scaffolded but not currently implemented
In this repository15 other files it gives its agents.
- openspec-apply-changeSkill
- openspec-archive-changeSkill
- openspec-exploreSkill
- openspec-proposeSkill
- openspec-verify-changeSkill
- openspec-apply-changeSkill
- openspec-archive-changeSkill
- openspec-exploreSkill
- openspec-proposeSkill
- openspec-verify-changeSkill
- openspec-apply-changeSkill
- openspec-archive-changeSkill
- openspec-exploreSkill
- openspec-proposeSkill
- openspec-verify-changeSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

