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 ¶
- type Generator
- func (g *Generator) GenerateFullConfig(server *nginxv1alpha1.NginxServer, routes []nginxv1alpha1.NginxRoute, ...) (string, error)
- func (g *Generator) GenerateMainConfig(server *nginxv1alpha1.NginxServer) (string, error)
- func (g *Generator) GenerateRouteConfig(route *nginxv1alpha1.NginxRoute, upstreamMap map[string]string) (string, error)
- func (g *Generator) GenerateUpstreamConfig(upstream *nginxv1alpha1.NginxUpstream) (string, string, error)
- func (g *Generator) Hash(content string) string
- type ValidationError
- type ValidationResult
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 ¶
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)
type ValidationError ¶
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.