load

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Package load reads KNE deployment configurations, populates a deployment structure, and does basic validation on the configuration. It requires yaml tags to be defined for all struct fields specified in the YAML configuration.

Fields with the kne tag "yaml" (kne:"yaml") are interpreted as path names to YAML files. An error is generated if the file does not exist or cannot be parsed as a YAML file.

Nodes that have the "kind" and "spec" yaml tags expect the spec field to be a *yaml.Node and the kind has been registered with Register.

Typical Usage:

var config DeploymentConfig{}
var deployment Deployment{}
c, err := NewConfig(file, &config)
if err != nil {
	...
}
if err := c.Decode(&deployment); err != nil {
	...
}
// deployment is now ready for use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(kind string, spec *Spec)

Register registers kind with the provided spec.

Types

type Config

type Config struct {
	Path       string      // Path of the configuration file
	Dir        string      // Absolute path of the diretory Path is in
	Config     interface{} // The configuration structure
	Deployment interface{} // Filled by Config.Decode

	IgnoreMissingFiles bool // when set there is no error when a file is missing.
}

A Config represents a KNE deployment configuration.

func NewConfig

func NewConfig(path string, config interface{}) (*Config, error)

NewConfig reads a yaml configuration file at path and populates the provided config structure.

A sample config structure:

type DeploymentConfig struct {
	Cluster     ClusterSpec       `yaml:"cluster"`
	Ingress     IngressSpec       `yaml:"ingress"`
	CNI         CNISpec           `yaml:"cni"`
	Controllers []*ControllerSpec `yaml:"controllers"`
}

func (*Config) Decode

func (c *Config) Decode(deployment interface{}) error

Decode decodes the configuration in Config c and populates deployment. Only fields in the deployment structure that have a registered KNE tag are populated. These fields are populated from configuration nodes that have a "kind" and a "spec" field that match a previously registered spec.

An example deployment structure:

type Deployment struct {
	Cluster     Cluster      `kne:"cluster"`
	Ingress     Ingress      `kne:"ingress"`
	CNI         CNI          `kne:"cni"`
	Controllers []Controller `kne:"controllers"`
}

type Spec

type Spec struct {
	Type     interface{}
	Tag      string // Associated "kne" tag in the used in the deployment structure
	Validate func(c *Config, node interface{}) error
}

A Spec represents a structure that yaml can be decoded into. The type is the type of structure to decode the yaml into. As an example, reflect.TypeOf(KindSpec{}).

The Validate function is called once the yaml file has been decoded into a new created structure of type Type.

Jump to

Keyboard shortcuts

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