config

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config provides NGINX configuration generation from CRD resources. It renders Go templates into valid NGINX configuration files, computes content hashes for change detection, and provides validation helpers.

Usage:

gen := config.NewGenerator()
mainConf, err := gen.GenerateMainConfig(server)
routeConf, err := gen.GenerateRouteConfig(route, upstreams)
hash := gen.Hash(routeConf)

Package config provides NGINX configuration generation and validation utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

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

Generator renders NGINX configuration from CRD specs. It holds pre-parsed templates for efficient repeated rendering.

func NewGenerator

func NewGenerator() (*Generator, error)

NewGenerator creates a new config Generator with pre-parsed templates.

Usage:

gen := config.NewGenerator()

func (*Generator) GenerateFullConfig

func (g *Generator) GenerateFullConfig(
	server *nginxv1alpha1.NginxServer,
	routes []nginxv1alpha1.NginxRoute,
	upstreams []nginxv1alpha1.NginxUpstream,
) (string, error)

GenerateFullConfig assembles a complete NGINX configuration from an NginxServer, its associated NginxRoutes, and NginxUpstreams. Routes are sorted by priority.

Usage:

fullConfig, err := gen.GenerateFullConfig(server, routes, upstreams)

func (*Generator) GenerateMainConfig

func (g *Generator) GenerateMainConfig(server *nginxv1alpha1.NginxServer) (string, error)

GenerateMainConfig renders the main nginx.conf from an NginxServer spec.

Usage:

config, err := gen.GenerateMainConfig(server)

func (*Generator) GenerateRouteConfig

func (g *Generator) GenerateRouteConfig(route *nginxv1alpha1.NginxRoute, upstreamMap map[string]string) (string, error)

GenerateRouteConfig renders a server block configuration from an NginxRoute spec. The upstreamMap maps upstream names to their rendered upstream block names.

Usage:

config, err := gen.GenerateRouteConfig(route, map[string]string{"backend": "ns-backend"})

func (*Generator) GenerateUpstreamConfig

func (g *Generator) GenerateUpstreamConfig(upstream *nginxv1alpha1.NginxUpstream) (string, string, error)

GenerateUpstreamConfig renders an upstream block configuration from an NginxUpstream spec. The returned upstream name follows the format: namespace-name.

Usage:

name, config, err := gen.GenerateUpstreamConfig(upstream)

func (*Generator) Hash

func (g *Generator) Hash(content string) string

Hash computes a SHA-256 hash of the given configuration content. Used for change detection to avoid unnecessary NGINX reloads.

Usage:

hash := gen.Hash(configContent)

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a configuration validation error with context.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface for ValidationError.

type ValidationResult

type ValidationResult struct {
	Valid    bool
	Errors   []ValidationError
	Warnings []string
}

ValidationResult holds the combined results of a validation pass.

func ValidateNginxRoute

func ValidateNginxRoute(route *nginxv1alpha1.NginxRoute) ValidationResult

ValidateNginxRoute validates an NginxRoute spec for correctness.

Usage:

result := config.ValidateNginxRoute(route)

func ValidateNginxServer

func ValidateNginxServer(server *nginxv1alpha1.NginxServer) ValidationResult

ValidateNginxServer validates an NginxServer spec for correctness.

Usage:

result := config.ValidateNginxServer(server)
if !result.Valid { /* handle errors */ }

func ValidateNginxUpstream

func ValidateNginxUpstream(upstream *nginxv1alpha1.NginxUpstream) ValidationResult

ValidateNginxUpstream validates an NginxUpstream spec for correctness.

Usage:

result := config.ValidateNginxUpstream(upstream)

func (*ValidationResult) ErrorMessages

func (r *ValidationResult) ErrorMessages() string

ErrorMessages returns all validation error messages as a single string.

Jump to

Keyboard shortcuts

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