Skip to content

Commit e6e39e5

Browse files
authored
Bump golang version and claude (#37)
* chore: update Go version to 1.24 and bump Docker base image to 1.24 * fix * chore: update golangci-lint version to v1.64.8 in workflow and Makefile
1 parent 583d900 commit e6e39e5

File tree

5 files changed

+157
-31
lines changed

5 files changed

+157
-31
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
- name: Run linter
2121
uses: golangci/golangci-lint-action@v6
2222
with:
23-
version: v1.63.4
23+
version: v1.64.8

CLAUDE.md

Lines changed: 152 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,192 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
The Operation Cache Controller is a Kubernetes operator built with kubebuilder 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.
7+
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.
88

99
## Architecture
1010

11-
The controller manages four main Custom Resource Definitions (CRDs):
11+
The controller manages four main Custom Resource Definitions (CRDs) in the `controller.azure.github.com` API group:
1212

13-
1. **Requirement** - User-defined specifications for required applications and their configurations
13+
1. **Requirement** - User-defined specifications for required applications with optional caching
1414
2. **Operation** - Represents the deployment operation based on requirements
1515
3. **AppDeployment** - Manages provision and teardown jobs for actual resource deployment
1616
4. **Cache** - Stores pre-provisioned resources with cache duration and auto-count features
1717

18+
### Controller Architecture Pattern
19+
20+
The project follows a **handler-based reconciliation pattern** with clear separation of concerns:
21+
22+
```
23+
Controller (Reconciler) → Handler Interface → Handler Implementation
24+
25+
Helper Utilities
26+
```
27+
1828
The main reconcilers are located in `internal/controller/`:
1929
- `RequirementReconciler` - Creates Cache and Operation CRs from Requirement specs
20-
- `OperationReconciler` - Creates/deletes AppDeployment CRs from Operation specs
30+
- `OperationReconciler` - Creates/deletes AppDeployment CRs from Operation specs
2131
- `AppDeploymentReconciler` - Creates provision/teardown Kubernetes Jobs
2232
- `CacheReconciler` - Manages cached resource lifecycle
2333

34+
Each controller uses:
35+
- **Sequential operations**: Reconciliation operations are executed in order using `internal/utils/reconciler/operations.go`
36+
- **Handler interfaces**: Business logic is separated into mockable handler interfaces in `internal/handler/`
37+
- **High concurrency**: 50-100 concurrent reconciles per controller
38+
- **Finalizers**: All CRDs except Cache use finalizers for cleanup
39+
- **Field indexers**: Efficient queries for owned resources
40+
41+
### Key Relationships and Data Flow
42+
43+
- **Requirements** own **Operations** (unless acquired from cache)
44+
- **Operations** own multiple **AppDeployments**
45+
- **AppDeployments** own Kubernetes **Jobs**
46+
- **Caches** own multiple **Operations** (for pre-provisioning)
47+
48+
**Cache Hit Flow**: Requirement → finds cached Operation → acquires it → Ready immediately
49+
**Cache Miss Flow**: Requirement → creates Operation → creates AppDeployments → creates Jobs → provisions resources
50+
2451
## Common Development Commands
2552

2653
### Building and Testing
2754
- `make build` - Build the manager binary (runs manifests, generate, fmt, vet first)
2855
- `make run` - Run the controller locally
29-
- `make test` - Run unit tests with coverage
30-
- `make test-integration` - Run integration tests
56+
- `make test` - Run unit tests with coverage (excludes e2e/integration)
57+
- `make test-integration` - Run integration tests with envtest K8s API server
3158
- `make test-e2e` - Run end-to-end tests (requires Kind cluster)
3259

60+
### Running Specific Tests
61+
- `go test ./internal/controller/...` - Run controller tests only
62+
- `go test ./internal/handler/...` - Run handler tests only
63+
- `go test -run TestRequirementReconciler_Reconcile` - Run specific test
64+
- `go test -v ./internal/controller/requirement_controller_test.go` - Run with verbose output
65+
3366
### Code Quality
34-
- `make fmt` - Format Go code
35-
- `make vet` - Run go vet
36-
- `make lint` - Run golangci-lint with project configuration
67+
- `make fmt` - Format Go code with gofmt
68+
- `make vet` - Run go vet to catch suspicious constructs
69+
- `make lint` - Run golangci-lint with project configuration (18 linters enabled)
3770
- `make lint-fix` - Auto-fix linting issues where possible
3871

39-
### Code Generation
40-
- `make generate` - Generate DeepCopy methods using controller-gen
72+
### Code Generation and Mocks
73+
- `make generate` - Generate DeepCopy methods using controller-gen v0.17.2
4174
- `make manifests` - Generate CRDs, RBAC, and webhook configurations
75+
- `go generate ./...` - Generate mocks for handler interfaces using mockgen
4276

4377
### Docker and Deployment
4478
- `make docker-build` - Build Docker image (use `IMG=name:tag` to specify image)
4579
- `make docker-push` - Push Docker image to registry
46-
- `make install` - Install CRDs into Kubernetes cluster
80+
- `make install` - Install CRDs into Kubernetes cluster using kustomize v5.6.0
4781
- `make deploy` - Deploy controller to Kubernetes cluster
4882
- `make build-installer` - Generate consolidated YAML in `dist/install.yaml`
4983

5084
## Key Files and Directories
5185

52-
- `api/v1alpha1/` - CRD type definitions
53-
- `internal/controller/` - Controller reconciler implementations
54-
- `internal/handler/` - Business logic handlers for each CRD type
55-
- `internal/utils/controller/` - Controller helper utilities
86+
- `api/v1alpha1/` - CRD type definitions with kubebuilder markers
87+
- `internal/controller/` - Controller reconciler implementations (4 controllers)
88+
- `internal/handler/` - Business logic handlers for each CRD type with mockable interfaces
89+
- `internal/utils/controller/` - Controller helper utilities for CRDs
90+
- `internal/utils/reconciler/` - Common reconciliation patterns and operation sequencing
91+
- `internal/utils/rand/` - Random string generation utilities
92+
- `internal/utils/ptr/` - Pointer helper utilities
93+
- `internal/log/` - Logging constants and structured logging keys
5694
- `config/` - Kubernetes manifests and kustomization files
57-
- `doc/arch/` - Architecture documentation with detailed diagrams
58-
59-
## Testing Requirements
60-
61-
- Unit tests must be written for new functionality
62-
- Integration tests validate controller behavior with Kubernetes API
63-
- E2E tests require a running Kind cluster
64-
- All tests must pass before submitting changes
65-
- Coverage reports are generated in `cover.out`
95+
- `test/e2e/` - End-to-end tests using sigs.k8s.io/e2e-framework
96+
- `test/integration/` - Integration tests using envtest
97+
- `test/utils/` - Common test utilities and resource builders
98+
- `doc/arch/` - Architecture documentation with detailed diagrams (6 files)
99+
100+
## Development Environment Requirements
101+
102+
- **Go**: v1.24.0+ (as specified in go.mod and Dockerfile)
103+
- **Docker**: For building container images
104+
- **Kind**: For running E2E tests locally
105+
- **Tools**: controller-gen v0.17.2, kustomize v5.6.0, golangci-lint v1.63.4 (auto-installed via Makefile)
106+
107+
## Testing Strategy
108+
109+
### Test Structure
110+
- **Unit Tests**: 22 test files using Ginkgo v2 + Gomega framework
111+
- **Integration Tests**: Use envtest for lightweight K8s API server testing
112+
- **E2E Tests**: Require Kind cluster, test full deployment lifecycle in `operation-cache-controller-system` namespace
113+
- **Mock Generation**: Uses go.uber.org/mock with `//go:generate mockgen` directives
114+
115+
### Mock Interfaces
116+
All handler interfaces are mocked for testing:
117+
- `internal/handler/mocks/mock_requirement.go`
118+
- `internal/handler/mocks/mock_operation.go`
119+
- `internal/handler/mocks/mock_cache.go`
120+
- `internal/handler/mocks/mock_appdeployment.go`
121+
122+
### Testing Patterns
123+
- Controllers use envtest suite in `internal/controller/suite_test.go`
124+
- Handlers are unit tested with mocked Kubernetes clients
125+
- Coverage reports generated in `cover.out`
66126

67127
## Linting Configuration
68128

69-
The project uses golangci-lint with custom configuration in `.golangci.yml`. Key enabled linters include errcheck, gofmt, goimports, govet, staticcheck, and others. Some linters are disabled for specific paths (api/ and internal/ directories have relaxed line length requirements).
129+
The project uses golangci-lint with custom configuration in `.golangci.yml`. Key enabled linters include:
130+
- **Error handling**: errcheck, staticcheck, govet
131+
- **Code quality**: gocyclo, dupl, goconst, revive
132+
- **Style**: gofmt, goimports, misspell
133+
- **Performance**: prealloc, ineffassign
134+
- **Testing**: ginkgolinter
135+
- **Go 1.22+**: copyloopvar
136+
137+
Some linters are disabled for specific paths (api/ and internal/ have relaxed line length requirements).
138+
139+
## Important Constants and Patterns
140+
141+
### Labels and Annotations
142+
- `operation-cache-controller.azure.github.com/cache-key` - Cache key label for grouping
143+
- `operation.controller.azure.com/acquired` - Operation acquisition timestamp annotation
144+
- `operation-cache-controller.azure.github.com/cache-mode` - Cache mode annotation
145+
146+
### Finalizers
147+
- `finalizer.operation.controller.azure.com` - Operation cleanup finalizer
148+
- `finalizer.appdeployment.devinfra.goms.io` - AppDeployment cleanup finalizer
149+
150+
### Resource Naming Patterns
151+
- Max length: 63 characters (Kubernetes limit)
152+
- Format: `{type}-{hash}` for generated names (e.g., `cache-a31acb88`)
153+
- Operation IDs are unique across the cluster
154+
155+
### Requeue Intervals
156+
- Default reconciliation: 10 seconds
157+
- Requirement check: 10 minutes
158+
- Cache check: 60 seconds
159+
160+
## Development Workflow
161+
162+
### Adding New Features
163+
1. **CRD Changes**: Update `api/v1alpha1/*_types.go` with kubebuilder markers
164+
2. **Generate Code**: Run `make manifests generate` to update CRDs and DeepCopy methods
165+
3. **Handler Logic**: Implement business logic in `internal/handler/` with interface-first approach
166+
4. **Controller Updates**: Update reconciler in `internal/controller/` to call new handler methods
167+
5. **Testing**: Add unit tests for handlers and integration tests for controllers
168+
6. **Mocks**: Run `go generate ./...` to update mock interfaces
169+
170+
### Debugging Tips
171+
- Use structured logging with keys from `internal/log/`
172+
- Check controller metrics at `:8443/metrics` endpoint
173+
- Examine finalizers if resources aren't deleting
174+
- Review owner references for cascade deletion issues
175+
- Check field indexes if queries are slow
176+
177+
### RBAC Considerations
178+
- Controllers have full CRUD on all 4 CRDs
179+
- AppDeployment controller has full access to batch/jobs
180+
- Metrics endpoint requires authentication
181+
- Generated RBAC includes admin/editor/viewer roles for each CRD
182+
183+
## Key Kubebuilder Patterns
184+
185+
### Controller Configuration
186+
- High concurrency: 50-100 reconciles per controller
187+
- Field indexers for efficient child resource queries
188+
- Named controllers with clear reconciliation strategies
189+
- Status subresources for optimistic concurrency control
190+
191+
### Resource Management
192+
- Owner references enable cascade deletion
193+
- Finalizers ensure external resource cleanup
194+
- PrintColumns provide useful kubectl output
195+
- Webhooks scaffolded but not currently implemented

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.23 AS builder
2+
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.24 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.17.2
182182
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
183183
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
184184
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
185-
GOLANGCI_LINT_VERSION ?= v1.63.4
185+
GOLANGCI_LINT_VERSION ?= v1.64.8
186186

187187
.PHONY: kustomize
188188
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/Azure/operation-cache-controller
22

3-
go 1.23.0
3+
go 1.24.0
44

5-
godebug default=go1.23
5+
godebug default=go1.24
66

77
require (
88
github.com/go-logr/logr v1.4.2

0 commit comments

Comments
 (0)