Skip to content

Contributing

Development Setup

Clone the repository and ensure you have the prerequisites installed.

git clone https://github.com/dsp0x4/cloudfront-tenant-operator.git
cd cloudfront-tenant-operator

Common Commands

# Run unit tests (uses envtest: real K8s API server + etcd, mock AWS client)
make test

# Run linter
make lint

# Auto-fix lint issues
make lint-fix

# Regenerate CRD manifests and DeepCopy methods after editing *_types.go
make manifests generate

# Install CRDs
make install

# Run the operator locally against your current kubeconfig
make run

Test Structure

Tests use Ginkgo + Gomega (BDD style):

  • internal/controller/distributiontenant_controller_test.go -- Integration tests using envtest (real K8s API) with a mock AWS client.
  • internal/controller/change_detection_test.go -- Unit tests for the three-way diff and drift policy logic.
  • internal/aws/errors_test.go -- Unit tests for AWS error classification.
  • test/e2e/e2e_test.go -- End-to-end tests designed to run against an isolated Kind cluster.

Warning

The e2e tests require a dedicated Kind cluster. Do not run them against a real cluster.

After Editing Types

If you modify any *_types.go file or kubebuilder markers, always run:

make manifests generate

This regenerates:

  • config/crd/bases/*.yaml -- CRD manifests
  • config/rbac/role.yaml -- RBAC rules from +kubebuilder:rbac markers
  • **/zz_generated.deepcopy.go -- DeepCopy methods

Do not edit these generated files manually.

Code Style

  • Use log := log.FromContext(ctx) for structured logging.
  • Keep reconciliation idempotent: safe to run multiple times.
  • At most one K8s API write per reconcile loop (see ResourceVersion Safety).
  • Use owner references for automatic garbage collection.
  • Wrap errors with context: fmt.Errorf("failed to X: %w", err).