Documentation
¶
Overview ¶
Package yaml provides centralized schema management for Nexlayer Deployment YAML configurations.
Package yaml provides centralized schema management for Nexlayer Deployment YAML configurations.
Package yaml provides centralized schema management for Nexlayer Deployment YAML configurations. It handles validation, parsing, and processing of configuration files.
Index ¶
- Constants
- func CategorizeErrors(errors []ValidationError) map[ValidationErrorSeverity][]ValidationError
- func Marshal(config *NexlayerYAML) ([]byte, error)
- func WriteToFile(config *NexlayerYAML, filePath string) error
- type APIResponse
- type Application
- type DatabaseType
- type Deployment
- type DeploymentResponse
- type EnvVar
- type GenerateOptions
- type NexlayerYAML
- type Pod
- type PodStatus
- type Processor
- type ProcessorOptions
- type RegistryLogin
- type Resources
- type Secret
- type ValidationContext
- type ValidationError
- func FromBaseError(err *errors.Error) ValidationError
- func MakeConflictError(field1, field2 string, reason string) ValidationError
- func MakeFormatError(field, formatName string, examples ...string) ValidationError
- func MakeInfo(field, message string, suggestions ...string) ValidationError
- func MakeProhibitedFieldError(field, reason string) ValidationError
- func MakeReferenceError(field, refType, refName string) ValidationError
- func MakeRequiredError(field string) ValidationError
- func MakeUnsupportedError(field, value, reason string) ValidationError
- func MakeWarning(field, message string, suggestions ...string) ValidationError
- func Validate(config *NexlayerYAML) []ValidationError
- func ValidateProhibitedFields(rawConfig map[string]interface{}) []ValidationError
- func ValidateSecret(secret *Secret) []ValidationError
- func ValidateVolume(volume *Volume) []ValidationError
- func ValidateYAML(config *NexlayerYAML) []ValidationError
- type ValidationErrorCategory
- type ValidationErrorInfo
- type ValidationErrorSeverity
- type Volume
Constants ¶
const ( // Frontend pod types PodTypeFrontend = "frontend" PodTypeReact = "react" PodTypeNextJS = "nextjs" PodTypeVue = "vue" // Backend pod types PodTypeBackend = "backend" PodTypeExpress = "express" PodTypeDjango = "django" PodTypeFastAPI = "fastapi" PodTypeNode = "node" PodTypePython = "python" PodTypeGolang = "golang" PodTypeJava = "java" // Database pod types PodTypeDatabase = "database" PodTypeMongoDB = "mongodb" PodTypePostgres = "postgres" PodTypeRedis = "redis" PodTypeMySQL = "mysql" // AI pod types PodTypeAI = "ai" PodTypeTensorflow = "tensorflow" PodTypePyTorch = "pytorch" PodTypeHuggingFace = "huggingface" // Cache pod types PodTypeCache = "cache" // Message queue pod types PodTypeMessageQueue = "messagequeue" PodTypeRabbitMQ = "rabbitmq" PodTypeKafka = "kafka" // Search pod types PodTypeSearch = "search" PodTypeElasticsearch = "elasticsearch" )
Pod types
const ( VolumeTypePersistent = "persistent" VolumeTypeEmptyDir = "emptydir" VolumeTypeConfigMap = "configmap" VolumeTypeSecret = "secret" )
Volume types
const ( ProtocolTCP = "TCP" ProtocolUDP = "UDP" )
Protocol types
const ( ResourceUnitCPU = "m" ResourceUnitMemory = "Mi" )
Resource units
const ( DefaultCPURequest = "100m" DefaultCPULimit = "500m" DefaultMemoryRequest = "128Mi" DefaultMemoryLimit = "512Mi" )
Default resource values
const ( DefaultHTTPPort = 80 DefaultHTTPSPort = 443 DefaultNodePort = 3000 DefaultPythonPort = 8000 DefaultGoPort = 8080 DefaultJavaPort = 8080 DefaultMongoDBPort = 27017 DefaultPostgresPort = 5432 DefaultMySQLPort = 3306 DefaultRedisPort = 6379 DefaultElasticsearch = 9200 DefaultRabbitMQPort = 5672 DefaultKafkaPort = 9092 )
Default port values
const ( DefaultNodeImage = "node:18-alpine" DefaultPythonImage = "python:3.11-slim" DefaultGoImage = "golang:1.21-alpine" DefaultJavaImage = "openjdk:17-slim" DefaultNginxImage = "nginx:alpine" DefaultMongoDBImage = "mongo:6" DefaultPostgresImage = "postgres:15-alpine" DefaultMySQLImage = "mysql:8" DefaultRedisImage = "redis:7-alpine" DefaultElasticsearchImage = "elasticsearch:8.7.0" DefaultRabbitMQImage = "rabbitmq:3-management" DefaultKafkaImage = "bitnami/kafka:3.4" )
Default image values
const SchemaV2 = `` /* 9071-byte string literal not displayed */
SchemaV2 contains the JSON Schema for validating Nexlayer Deployment YAML configurations
Variables ¶
This section is empty.
Functions ¶
func CategorizeErrors ¶
func CategorizeErrors(errors []ValidationError) map[ValidationErrorSeverity][]ValidationError
CategorizeErrors groups validation errors by severity.
func Marshal ¶
func Marshal(config *NexlayerYAML) ([]byte, error)
Marshal serializes a NexlayerYAML configuration to YAML
func WriteToFile ¶
func WriteToFile(config *NexlayerYAML, filePath string) error
WriteToFile writes a NexlayerYAML configuration to a file
Types ¶
type APIResponse ¶
type APIResponse[T any] struct { Success bool `json:"success"` Message string `json:"message,omitempty"` Data T `json:"data,omitempty"` }
APIResponse represents a generic API response.
type Application ¶
type Application struct {
Name string `yaml:"name" json:"name"`
Type string `yaml:"type"`
Description string `yaml:"description,omitempty"`
URL string `yaml:"url,omitempty"`
Pods []Pod `yaml:"pods" json:"pods"`
RegistryLogin *RegistryLogin `yaml:"registryLogin,omitempty"`
Annotations map[string]string `yaml:"annotations,omitempty"`
Metadata map[string]string `yaml:"metadata,omitempty" json:"metadata,omitempty"`
}
Application represents a Nexlayer application configuration
func (*Application) UnmarshalYAML ¶
func (a *Application) UnmarshalYAML(node *yaml.Node) error
UnmarshalYAML implements the yaml.Unmarshaler interface for Application.
type DatabaseType ¶
type DatabaseType string
Database type enum
const ( DatabaseNone DatabaseType = "none" DatabasePostgres DatabaseType = "postgres" DatabaseMySQL DatabaseType = "mysql" DatabaseMongoDB DatabaseType = "mongodb" DatabaseRedis DatabaseType = "redis" )
type Deployment ¶
Deployment represents a deployment configuration.
type DeploymentResponse ¶
type DeploymentResponse struct {
APIResponse[*Deployment]
}
DeploymentResponse represents a deployment API response.
type EnvVar ¶
type EnvVar struct {
Key string `yaml:"key" json:"key" validate:"required,envvar"`
Value string `yaml:"value" json:"value" validate:"required"`
}
EnvVar represents an environment variable.
type GenerateOptions ¶
type GenerateOptions struct {
AppName string // Application name override
AppType string // Application type override
Description string // Application description override
PodName string // Main pod name override
PodType string // Main pod type override
PodImage string // Main pod image override
PodPort int // Main pod port override
PodPath string // Main pod path override
EnvVars map[string]string // Environment variables to include
VerifyImages bool // Whether to verify Docker images
AdditionalPods []Pod // Additional pods to include in the configuration
}
GenerateOptions holds configuration for YAML generation
type NexlayerYAML ¶
type NexlayerYAML struct {
Application Application `yaml:"application"`
}
NexlayerYAML represents the root configuration
func Generate ¶
func Generate(info *types.ProjectInfo, opts *GenerateOptions) (*NexlayerYAML, error)
Generate creates a gold-compliant NexlayerYAML configuration
func ParseFile ¶
func ParseFile(filePath string) (*NexlayerYAML, error)
ParseFile parses a YAML file into a NexlayerYAML configuration
func (*NexlayerYAML) UnmarshalYAML ¶
func (n *NexlayerYAML) UnmarshalYAML(node *yaml.Node) error
UnmarshalYAML implements the yaml.Unmarshaler interface for NexlayerYAML.
type Pod ¶
type Pod struct {
Name string `yaml:"name"`
Type string `yaml:"type,omitempty"`
Image string `yaml:"image"`
ServicePorts []int `yaml:"servicePorts"`
MountPath string `yaml:"mountPath,omitempty"`
Path string `yaml:"path,omitempty"`
Vars map[string]string `yaml:"vars,omitempty"`
Secrets []Secret `yaml:"secrets,omitempty"`
Volumes []Volume `yaml:"volumes,omitempty"`
}
Pod represents a pod configuration
type PodStatus ¶
type PodStatus struct {
Name string `json:"name"`
Status string `json:"status"`
Ready bool `json:"ready"`
}
PodStatus represents the status of a pod.
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor handles variable substitution in YAML configurations
func (*Processor) ExtractVariables ¶
func (p *Processor) ExtractVariables(config *NexlayerYAML) []string
ExtractVariables extracts all variable references from a configuration
func (*Processor) Process ¶
func (p *Processor) Process(config *NexlayerYAML, opts *ProcessorOptions) (*NexlayerYAML, error)
Process applies variable substitution to a YAML configuration
type ProcessorOptions ¶
type ProcessorOptions struct {
// ApplicationURL is the URL of the application
ApplicationURL string
// RegistryURL is the URL of the container registry
RegistryURL string
// CustomVariables contains additional variables for substitution
CustomVariables map[string]string
}
ProcessorOptions contains options for the YAML processor
type RegistryLogin ¶
type RegistryLogin struct {
Registry string `yaml:"registry" json:"registry" validate:"required"`
Username string `yaml:"username" json:"username" validate:"required"`
PersonalAccessToken string `yaml:"personalAccessToken" json:"personal_access_token" validate:"required"`
}
RegistryLogin represents registry login credentials in the Nexlayer Deployment YAML configuration.
type Secret ¶
type Secret struct {
Name string `yaml:"name"`
Data string `yaml:"data"`
MountPath string `yaml:"mountPath"`
FileName string `yaml:"fileName"`
}
Secret represents a secret configuration
type ValidationContext ¶
type ValidationContext struct {
Field string
Value interface{}
}
ValidationContext provides context for validation
type ValidationError ¶
type ValidationError struct {
Field string `json:"field"`
Message string `json:"message"`
Severity ValidationErrorSeverity `json:"severity"`
Suggestions []string `json:"suggestions,omitempty"`
Info *ValidationErrorInfo `json:"info,omitempty"`
AutoFixed bool `json:"auto_fixed,omitempty"`
}
ValidationError represents a validation error with field, message, and severity. TODO: In a future update, consider migrating to use pkg/errors.Error directly This is kept as a separate type for backward compatibility.
func FromBaseError ¶
func FromBaseError(err *errors.Error) ValidationError
FromBaseError converts a common errors.Error to a ValidationError
func MakeConflictError ¶
func MakeConflictError(field1, field2 string, reason string) ValidationError
MakeConflictError creates a validation error for conflicting fields.
func MakeFormatError ¶
func MakeFormatError(field, formatName string, examples ...string) ValidationError
MakeFormatError creates a validation error for a field with an invalid format.
func MakeInfo ¶
func MakeInfo(field, message string, suggestions ...string) ValidationError
MakeInfo creates an informational validation message.
func MakeProhibitedFieldError ¶
func MakeProhibitedFieldError(field, reason string) ValidationError
MakeProhibitedFieldError creates a validation error for a prohibited field.
func MakeReferenceError ¶
func MakeReferenceError(field, refType, refName string) ValidationError
MakeReferenceError creates a validation error for a reference to a non-existent resource.
func MakeRequiredError ¶
func MakeRequiredError(field string) ValidationError
MakeRequiredError creates a validation error for a missing required field.
func MakeUnsupportedError ¶
func MakeUnsupportedError(field, value, reason string) ValidationError
MakeUnsupportedError creates a validation error for an unsupported value.
func MakeWarning ¶
func MakeWarning(field, message string, suggestions ...string) ValidationError
MakeWarning creates a validation warning.
func Validate ¶
func Validate(config *NexlayerYAML) []ValidationError
Validate validates a NexlayerYAML configuration
func ValidateProhibitedFields ¶
func ValidateProhibitedFields(rawConfig map[string]interface{}) []ValidationError
ValidateProhibitedFields checks for fields not allowed in Nexlayer Deployment YAML.
func ValidateSecret ¶
func ValidateSecret(secret *Secret) []ValidationError
ValidateSecret validates a secret configuration
func ValidateVolume ¶
func ValidateVolume(volume *Volume) []ValidationError
ValidateVolume validates a volume configuration
func ValidateYAML ¶
func ValidateYAML(config *NexlayerYAML) []ValidationError
ValidateYAML validates a NexlayerYAML configuration.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
Error implements the error interface for ValidationError.
func (ValidationError) ToBaseError ¶
func (ve ValidationError) ToBaseError() *errors.Error
ToBaseError converts a ValidationError to the common errors.Error type
type ValidationErrorCategory ¶
type ValidationErrorCategory string
ValidationErrorCategory represents the category of a validation error.
const ( // ValidationErrorCategoryRequired indicates a required field is missing ValidationErrorCategoryRequired ValidationErrorCategory = "required" // ValidationErrorCategoryFormat indicates a field has an invalid format ValidationErrorCategoryFormat ValidationErrorCategory = "format" // ValidationErrorCategoryReference indicates a reference to a non-existent resource ValidationErrorCategoryReference ValidationErrorCategory = "reference" // ValidationErrorCategoryConflict indicates conflicting fields ValidationErrorCategoryConflict ValidationErrorCategory = "conflict" // ValidationErrorCategoryUnsupported indicates an unsupported value ValidationErrorCategoryUnsupported ValidationErrorCategory = "unsupported" // ValidationErrorCategoryProhibited indicates a prohibited field ValidationErrorCategoryProhibited ValidationErrorCategory = "prohibited" )
type ValidationErrorInfo ¶
type ValidationErrorInfo struct {
Line int `json:"line"`
Column int `json:"column"`
Detail string `json:"detail,omitempty"`
Category ValidationErrorCategory `json:"category,omitempty"`
Details map[string]interface{} `json:"details,omitempty"`
}
ValidationErrorInfo contains additional information about a validation error.
type ValidationErrorSeverity ¶
type ValidationErrorSeverity string
ValidationErrorSeverity represents the severity level of a validation error.
const ( // ErrorSeverity indicates a critical validation error ErrorSeverity ValidationErrorSeverity = "error" // WarningSeverity indicates a non-critical validation warning WarningSeverity ValidationErrorSeverity = "warning" )