Module 3: Building Custom Controllers

Overview

Now that you’ve built your first operator in Module 2, it’s time to dive deeper into building sophisticated controllers. This module teaches you the advanced patterns and techniques needed to build production-ready operators that manage complex applications.

Duration: 6-7 hours
Prerequisites:

Learning Objectives

By the end of this module, you will:

  • Understand controller-runtime architecture in depth
  • Design well-structured APIs for your operators
  • Implement robust reconciliation logic
  • Work effectively with the Kubernetes client
  • Build a database operator that manages PostgreSQL

Module Structure

  1. Lesson 3.1: Controller Runtime Deep Dive
  2. Lesson 3.2: Designing Your API
  3. Lesson 3.3: Implementing Reconciliation Logic
  4. Lesson 3.4: Working with Client-Go

Prerequisites Check

Before starting, ensure you’ve completed:

  • Module 1: Understand CRDs, controllers, and reconciliation
  • Module 2: Built your first “Hello World” operator
  • ✅ Can scaffold kubebuilder projects
  • ✅ Understand the Reconcile function basics

If you haven’t completed Module 2, start with Module 2: Introduction to Operators.

What You’ll Build

Throughout this module, you’ll build a PostgreSQL operator that:

  • Manages PostgreSQL database instances
  • Handles database creation and configuration
  • Manages StatefulSets and Services
  • Implements proper reconciliation logic
  • Uses owner references for resource management

This builds on your “Hello World” operator from Module 2, adding complexity and real-world patterns.

Setup

Before starting this module:

  1. Verify Module 2 completion:
    • You should have built a “Hello World” operator
    • You understand kubebuilder project structure
    • You can run operators locally
  2. Ensure development environment is ready:
    ./scripts/setup-dev-environment.sh
    
  3. Have a kind cluster running:
    ./scripts/setup-kind-cluster.sh
    

Hands-on Labs

Each lesson includes hands-on exercises building toward a complete PostgreSQL operator.

Solutions

Complete working solutions for all labs are available in the solutions directory:

  • Lab 3.3 Solutions - Complete Database operator (types, controller with StatefulSet/Service)