Module 6: Testing and Debugging
Overview
Now that you can build sophisticated operators with webhooks (Module 5), it’s time to learn how to test and debug them effectively. This module covers unit testing with envtest, integration testing, debugging techniques, and observability patterns that make operators production-ready.
Duration: 6-7 hours
Prerequisites:
- Completion of Module 1: Kubernetes Architecture Deep Dive
- Completion of Module 2: Introduction to Operators
- Completion of Module 3: Building Custom Controllers
- Completion of Module 4: Advanced Reconciliation Patterns
- Completion of Module 5: Webhooks and Admission Control
- Understanding of Go testing fundamentals
Learning Objectives
By the end of this module, you will:
- Write comprehensive unit tests using envtest
- Create integration test suites with Ginkgo/Gomega
- Debug operators effectively using Delve and logs
- Add observability with metrics, logging, and events
- Understand testing best practices for operators
Module Structure
- Lesson 6.1: Testing Fundamentals
- Lesson 6.2: Unit Testing with envtest
- Lesson 6.3: Integration Testing
- Lesson 6.4: Debugging and Observability
Prerequisites Check
Before starting, ensure you’ve completed:
- ✅ Module 5: Operator with webhooks
- ✅ Understand Go testing from Module 2
- ✅ Have a working operator from Module 3/4/5
- ✅ Basic understanding of Go testing (
go test)
If you haven’t completed Module 5, start with Module 5: Webhooks and Admission Control.
What You’ll Build
Throughout this module, you’ll add testing and observability to your Database operator:
- Unit tests for reconciliation logic
- Integration tests for end-to-end scenarios
- Debugging setup for local development
- Metrics and logging for observability
Setup
Before starting this module:
- Have your Database operator from Module 3/4/5:
- Should have a working operator
- Webhooks implemented (from Module 5)
- Ready to add tests
- Ensure development environment is ready:
./scripts/setup-dev-environment.sh - Install testing tools:
# Install Ginkgo and Gomega go install github.com/onsi/ginkgo/v2/ginkgo@latest # Install Delve debugger go install github.com/go-delve/delve/cmd/dlv@latest
Hands-on Labs
Each lesson includes hands-on exercises that add testing and observability to your operator.
- Lab 6.1: Setting Up Testing Environment
- Lab 6.2: Writing Unit Tests
- Lab 6.3: Creating Integration Tests
- Lab 6.4: Adding Observability
Solutions
Complete working solutions for all labs are available in the solutions directory:
- Lab 6.1 Solutions - Test suite setup
- Lab 6.2 Solutions - Unit test examples
- Lab 6.3 Solutions - Integration test examples
- Lab 6.4 Solutions - Metrics, Lab 6.4 Solutions - Observability - Observability examples