|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is the Managed Node Metadata Operator for OpenShift Dedicated - a Kubernetes operator written in Go that syncs metadata (labels and taints) from MachineSets to existing Nodes. The operator watches MachineSet objects and reconciles any labels or taints to corresponding Nodes within the pool, solving the limitation where machine-api-operator doesn't reconcile metadata to existing machines. |
| 8 | + |
| 9 | +## Key Architecture |
| 10 | + |
| 11 | +- **Controller**: `controllers/machineset_controller.go` - Main controller that watches MachineSets and reconciles metadata to Machines and their referenced Nodes |
| 12 | +- **Core Logic**: `pkg/machine/machine.go` - Contains the core reconciliation logic for syncing labels and taints |
| 13 | +- **Metrics**: `pkg/metrics/metrics.go` - Prometheus metrics for operator monitoring |
| 14 | +- **Main Entry**: `main.go` - Operator entry point using controller-runtime |
| 15 | + |
| 16 | +The operator follows this reconciliation flow: |
| 17 | +1. Watch MachineSet changes |
| 18 | +2. Loop through all Machines in the MachineSet |
| 19 | +3. Sync label/taint changes from MachineSet to Machine |
| 20 | +4. Get referenced Node and sync changes from Machine to Node |
| 21 | + |
| 22 | +## Development Commands |
| 23 | + |
| 24 | +This project uses OpenShift's golang-osd-operator boilerplate convention. Key commands: |
| 25 | + |
| 26 | +### Local Development |
| 27 | +```bash |
| 28 | +# Run operator locally (uses your current kubeconfig) |
| 29 | +go run . |
| 30 | + |
| 31 | +# Run unit tests |
| 32 | +make test |
| 33 | + |
| 34 | +# Run integration tests (requires cluster and env vars) |
| 35 | +go test -count=1 ./int/ |
| 36 | + |
| 37 | +# Run linting and static analysis |
| 38 | +make lint |
| 39 | + |
| 40 | +# Run code generation and validation |
| 41 | +make validate |
| 42 | + |
| 43 | +# Build the binary |
| 44 | +make go-build |
| 45 | +``` |
| 46 | + |
| 47 | +### Testing Requirements |
| 48 | +For E2E/integration tests, these environment variables must be set: |
| 49 | +- `OCM_TOKEN` - OCM authentication token |
| 50 | +- `OCM_CLUSTER_ID` - Target cluster ID |
| 51 | +- `OCM_ENV` - Environment (stage|int) |
| 52 | + |
| 53 | +### Container/Cluster Development |
| 54 | +```bash |
| 55 | +# Build and push operator image |
| 56 | +make docker-build docker-push |
| 57 | + |
| 58 | +# Deploy to cluster (requires IMAGE_* env vars set) |
| 59 | +make deploy |
| 60 | + |
| 61 | +# Run tests in container environment (mirrors CI) |
| 62 | +make container-test |
| 63 | +make container-lint |
| 64 | +make container-validate |
| 65 | +``` |
| 66 | + |
| 67 | +### Required Environment Variables for Development |
| 68 | +```bash |
| 69 | +export REGISTRY_TOKEN=... # quay.io encrypted password |
| 70 | +export REGISTRY_USER=... # quay.io username |
| 71 | +export IMG=quay.io/$REGISTRY_USER/managed-node-metadata-operator |
| 72 | +export IMAGE_REPOSITORY=$REGISTRY_USER |
| 73 | +``` |
| 74 | + |
| 75 | +## FIPS Support |
| 76 | + |
| 77 | +This project has FIPS enabled (`FIPS_ENABLED=true` in Makefile). The `fips.go` file is auto-generated to ensure FIPS-compliant TLS configuration. |
| 78 | + |
| 79 | +## Testing |
| 80 | + |
| 81 | +- Unit tests: `make test` (excludes integration tests in `./int/`) |
| 82 | +- Integration tests: `go test ./int/` (requires cluster access and OCM env vars) |
| 83 | +- E2E tests: Located in `test/e2e/` with specific OCM requirements |
| 84 | +- Container tests: `make container-test` for CI-like environment |
| 85 | + |
| 86 | +The project uses Ginkgo/Gomega for testing framework. |
0 commit comments