Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Druid Kubernetes Operator Main

From Leeroopedia


Knowledge Sources
Domains Kubernetes, Operator, Infrastructure
Last Updated 2026-02-10 10:00 GMT

Overview

druid-operator/main.go is the entry point for the Druid Kubernetes Operator, bootstrapping the controller-runtime manager that reconciles Druid cluster and ingestion custom resources.

Description

This Go program initializes a Kubernetes controller manager using the sigs.k8s.io/controller-runtime framework. It registers the Druid CRD scheme, creates two reconcilers (one for Druid cluster resources via druid.NewDruidReconciler and one for ingestion resources via druidingestioncontrollers.NewDruidIngestionReconciler), configures metrics and health probe endpoints, and supports leader election for high availability. The WATCH_NAMESPACE environment variable controls whether the operator watches a single namespace, multiple comma-separated namespaces, or all namespaces cluster-wide.

Usage

This file is the main executable for deploying the Druid Operator in a Kubernetes cluster. It is built as a Go binary and typically run inside a container managed by a Kubernetes Deployment.

Code Reference

Source Location

Signature

package main

// init registers the Kubernetes client-go and Druid CRD schemes
func init()

// main parses flags, creates the controller manager, registers reconcilers,
// adds health/ready checks, and starts the manager loop
func main()

// watchNamespaceCache returns a multi-namespace cache function when
// WATCH_NAMESPACE contains comma-separated namespaces, or nil for
// single/all-namespace mode
func watchNamespaceCache() cache.NewCacheFunc

Import

import (
    "github.com/datainfrahq/druid-operator/controllers/druid"
    druidv1alpha1 "github.com/datainfrahq/druid-operator/apis/druid/v1alpha1"
    druidingestioncontrollers "github.com/datainfrahq/druid-operator/controllers/ingestion"
    ctrl "sigs.k8s.io/controller-runtime"
)

I/O Contract

Inputs

Name Type Required Description
--metrics-bind-address string No Address for the metrics endpoint (default ":8080")
--health-probe-bind-address string No Address for the health probe endpoint (default ":8081")
--leader-elect bool No Enable leader election for HA controller manager (default false)
WATCH_NAMESPACE env var No Comma-separated list of namespaces to watch; empty string watches all namespaces

Outputs

Name Type Description
/healthz HTTP endpoint Liveness probe endpoint returning health status
/readyz HTTP endpoint Readiness probe endpoint returning ready status
:8080/metrics HTTP endpoint Prometheus-compatible metrics endpoint
Kubernetes reconciliation side effect Creates and manages Druid cluster resources (StatefulSets, Services, ConfigMaps, etc.)

Usage Examples

Running the Operator Locally

# Set the namespace to watch
export WATCH_NAMESPACE=druid-system

# Run the operator binary
go run druid-operator/main.go \
  --metrics-bind-address=:8080 \
  --health-probe-bind-address=:8081

Multi-Namespace Watching

# Watch multiple namespaces
export WATCH_NAMESPACE="druid-prod,druid-staging,druid-dev"
go run druid-operator/main.go --leader-elect=true

Kubernetes Deployment Manifest (excerpt)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: druid-operator
spec:
  template:
    spec:
      containers:
        - name: manager
          image: druid-operator:latest
          args:
            - --leader-elect
          env:
            - name: WATCH_NAMESPACE
              value: "druid-system"
          ports:
            - containerPort: 8080
              name: metrics
            - containerPort: 8081
              name: health

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment