Development Guide
Developer guide for building and testing Lynq locally. Covers prerequisites, local cluster setup, build commands, and E2E tests.
Build, test, and iterate on Lynq locally. Covers prerequisites, cluster setup, make targets, and E2E test execution against a live Kind cluster.
First time here?
Start with the Quick Start guide to get familiar with the system before diving into development tooling.
Setup
Prerequisites
| Tool | Version / Notes |
|---|---|
| Go | 1.22+ |
| kubectl | Matches target cluster |
| kind or minikube | Local cluster for testing |
| Docker | Required for image builds |
| make | Used for build/test helpers |
Clone Repository
git clone https://github.com/k8s-lynq/lynq.git
cd lynqInstall Dependencies
go mod downloadLocal Development
Running Locally
# Install CRDs
make install
# Run controller locally (uses ~/.kube/config)
make run
# Run with debug logging
LOG_LEVEL=debug make runLocal Run Limitations
make run runs the operator outside the cluster, which means:
- ⚠️ Webhooks are NOT available (no TLS certificates)
- ⚠️ No validation at admission time (invalid configs will only fail at reconciliation)
- ⚠️ No defaulting (all fields must be specified explicitly)
For complete testing with webhooks, deploy to cluster with cert-manager:
# See Local Development with Minikube guide
./scripts/deploy-to-minikube.sh # Includes cert-manager and webhooksWhen to use make run:
- Quick iteration on controller logic
- Testing reconciliation loops
- Debugging without webhook complications
When to deploy to cluster:
- Testing webhooks (validation/defaulting)
- Final testing before committing
- Verifying production-like behavior
Testing Against Local Cluster
# Create kind cluster
kind create cluster --name lynq-dev
# Install CRDs
make install
# Run operator
make runBuilding
Build Binary
# Build for current platform
make build
# Binary output: bin/manager
./bin/manager --helpBuild Container Image
# Build image
make docker-build IMG=myregistry/lynq:dev
# Push image
make docker-push IMG=myregistry/lynq:dev
# Build multi-platform
docker buildx build --platform linux/amd64,linux/arm64 \
-t myregistry/lynq:dev \
--push .Testing
Unit Tests
# Run all unit tests
make test
# Run with coverage (generate cover.out, then view)
go test ./... -coverprofile=cover.out
go tool cover -html=cover.outIntegration / E2E Tests
# Run full E2E suite (30-45 minutes, creates Kind cluster)
make test-e2e
# Run a single focused test (3-5 minutes)
make test-e2e-focus FOCUS="<test description substring>"Cluster required
Integration and E2E suites create and mutate Kubernetes resources. Run them against disposable clusters.
E2E Tests
End-to-End tests run against a real Kubernetes cluster (Kind) to validate complete scenarios.
Test Strategy
Lynq uses a 3-tier testing approach:
| Test Type | Environment | Speed | Use Case |
|---|---|---|---|
| Unit | fake client | Very Fast (seconds) | Logic validation, TDD |
| Integration | envtest | Fast (seconds-minutes) | Controller behavior |
| E2E | Kind cluster | Slower (minutes) | Real scenarios, policies |
When to use E2E tests:
- Testing actual Kubernetes behavior (ownerReferences, labels, etc.)
- Validating policy behaviors (CreationPolicy, DeletionPolicy)
- End-to-end workflows with multiple resources
- CI/CD validation before release
Prerequisites
# Install Kind (required for E2E tests)
# macOS
brew install kind
# Linux
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
# Verify installation
kind versionQuick Start
# Run all E2E tests (creates cluster, runs tests, cleans up)
make test-e2e
# This will:
# 1. Create Kind cluster "lynq-test-e2e"
# 2. Build and load operator image
# 3. Install CRDs and deploy operator
# 4. Run all E2E tests (including policy tests)
# 5. Delete clusterRunning Specific Tests
# Setup cluster once
make setup-test-e2e
# Run specific test suites
go test ./test/e2e/ -v -ginkgo.focus="Policy Behaviors" # Policy tests only
go test ./test/e2e/ -v -ginkgo.focus="CreationPolicy" # Creation policy only
go test ./test/e2e/ -v -ginkgo.focus="DeletionPolicy" # Deletion policy only
# Cleanup when done
make cleanup-test-e2eDevelopment Workflow (Fast Iteration)
For rapid development cycles, reuse the cluster:
# 1. Create cluster once
make setup-test-e2e
# 2. Make code changes, then:
make docker-build IMG=example.com/lynq:v0.0.1
kind load docker-image example.com/lynq:v0.0.1 --name lynq-test-e2e
kubectl rollout restart deployment lynq-controller-manager -n lynq-system
# 3. Run tests
go test ./test/e2e/ -v -ginkgo.focus="Policy"
# 4. Repeat steps 2-3 as needed
# 5. Cleanup when done
make cleanup-test-e2eWriting BDD E2E Tests
Policy E2E tests use Ginkgo BDD framework with Given-When-Then pattern:
// test/e2e/policy_e2e_test.go
var _ = Describe("Policy Behaviors", func() {
Context("CreationPolicy", func() {
It("should create resource only once with Once policy", func() {
// Given: A LynqNode with CreationPolicy=Once
By("creating LynqNode with Once policy")
createLynqNode(nodeYAML)
// When: ConfigMap is created
By("verifying ConfigMap has created-once annotation")
Eventually(func() string {
return getAnnotation(cmName, "lynq.sh/created-once")
}, timeout).Should(Equal("true"))
// And: Update spec to change data
By("updating LynqNode spec")
updateLynqNode(updatedYAML)
// Then: ConfigMap should NOT be updated
By("verifying ConfigMap data remains unchanged")
Consistently(func() string {
return getConfigMapData(cmName, "key")
}, "30s", "5s").Should(Equal("initial-value"))
})
})
})Key patterns:
- Use
By()for clear test steps (Given-When-Then) - Use
Eventually()for async operations (resource creation, updates) - Use
Consistently()to verify state doesn't change - Use
BeforeEach/AfterEachfor setup/cleanup
Troubleshooting E2E Tests
# Test timeout - check pod status
kubectl get pods -n lynq-system
kubectl logs -n lynq-system deployment/lynq-controller-manager
# Cluster stuck - force cleanup
kind delete cluster --name lynq-test-e2e
# Image not loaded - verify
docker exec -it lynq-test-e2e-control-plane crictl images | grep lynq
# Namespace stuck - remove finalizers
kubectl patch ns policy-test -p '{"metadata":{"finalizers":[]}}' --type=mergeCI/CD Integration
E2E tests run automatically in GitHub Actions:
# .github/workflows/test-e2e.yml
# Triggers on: push, pull_request
# Runs: make test-e2eTests run in CI on:
- Every push to main/master
- Every pull request
- Manual workflow dispatch
Code Quality
Linting
# Run linter
make lint
# Auto-fix issues
golangci-lint run --fixFormatting
# Format code
go fmt ./...
# Or use goimports
goimports -w .Generate Code
# Generate CRD manifests, RBAC, etc.
make generate
# Generate DeepCopy methods
make manifestsProject Structure
lynq/
├── api/v1/ # CRD types
│ ├── lynqnode_types.go
│ ├── lynqhub_types.go
│ ├── lynqform_types.go
│ └── common_types.go
├── internal/controller/ # Controllers
│ ├── lynqnode_controller.go
│ ├── lynqhub_controller.go
│ └── lynqform_controller.go
├── internal/apply/ # SSA apply engine
├── internal/database/ # Database connectors
├── internal/graph/ # Dependency graph
├── internal/readiness/ # Readiness checks
├── internal/template/ # Template engine
├── internal/metrics/ # Prometheus metrics
├── config/ # Kustomize configs
│ ├── crd/ # CRD manifests
│ ├── rbac/ # RBAC configs
│ ├── manager/ # Deployment configs
│ └── samples/ # Example CRs
├── test/ # Tests
│ ├── e2e/ # E2E tests
│ └── utils/ # Test utilities
├── docs/ # Documentation
└── cmd/ # Entry pointAdding Features
New CRD Field
- Update API types:
// api/v1/lynqnode_types.go
type LynqNodeSpec struct {
NewField string `json:"newField,omitempty"`
}- Generate code:
make generate
make manifests-
Update controller logic
-
Add tests
-
Update documentation
New Controller
- Create controller file:
// internal/controller/myresource_controller.go
package controller
type MyResourceReconciler struct {
client.Client
Scheme *runtime.Scheme
}
func (r *MyResourceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
// Implementation
}- Register controller:
// cmd/main.go
if err = (&controller.MyResourceReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
// Handle error
}- Add tests
Adding a New Datasource
Lynq uses a pluggable adapter pattern. To add support for a new database, implement the Datasource interface in internal/datasource/, register it in the factory, and add API types in api/v1/lynqhub_types.go. The MySQL adapter (internal/datasource/mysql.go) is the reference implementation to copy from.
For the full step-by-step guide, see Contributing a New Datasource.
Contributing
Contribution checklist
Always include tests, update docs, and run make lint before opening a pull request.
Workflow
- Fork repository
- Create feature branch
- Make changes
- Add tests
- Run linter:
make lint - Run tests:
make test - Commit with conventional commits
- Open Pull Request
Conventional Commits
feat: add new feature
fix: fix bug
docs: update documentation
test: add tests
refactor: refactor code
chore: maintenance tasksPull Request Template
## Description
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] Tests passingRelease Process
Release automation
Tags trigger the release pipeline. Confirm CI is green before pushing a new tag.
Version Bump
-
Update version in:
README.mdconfig/manager/kustomization.yaml
-
Generate changelog
-
Create git tag:
git tag -a v1.1.0 -m "Release v1.1.0"
git push origin v1.1.0- GitHub Actions builds and publishes release
Useful Commands
# Install CRDs
make install
# Uninstall CRDs
make uninstall
# Deploy operator
make deploy IMG=<image>
# Undeploy operator
make undeploy
# Run locally
make run
# Build binary
make build
# Build container
make docker-build IMG=<image>
# Run tests
make test
# Run linter
make lint
# Generate code
make generate manifestsSee Also
Local Development with Minikube
Covers building Lynq from source, running against a live Minikube cluster with webhooks enabled, and wiring up a local MySQL datasource for end-to-end testing.
Just trying it out?
Follow the Quick Start guide instead — it uses pre-built images and takes 5 minutes.
Overview
This guide covers the development workflow for making code changes to Lynq and testing them locally on Minikube.
Use this guide when you want to:
- ✅ Modify Lynq source code
- ✅ Add new features or fix bugs
- ✅ Test code changes locally before committing
- ✅ Debug the operator with breakpoints
- ✅ Iterate quickly on code changes
For initial setup: Follow the Quick Start guide first to set up your Minikube environment.
Prerequisites
Prerequisites
Complete the Quick Start guide first. You should have:
- ✅ Minikube cluster running (
lynqprofile) - ✅ cert-manager installed (automatically by setup script)
- ✅ Lynq deployed with webhooks enabled
- ✅ MySQL test database (optional, for full testing)
cert-manager Required
cert-manager is REQUIRED for all installations. The automated setup scripts install it automatically. If setting up manually, install cert-manager before deploying the operator.
Additional development tools:
- Go 1.22+
- make
- golangci-lint (optional, for linting)
- delve (optional, for debugging)
Development Workflow
Typical Development Cycle
# 1. Make code changes
vim internal/controller/lynqnode_controller.go
# 2. Run unit tests
make test
# 3. Run linter
make lint
# 4. Build and deploy to Minikube
./scripts/deploy-to-minikube.sh
# 5. View operator logs
kubectl logs -n lynq-system -l control-plane=controller-manager -f
# 6. Test changes
kubectl apply -f config/samples/
# 7. Verify results
kubectl get lynqnodes
kubectl get all -n node-<uid>
# 8. Repeat steps 1-7 as neededIteration speed
Expect roughly 1–2 minutes per build + deploy cycle when using the provided scripts.
Code Changes & Rebuilding
Quick Rebuild and Deploy
After making code changes:
# Rebuild and redeploy operator
./scripts/deploy-to-minikube.shThis script:
- Builds new Docker image with timestamp tag
- Loads image into Minikube's internal registry
- Updates operator deployment
- Waits for readiness
Why timestamp tags? Each deployment gets a unique tag, preventing Kubernetes from using cached old images.
Custom Image Tag
Use a custom tag for easier identification:
IMG=lynq:my-feature ./scripts/deploy-to-minikube.shManual Build (if needed)
# Build binary locally
make build
# Build Docker image
make docker-build IMG=lynq:dev
# Load into Minikube
minikube -p lynq image load lynq:devRunning Operator Locally (Outside Cluster)
For fastest iteration, run the operator locally on your machine while connecting to the Minikube cluster:
# Ensure CRDs are installed
make install
# Run operator locally
make runBenefits
- ✅ Instant restarts (no image build/load)
- ✅ Direct Go debugging with breakpoints
- ✅ Real-time logs in your terminal
- ✅ Fast feedback loop (~5 seconds)
Limitations
- ⚠️ Webhooks unavailable (TLS certificates require in-cluster deployment with cert-manager)
- ⚠️ No validation at admission time (changes are only validated at reconciliation)
- ⚠️ No automatic defaulting (must specify all fields manually)
- ⚠️ Runtime differs from production environment
When to use:
- Controller logic changes
- Quick iteration on reconciliation loops
- Debugging with delve
When NOT to use:
- Testing webhooks (requires full deployment with cert-manager)
- Testing validation/defaulting behavior
- Verifying in-cluster networking
- Final testing before PR
Testing with Webhooks
For complete testing including webhooks, always deploy to cluster:
./scripts/deploy-to-minikube.sh # Includes cert-manager and webhooksTesting with local run:
# Terminal 1: Run operator
make run
# Terminal 2: Apply resources
kubectl apply -f config/samples/
kubectl get lynqnodes --watch
# Terminal 3: View database changes
# deploy-mysql.sh seeds lynq_demo.tenants (override via MYSQL_DATABASE).
kubectl exec -it deployment/mysql -n lynq-test -- \
mysql -u node_reader -p lynq_demo -e "SELECT * FROM tenants;"Debugging
Debug with Delve
Run operator with debugger:
# Install delve if needed
go install github.com/go-delve/delve/cmd/dlv@latest
# Run with delve
dlv debug ./cmd/main.go -- --zap-devel=trueThen in delve:
(dlv) break internal/controller/lynqnode_controller.go:123
(dlv) continueDebug Operator Logs
View operator logs with different verbosity:
# Default logs
kubectl logs -n lynq-system -l control-plane=controller-manager -f
# Filter for specific node
kubectl logs -n lynq-system -l control-plane=controller-manager | grep acme-corp
# Follow logs for errors only
kubectl logs -n lynq-system -l control-plane=controller-manager -f | grep -i error
# View logs from previous crash
kubectl logs -n lynq-system -l control-plane=controller-manager --previousDebug Test Resources
View what the operator sees:
# Check LynqNode CR status
kubectl get lynqnode acme-corp-test-template -o yaml
# Check hub sync status
kubectl get lynqhub test-hub -o yaml | yq '.status'
# Check template
kubectl get lynqform test-template -o yaml
# View events
kubectl get events --sort-by='.lastTimestamp' -n lynq-system
# Describe resource for events
kubectl describe lynqnode acme-corp-test-templateTesting
Unit Tests
# Run all tests
make test
# Run with coverage
make test-coverage
# Run specific package
go test ./internal/controller/... -v
# Run specific test
go test ./internal/controller/ -run TestLynqNodeController_Reconcile -vIntegration Tests
# Requires running Minikube cluster
make test-integrationE2E Testing
Test complete workflow:
# 1. Deploy fresh operator
./scripts/deploy-to-minikube.sh
# 2. Deploy test database
./scripts/deploy-mysql.sh
# 3. Deploy test hub and template
./scripts/deploy-lynqhub.sh
./scripts/deploy-lynqform.sh
# 4. Verify nodes created
kubectl get lynqnodes
kubectl get deployments,services -l lynq.sh/node
# 5. Test lifecycle: Add node
kubectl exec -it deployment/mysql -n lynq-test -- \
mysql -u root -p lynq_demo -e \
"INSERT INTO tenants (uid, host_or_url, activate, deploy_image, plan_id) VALUES ('delta-co', 'https://delta.example.com', TRUE, 'nginx:stable', 'enterprise');"
# Wait 30s, then verify
kubectl get lynqnode delta-co-test-template
# 6. Test lifecycle: Deactivate node
kubectl exec -it deployment/mysql -n lynq-test -- \
mysql -u root -p lynq_demo -e \
"UPDATE tenants SET activate = FALSE WHERE uid = 'acme-corp';"
# Wait 30s, then verify deletion
kubectl get lynqnode acme-corp-test-template
# Should be NotFoundTips for Fast Iteration
1. Skip Image Build for Controller Changes
If only changing controller logic (not CRDs, RBAC, etc.):
# Run locally instead of deploying
make run~10x faster than full build/deploy cycle.
2. Keep Logs Open
# In a dedicated terminal
kubectl logs -n lynq-system -l control-plane=controller-manager -f3. Use Watch Commands
# Watch nodes
watch kubectl get lynqnodes
# Watch specific node
watch kubectl get lynqnode acme-corp-test-template -o yaml4. Quick MySQL Queries
Create aliases:
alias mysql-test='kubectl exec -it deployment/mysql -n lynq-test -- mysql -u node_reader -p$(kubectl get secret mysql-credentials -n lynq-test -o jsonpath="{.data.password}" | base64 -d) lynq_demo'
# Then use:
mysql-test -e "SELECT * FROM tenants;"5. Fast Context Switching
# Add to ~/.zshrc or ~/.bashrc
alias kto='kubectl config use-context lynq'
alias ktos='kubectl -n lynq-system'
alias ktot='kubectl -n lynq-test'
# Usage:
kto # Switch to lynq context
ktos get pods # Get pods in operator namespaceCommon Development Scenarios
Scenario 1: Testing Template Changes
# 1. Modify template logic in lynqnode_controller.go
vim internal/controller/lynqnode_controller.go
# 2. Run locally for quick feedback
make run
# 3. In another terminal, apply test template
kubectl apply -f config/samples/operator_v1_lynqform.yaml
# 4. Watch logs and verify rendered resources
kubectl logs -n lynq-system -l control-plane=controller-manager -f
kubectl get lynqnode -o yaml | grep -A 10 "spec:"Scenario 2: Testing Database Sync
# 1. Modify hub controller
vim internal/controller/lynqhub_controller.go
# 2. Deploy to test in-cluster
./scripts/deploy-to-minikube.sh
# 3. Change database and watch sync
mysql-test -e "UPDATE tenants SET plan_id = 'premium' WHERE uid = 'acme-corp';"
# 4. Verify LynqNode CR updated
kubectl get lynqnode acme-corp-test-template -o yaml | grep planIdScenario 3: Testing CRD Changes
# 1. Modify CRD in api/v1/
vim api/v1/lynqnode_types.go
# 2. Regenerate manifests
make manifests
# 3. Install updated CRDs
make install
# 4. Rebuild and deploy operator
./scripts/deploy-to-minikube.sh
# 5. Test with updated CRD
kubectl apply -f config/samples/Scenario 4: Testing Webhook Validation
# 1. Modify webhook in api/v1/*_webhook.go
vim api/v1/lynqform_webhook.go
# 2. Must deploy to cluster (webhooks need TLS)
./scripts/deploy-to-minikube.sh
# 3. Test invalid resource
kubectl apply -f - <<EOF
apiVersion: operator.lynq.sh/v1
kind: LynqForm
metadata:
name: invalid-template
spec:
hubId: non-existent-registry # Should fail validation
EOF
# 4. Should see validation errorCleanup
Partial Cleanup (Keep Cluster)
# Delete test resources
kubectl delete lynqnodes --all
kubectl delete lynqform test-template
kubectl delete lynqhub test-hub
# Delete MySQL
kubectl delete deployment,service,pvc mysql -n lynq-test
# Delete operator
kubectl delete deployment lynq-controller-manager -n lynq-systemFull Cleanup
# Delete everything including cluster
./scripts/cleanup-minikube.sh
# Answer 'y' to all prompts for complete cleanupFresh Start
# Complete reset
./scripts/cleanup-minikube.sh # Delete everything
./scripts/setup-minikube.sh # Recreate cluster
./scripts/deploy-to-minikube.sh # Deploy operatorTroubleshooting
Operator Won't Start
# Check pod status
kubectl get pods -n lynq-system
# Check logs
kubectl logs -n lynq-system -l control-plane=controller-manager
# Common issues:
# 1. cert-manager not ready
kubectl get pods -n cert-manager
# If pods are not running, wait or check:
kubectl describe pods -n cert-manager
# 2. Webhook certificates not ready
kubectl get certificate -n lynq-system
# Should show "Ready=True"
# 3. Image not loaded
minikube -p lynq image ls | grep lynq
# 4. CRDs not installed
kubectl get crd | grep lynqcert-manager is Critical
If the operator pod fails to start with webhook certificate errors, cert-manager is likely not installed or not ready. Check:
# Verify cert-manager installation
kubectl get pods -n cert-manager
# Check certificate status
kubectl get certificate -n lynq-system
kubectl describe certificate -n lynq-system
# If missing, install cert-manager:
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.0/cert-manager.yaml
kubectl wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager-webhookTests Failing
# Ensure test cluster is accessible
kubectl cluster-info
# Check if CRDs are installed
kubectl get crd | grep lynq
# Run tests with verbose output
go test ./... -v -count=1Image Not Updating
# Force rebuild without cache
docker build --no-cache -t lynq:dev .
# Reload into Minikube
minikube -p lynq image load lynq:dev
# Restart operator pod
kubectl rollout restart deployment -n lynq-system lynq-controller-managerAdvanced Workflows
Multiple Minikube Profiles
Work on multiple features simultaneously:
# Feature A cluster
MINIKUBE_PROFILE=feature-a ./scripts/setup-minikube.sh
MINIKUBE_PROFILE=feature-a ./scripts/deploy-to-minikube.sh
# Feature B cluster
MINIKUBE_PROFILE=feature-b ./scripts/setup-minikube.sh
MINIKUBE_PROFILE=feature-b ./scripts/deploy-to-minikube.sh
# Switch between them
kubectl config use-context feature-a
kubectl config use-context feature-bCustom Resource Allocations
# More powerful cluster for load testing
MINIKUBE_CPUS=8 \
MINIKUBE_MEMORY=16384 \
./scripts/setup-minikube.shSee Also
- Quick Start - Initial setup guide
- Development Guide - General development practices
- Contributing - Contribution guidelines
- Troubleshooting - Common issues
Summary
Fast iteration workflow:
- Make code changes
- Run
make runfor controller changes (5s feedback) - Or run
./scripts/deploy-to-minikube.shfor full testing (2min) - Test with
kubectl apply -f config/samples/ - Iterate
Key takeaways:
- Use
make runfor fastest iteration (no webhooks) - Use
./scripts/deploy-to-minikube.shfor full testing (with webhooks) - Keep logs open in a separate terminal
- Test E2E with real MySQL database
- Clean up and reset when needed
Happy coding! 🚀
Dashboard
Install and configure the Lynq Dashboard web UI. Visualize Hub, Form, and Node topology, and monitor operator status in real-time.
Contributing a New Datasource
Guide for implementing a new datasource adapter for Lynq. Covers the Datasource interface, factory registration, API types, and testing.