Skip to content

Latest commit

 

History

History
198 lines (150 loc) · 4.28 KB

File metadata and controls

198 lines (150 loc) · 4.28 KB

Development Guide

Quick reference for developing the Managed Node Metadata.

Prerequisites

  • Go: 1.22.7 or later
  • operator-sdk: v1.21.0
  • kubectl: For cluster interaction
  • pre-commit: pip install pre-commit

Initial Setup

# 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 install

Common Commands

Build

make go-build                 # Build operator binary
make docker-build             # Build container image

Test

make go-test                  # Run all unit tests
go test ./controllers/...  # Test specific package
ginkgo -r ./controllers/      # Run controller tests with Ginkgo

Lint

make go-check                 # Full linting (golangci-lint)
pre-commit run --all-files    # Run all pre-commit hooks
pre-commit run golangci-lint  # Lint only

Code Generation

# 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 Locally

# Run against cluster in ~/.kube/config
make run

# Run with verbose logging
make run-verbose

Container-based Build

# 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 generate

Fast Local Iteration

Minimal validation loop:

# After code changes
go build ./...                # Fast compile check (~5s)
go test ./pkg/mypackage       # Run affected tests
pre-commit run                # Lint staged files

Full validation (pre-PR):

pre-commit run --all-files    # All hooks (~15-30s)
make go-test                  # Full test suite

Targeted Testing

# 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 ./...

Debugging

# Verbose operator logs
make run-verbose

# Print specific package logs
go test -v ./pkg/... 2>&1 | grep "MyFunction"

# Ginkgo verbose output
ginkgo -v ./...

Dependency Management

# 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 verify

Note: go.sum changes automatically trigger validation in pre-commit.

Architecture Pointers

  • API Types: api/v1alpha1/ - CRD definitions
  • Controllers: controllers/ - Reconciliation logic
  • Business Logic: controllers/ - Resource management
  • Tests: *_test.go alongside source, *_suite_test.go for Ginkgo
  • Mocks: pkg/util/test/generated/ - Generated mocks
  • E2E: test/e2e/ - End-to-end tests

CI Parity

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.

Boilerplate Integration

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

Troubleshooting

Mock generation fails:

# Use container-make for consistency with CI
boilerplate/_lib/container-make generate

Pre-commit hook timeout:

# macOS: Install GNU timeout
brew install coreutils

# Linux: timeout is built-in

go.sum checksum mismatch:

export GOPROXY="https://proxy.golang.org"
go mod tidy

Tests fail locally but pass in CI:

# Use container environment
boilerplate/_lib/container-make go-test

Further Reading