Overview
This guide covers the development workflow for contributing to the Forkspacer operator, including setting up your development environment, building, testing, and running the operator locally.
Prerequisites
Section titled “Prerequisites”Before you begin development, ensure you have the following tools installed:
- Go (v1.24 or later) - The operator is written in Go
- Docker or Podman - For building container images
- kubectl (v1.20 or later) - Kubernetes command-line tool
- Kind (Kubernetes in Docker) - Recommended for local development
- Git - Version control
Getting Started
Section titled “Getting Started”1. Clone the Repository
Section titled “1. Clone the Repository”git clone https://github.com/forkspacer/forkspacer.gitcd forkspacer/forkspacer2. Install Dependencies
Section titled “2. Install Dependencies”The project uses Go modules. Dependencies will be downloaded automatically, but you can explicitly install them:
go mod download3. Install Development Tools
Section titled “3. Install Development Tools”The Makefile will automatically install required tools (controller-gen, kustomize, etc.) when needed. These tools are installed in the local bin/ directory:
make help # View available commandsCommon Development Workflows
Section titled “Common Development Workflows”Running the Operator
Section titled “Running the Operator”Option 1: Run on Host (Quick Testing)
Section titled “Option 1: Run on Host (Quick Testing)”For rapid iteration, run the operator directly on your host machine:
# First, install CRDs if not already installedmake install
# Run the operator on your hostmake dev-hostThis runs the operator against your current kubeconfig context. It’s useful for:
- Quick testing of controller logic
- Debugging with your IDE
- Fast iteration without image builds
Important Notes:
- Webhooks are disabled - The operator runs with
ENABLE_WEBHOOKS=false, so validation and defaulting webhooks won’t be active - Use
localconnection type - When creating Workspaces in dev-host mode, usetype: localinstead oftype: in-clusterfor the connection configuration - Your kubeconfig must point to a running cluster (Kind, minikube, etc.)
Example Workspace for dev-host mode:
apiVersion: batch.forkspacer.com/v1kind: Workspacemetadata: name: dev-workspace namespace: defaultspec: type: kubernetes connection: type: local # Use 'local' when running with dev-host secretReference: name: localOption 2: Run in Kind Cluster (Recommended)
Section titled “Option 2: Run in Kind Cluster (Recommended)”For a complete, isolated development environment, use Kind:
make dev-kindThis will:
- Delete any existing
operator-devKind cluster - Create a fresh Kind cluster
- Install cert-manager
- Install CRDs
- Build the operator image
- Load the image into Kind
- Deploy the operator
Benefits of Kind Development:
- Isolated environment that won’t affect other clusters
- Tests the full deployment process
- Validates webhook configurations
- Mimics production deployment
Cleanup:
make cleanup-dev-kindCode Generation
Section titled “Code Generation”When you modify API types (api/v1/*.go), you need to regenerate manifests and code:
# Generate CRDs, RBAC, and webhook configurationsmake manifests
# Generate DeepCopy, DeepCopyInto, and DeepCopyObject methodsmake generateThese commands use controller-gen and are automatically run as part of make build.
Code Quality
Section titled “Code Quality”Format Code
Section titled “Format Code”make fmtRun Static Analysis
Section titled “Run Static Analysis”make vetRun Linter
Section titled “Run Linter”# Run golangci-lintmake lint
# Run linter with auto-fixmake lint-fix
# Verify linter configurationmake lint-configTesting
Section titled “Testing”Unit Tests
Section titled “Unit Tests”Run unit tests with coverage:
make testThis runs all tests except e2e tests and generates a coverage report in cover.out.
End-to-End Tests
Section titled “End-to-End Tests”E2E tests run against a real Kubernetes cluster (Kind):
make test-e2eThis will:
- Create a Kind cluster named
operator-test-e2e(if it doesn’t exist) - Run e2e tests using Ginkgo
- Clean up the Kind cluster after tests complete
Manual cleanup (if needed):
make cleanup-test-e2eDeploying to a Cluster
Section titled “Deploying to a Cluster”Install CRDs Only
Section titled “Install CRDs Only”make installDeploy the Operator
Section titled “Deploy the Operator”# Build imagemake docker-build IMG=myregistry/forkspacer:dev
# Load into Kind (if using Kind)kind load docker-image myregistry/forkspacer:dev -n operator-dev
# Deploy to clustermake deploy IMG=myregistry/forkspacer:devUndeploy the Operator
Section titled “Undeploy the Operator”make undeployUninstall CRDs
Section titled “Uninstall CRDs”make uninstallBuilding Release Artifacts
Section titled “Building Release Artifacts”Generate Installation Manifest
Section titled “Generate Installation Manifest”Create a consolidated YAML for installation:
make build-installerThis generates dist/install.yaml containing all CRDs and deployment manifests.
Multi-Platform Build
Section titled “Multi-Platform Build”Build and push images for multiple architectures:
make docker-buildx IMG=myregistry/forkspacer:v1.0.0Platforms: linux/arm64, linux/amd64, linux/s390x, linux/ppc64le
Development Tips
Section titled “Development Tips”Debugging
Section titled “Debugging”-
Enable verbose logging: Set environment variable before running:
Terminal window export LOG_LEVEL=debugmake dev-host -
Use delve for debugging:
Terminal window dlv debug ./cmd/main.go -
Check operator logs in cluster:
Terminal window kubectl logs -n forkspacer-system deployment/forkspacer-controller-manager -f
Rapid Iteration
Section titled “Rapid Iteration”For the fastest development cycle:
- Run operator on host:
make dev-host - Make code changes
- Stop the operator (Ctrl+C)
- Run
make manifests generateif you changed API types - Restart with
make dev-host
Working with Webhooks
Section titled “Working with Webhooks”Webhooks require TLS certificates, which makes local development challenging. When running on host:
- Webhooks are disabled by default in
dev-hostmode - Use
dev-kindto test webhook functionality - Webhook code is in
internal/webhook/
Version Management
Section titled “Version Management”The version is controlled by variables in the Makefile:
VERSION ?= v0.1.3To build with a custom version:
make build VERSION=v0.2.0-devContributing Workflow
Section titled “Contributing Workflow”- Fork the repository on GitHub
- Create a feature branch:
Terminal window git checkout -b feature/my-new-feature - Make your changes following the project structure
- Run tests and linting:
Terminal window make test lint - Commit your changes with clear commit messages
- Push to your fork:
Terminal window git push origin feature/my-new-feature - Open a Pull Request on GitHub
Next Steps
Section titled “Next Steps”- Custom Module Development - Learn how to create custom modules
- API Reference - Understand the CRD specifications