Quick reference for developing the Managed Node Metadata.
- Go: 1.22.7 or later
- operator-sdk: v1.21.0
- kubectl: For cluster interaction
- pre-commit:
pip install pre-commit
# Clone repository
git clone https://github.com/openshift/managed-node-metadata-operator.git
cd managed-node-metadata-operator
# Install development tools
make tools
# Install pre-commit hooks
pre-commit installmake go-build # Build operator binary
make docker-build # Build container imagemake go-test # Run all unit tests
go test ./controllers/... # Test specific package
ginkgo -r ./controllers/ # Run controller tests with Ginkgomake go-check # Full linting (golangci-lint)
pre-commit run --all-files # Run all pre-commit hooks
pre-commit run golangci-lint # Lint only# After modifying API types (api/v1alpha1/*.go)
# or interfaces requiring mocks
boilerplate/_lib/container-make generate
# What this generates:
# - Deepcopy methods (zz_generated.deepcopy.go)
# - OpenAPI schemas
# - Mock interfaces for testing# Run against cluster in ~/.kube/config
make run
# Run with verbose logging
make run-verbose# Run make targets inside boilerplate container
# (ensures consistent environment with CI)
boilerplate/_lib/container-make
boilerplate/_lib/container-make go-test
boilerplate/_lib/container-make generateMinimal validation loop:
# After code changes
go build ./... # Fast compile check (~5s)
go test ./pkg/mypackage # Run affected tests
pre-commit run # Lint staged filesFull validation (pre-PR):
pre-commit run --all-files # All hooks (~15-30s)
make go-test # Full test suite# Run specific test
ginkgo -focus="NetworkPolicy" ./controllers/
# Run tests for one package
go test -v ./controllers/
# Skip slow tests during development
ginkgo -skip="E2E" -r ./...# Verbose operator logs
make run-verbose
# Print specific package logs
go test -v ./pkg/... 2>&1 | grep "MyFunction"
# Ginkgo verbose output
ginkgo -v ./...# Add new dependency
go get github.com/some/package@v1.2.3
# Update dependency
go get -u github.com/some/package
# Tidy (removes unused, adds missing)
go mod tidy
# Verify checksums
go mod verifyNote: go.sum changes automatically trigger validation in pre-commit.
- API Types:
api/v1alpha1/- CRD definitions - Controllers:
controllers/- Reconciliation logic - Business Logic:
controllers/- Resource management - Tests:
*_test.goalongside source,*_suite_test.gofor Ginkgo - Mocks:
pkg/util/test/generated/- Generated mocks - E2E:
test/e2e/- End-to-end tests
Local pre-commit hooks mirror Tekton CI checks:
- go-check ↔ Tekton lint job
- go-build ↔ Compilation in CI
- go-test ↔ Unit test job
- gitleaks ↔ Security scanning
Run pre-commit run --all-files before pushing to catch CI failures early.
This repo uses Red Hat's standardized boilerplate:
- Centralized Makefiles:
boilerplate/openshift/golang-osd-operator/ - Standard targets:
go-build,go-check,go-test - Container builds:
boilerplate/_lib/container-make - Update boilerplate:
make boilerplate-update
Mock generation fails:
# Use container-make for consistency with CI
boilerplate/_lib/container-make generatePre-commit hook timeout:
# macOS: Install GNU timeout
brew install coreutils
# Linux: timeout is built-ingo.sum checksum mismatch:
export GOPROXY="https://proxy.golang.org"
go mod tidyTests fail locally but pass in CI:
# Use container environment
boilerplate/_lib/container-make go-test