currentconfigstore

package
v0.2.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

pkg/controller/currentconfigstore

In-memory cache of the parsed HAProxy currentConfig exposed to templates.

Overview

Templates can reference the previously-deployed HAProxy configuration to keep server-slot ordering stable across rolling deploys (so connections don't migrate when an unrelated backend changes). This package provides the cache that holds that pre-parsed config: the HAProxyCfg CRD watcher feeds it raw resource bytes, and the renderer reads back a *parserconfig.StructuredConfig that templates consume via the currentConfig runtime variable.

This is a utility component — direct calls, no event loop, no goroutine. It's safe for concurrent reads and serialised writes via an internal sync.RWMutex.

Quick Start

import "gitlab.com/haproxy-haptic/haptic/pkg/controller/currentconfigstore"

store, err := currentconfigstore.New(logger)
if err != nil { /* parser construction failed */ }

// Watcher's OnChange callback feeds the raw resource (or nil on delete)
store.Update(unstructuredHAProxyCfg)

// Renderer pulls the parsed value
cfg := store.Get() // *parserconfig.StructuredConfig (nil if not yet populated)

Hot-Path Optimisations

Update is called every time the HAProxyCfg CRD changes, including no-op status updates. Two short-circuits keep the parsing cost bounded:

  1. Generation check — if metadata.generation matches the last-seen value, the spec hasn't changed and the cached config is returned without re-parsing.
  2. Content hash — if the generation moved, a spec.checksum field (set by the config-publisher) is compared against the cached hash; if it matches, parsing is skipped without even decompressing. If no spec.checksum is present the content is decompressed and SHA-256'd, and parsing is skipped if the hash matches.

A single *parser.Parser is reused across calls to avoid the per-call parser.New() overhead.

See Also

  • pkg/dataplane/parser — the client-native wrapper that produces *StructuredConfig
  • pkg/controller/renderer — the consumer that exposes Get() to templates as currentConfig
  • pkg/compression — handles the optional zstd+base64-encoded payload of large HAProxyCfg resources (above controller.configPublishing.compressionThreshold, default 1 MiB)

License

Apache-2.0 — see root LICENSE.

Documentation

Overview

Package currentconfigstore provides a utility component for caching the parsed current HAProxy configuration from the HAProxyCfg CRD.

This is a utility component that can be called directly without events. It follows the codebase's utility component pattern for infrastructure concerns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds the parsed current HAProxy configuration. This is a utility component that can be called directly without events.

func New

func New(logger *slog.Logger) (*Store, error)

New creates a new CurrentConfigStore.

func (*Store) Get

Get returns the current parsed config (may be nil).

func (*Store) Update

func (s *Store) Update(resource any)

Update parses and stores the config from an unstructured HAProxyCfg resource. Pass nil to clear the stored config.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL