Site Controller

The site controller (cmd/controller) is the central Kubernetes operator for Skupper. It watches every Skupper custom resource in one or more namespaces and reconciles them into the desired network state — creating router deployments, ConfigMaps, Certificates, SecuredAccess objects, and Links as needed.

Role in the architecture

Skupper CRs (Site, Link, Connector, Listener, RouterAccess, …)
        ↓  watched by EventProcessor
   Site Controller
        ↓  writes desired state to
   skupper-router ConfigMap
        ↓  read by
   kube-adaptor (sidecar) → live router AMQP API

The site controller never touches the router process directly. It only writes to Kubernetes resources; the kube-adaptor is responsible for applying those changes to the running router.

Controller struct and sub-managers

The Controller struct owns three pluggable sub-managers:

Sub-managerPackageResponsibility
CertificateManagerImplinternal/kube/certificatesReconciles Certificate CRs → Kubernetes Secrets (mTLS material)
SecuredAccessManagerinternal/kube/securedaccessReconciles SecuredAccess CRs → Services, Routes, Ingresses, LoadBalancers
Grantsinternal/kube/grantsServes the HTTPS grant-redemption endpoint; reconciles AccessGrant/AccessToken CRs

Each sub-manager is initialised in NewController and handed a ControllerContext interface so they can call back into the controller for namespace-filtering and label/annotation propagation.

Namespace scope

The controller can run in two modes, controlled by WATCH_NAMESPACE:

  • Single namespace (WATCH_NAMESPACE=my-ns): only processes resources in that namespace; always requires an explicit control ConfigMap.
  • All namespaces (WATCH_NAMESPACE="", the default): monitors every namespace. When REQUIRE_EXPLICIT_CONTROL=true (or when watching all namespaces from a single-namespace deployment), a namespace is only processed if it contains a ConfigMap named skupper with a controller entry matching the controller’s qualified name.

The filter helper wraps every event handler with this check:

// internal/kube/controller/controller.go
func filter[V any](controller *Controller, handler func(string, V) error) func(string, V) error {
    return watchers.FilterByNamespace(controller.IsControlled, handler)
}

Informers registered at startup

NewController registers one informer per resource type. All informers are scoped to WatchNamespace:

InformerResourceHandler
siteWatcherSitecheckSite
listenerWatcherListenercheckListener
connectorWatcherConnectorcheckConnector
multiKeyListenerWatcherMultiKeyListenercheckMultiKeyListener
linkAccessWatcherRouterAccesscheckRouterAccess
attachedConnectorWatcherAttachedConnectorcheckAttachedConnector
attachedConnectorBindingWatcherAttachedConnectorBindingcheckAttachedConnectorBinding
LinksLinkcheckLink
AccessTokensAccessTokencheckAccessToken
Router podsPods with skupper.io/component=routerrouterPodEvent
Router ConfigMapsConfigMaps labelled internal.skupper.io/router-configrouterConfigUpdate
Network statusskupper-network-status ConfigMapnetworkStatusUpdate
Listener servicesServices labelled internal.skupper.io/listenercheckListenerService
Other servicesServices without that labelcheckObservedService
Site sizingConfigMaps labelled with the sizing labelsiteSizing.Update
Label templatesConfigMaps labelled skupper.io/label-templatelabelling.Update

Initialisation sequence

The init phase runs before the event loop and performs a full recovery from existing cluster state:

1. Start all informers, wait for cache sync
2. Recover namespace control config
3. Recover site-sizing and labelling ConfigMaps
4. Recover CertificateManager (existing Certificates + Secrets)
5. Recover SecuredAccessManager (existing SecuredAccess, Routes, Ingresses, Services)
6. Seed observed services cache
7. Seed RouterAccess objects into each Site (before site recovery)
8. Recover each Site: call site.StartRecovery()
9. Recover Connectors, Listeners, MultiKeyListeners
10. Recover AttachedConnectorBindings and AttachedConnectors
11. Recover network status ConfigMaps
12. Wait for pod-watcher caches to sync (pod selectors from connectors)
13. Call site.Reconcile() for each recovered site → writes router ConfigMap
14. Start grant HTTP server

Per-namespace Site objects

The controller holds a sites map[string]*site.Site. Each namespace gets exactly one Site instance, created lazily by getSite:

// internal/kube/controller/controller.go
func (c *Controller) getSite(namespace string) *site.Site {
    if existing, ok := c.sites[namespace]; ok {
        return existing
    }
    site := site.NewSite(namespace, c.eventProcessor, c.certMgr, c.accessMgr, c.siteSizing, c, c.disableSecContext)
    c.sites[namespace] = site
    return site
}

Almost every event handler just extracts the namespace from the key and delegates to the appropriate Site method:

func (c *Controller) checkConnector(key string, connector *skupperv2alpha1.Connector) error {
    namespace, name, _ := cache.SplitMetaNamespaceKey(key)
    return c.getSite(namespace).CheckConnector(name, connector)
}

What site.Reconcile does

Site.Reconcile in internal/kube/site/site.go is the core reconcile function. On every Site CR change it:

  1. Validates the site spec (e.g. rejects invalid linkAccess types).
  2. Ensures the router ServiceAccount, Role, and RoleBinding exist.
  3. Ensures the local CA Certificate and the skupper-local mTLS credentials exist (via certMgr.EnsureCA / certMgr.Ensure).
  4. Calls checkDefaultRouterAccess — creates a RouterAccess CR if linkAccess is set (see Default Site).
  5. Builds the desired RouterConfig (listeners, connectors, SSL profiles) and writes it as a ConfigMap labelled internal.skupper.io/router-config.
  6. Creates or updates the skupper-router Deployment (via the embedded YAML template in resources/).
  7. Ensures any SecuredAccess objects for active RouterAccess entries.
  8. Updates Site.Status conditions (Configured, Resolved, Running).

AccessToken handling

When an AccessToken CR appears (not yet redeemed), the controller calls grants.RedeemAccessToken directly from checkAccessToken:

func (c *Controller) checkAccessToken(key string, token *skupperv2alpha1.AccessToken) error {
    if token == nil || token.IsRedeemed() {
        return nil
    }
    site := c.getSite(token.Namespace).GetSite()
    return grants.RedeemAccessToken(token, site, c.eventProcessor)
}

This makes an HTTPS POST to the grant server on the remote site and, on success, creates the Secret and Link CRs that establish the inter-site connection. See Access Grants and Tokens.

Network status propagation

When the skupper-network-status ConfigMap changes (written by the kube-adaptor’s flow collector), the controller decodes the NetworkStatus JSON and forwards it to site.NetworkStatusUpdated. The site uses this to update Link operational status and — when exposePodsByName is used on listeners — to populate per-pod routing entries.

Configuration reference

Flag / Env varDefaultPurpose
NAMESPACErequiredNamespace the controller itself runs in
WATCH_NAMESPACE"" (all)Namespace(s) to monitor for Skupper CRs
REQUIRE_EXPLICIT_CONTROLfalseRequire a skupper ConfigMap in each namespace
DISABLE_SECURITY_CONTEXTfalseOmit security contexts from managed pods
SKUPPER_ENABLED_ACCESS_TYPESlocal,loadbalancer,routeAllowed SecuredAccess types
SKUPPER_DEFAULT_ACCESS_TYPEauto-detectedFallback access type when none specified

References