Documentation
¶
Index ¶
- Constants
- Variables
- func CreateDefaultJsonDir(basepath string) (string, error)
- func CreateManifestDir(path string) (string, error)
- func ParseYAMLCatalogue(catalogue *Catalogue, r io.Reader) error
- func ParseYAMLCatalogueFromFile(catalogue *Catalogue, filename string) error
- func RegisterTinkerbellHardware(ctx context.Context, client TinkerbellHardwarePusher, serializedJsons [][]byte) error
- func Translate(reader MachineReader, writer MachineWriter, validator MachineValidator) error
- func TranslateAll(reader MachineReader, writer MachineWriter, validator MachineValidator) error
- func WithDefaultAssertions(validator *DefaultMachineValidator)
- type Catalogue
- func (c *Catalogue) AllBMCs() []*pbnjv1alpha1.BMC
- func (c *Catalogue) AllHardware() []*v1alpha1.Hardware
- func (c *Catalogue) AllSecrets() []*corev1.Secret
- func (c *Catalogue) HardwareSpecMarshallable() ([]byte, error)
- func (c *Catalogue) IndexBMCs(index string, fn KeyExtractorFunc)
- func (c *Catalogue) IndexHardware(index string, fn KeyExtractorFunc)
- func (c *Catalogue) IndexSecret(index string, fn KeyExtractorFunc)
- func (c *Catalogue) InsertBMC(bmc *pbnjv1alpha1.BMC) error
- func (c *Catalogue) InsertHardware(hardware *v1alpha1.Hardware) error
- func (c *Catalogue) InsertSecret(secret *corev1.Secret) error
- func (c *Catalogue) LookupBMC(index, key string) ([]*pbnjv1alpha1.BMC, error)
- func (c *Catalogue) LookupHardware(index, key string) ([]*v1alpha1.Hardware, error)
- func (c *Catalogue) LookupSecret(index, key string) ([]*corev1.Secret, error)
- func (c *Catalogue) TotalBMCs() int
- func (c *Catalogue) TotalHardware() int
- func (c *Catalogue) TotalSecrets() int
- func (c *Catalogue) ValidateBMC() error
- func (c *Catalogue) ValidateBmcSecretRefs() error
- func (c *Catalogue) ValidateHardware(skipPowerActions, force bool, ...) error
- type CatalogueOption
- type CsvReader
- type DefaultMachineValidator
- type ErrIncorrectType
- type ErrUnknownIndex
- type FieldIndexer
- type Hardware
- type Indexer
- type Journal
- type KeyExtractorFunc
- type Machine
- type MachineAssertion
- type MachineReader
- type MachineValidator
- type MachineWriter
- type Nameservers
- type TinkerbellHardwareJson
- type TinkerbellHardwareJsonFactory
- type TinkerbellHardwareJsonWriter
- type TinkerbellHardwarePusher
- type TinkerbellManifestYaml
Constants ¶
const BMCNameIndex = ".ObjectMeta.Name"
const DefaultHardwareManifestYamlFilename = "hardware.yaml"
DefaultHardwareManifestYamlFilename is the default file for writing yinkerbell yaml manifests
const DefaultJsonDir = "json"
DefaultJsonDir is the default directory for writing hardware json files.
const DefaultManifestDir = "hardware-manifests"
DefaultManifestDir is the default directory for writing Tinkerbell hardware files.
const HardwareBMCRefIndex = ".Spec.BmcRef"
const HardwareIDIndex = ".Spec.ID"
const NameserversSeparator = "|"
NameserversSeparator is used to unmarshal Nameservers.
const Provisioning = "provisioning"
const SecretNameIndex = ".ObjectMeta.Name"
Variables ¶
var ErrTinkebellHardwareJsonRepeatWrites = errors.New("TinkerbellHardwareJson can only be written to once")
ErrTinkebellHardwareJsonRepeatWrites occurs when a TinkerbellHardwareJson receives multiple calls to Write().
Functions ¶
func CreateDefaultJsonDir ¶
CreateDefaultJsonDir creates the defaut directory where hardware json files are written returning it as the string parameter.
func CreateManifestDir ¶
CreateDefaultManifestDir creates the defaut directory where hardware files are written returning it as the string parameter.
func ParseYAMLCatalogue ¶ added in v0.9.0
ParseCatalogue parses a YAML document, r, that represents a set of Kubernetes manifests. Manifests parsed include CAPT Hardware, PBnJ BMCs and associated Core API Secret.
func ParseYAMLCatalogueFromFile ¶ added in v0.9.0
ParseYAMLCatalogueFromFile parses filename, a YAML document, using ParseYamlCatalogue.
func RegisterTinkerbellHardware ¶
func RegisterTinkerbellHardware(ctx context.Context, client TinkerbellHardwarePusher, serializedJsons [][]byte) error
RegisterTinkerbellHardware uses client to push all serializedJsons representing TinkerbellHardwareJson to a Tinkerbell server.
func Translate ¶
func Translate(reader MachineReader, writer MachineWriter, validator MachineValidator) error
Translate reads 1 entry from reader and writes it to writer. When reader returns io.EOF Translate returns io.EOF to the caller.
func TranslateAll ¶
func TranslateAll(reader MachineReader, writer MachineWriter, validator MachineValidator) error
TranslateAll reads entries 1 at a time from reader and writes them to writer. When reader returns io.EOF, TranslateAll returns nil. Failure to return io.EOF from reader will result in an infinite loop.
func WithDefaultAssertions ¶
func WithDefaultAssertions(validator *DefaultMachineValidator)
WithDefaultAssertions applies a set of default assertions to validator. The default assertions include UniqueHostnames and UniqueIds.
Types ¶
type Catalogue ¶ added in v0.9.0
type Catalogue struct {
// contains filtered or unexported fields
}
Catalogue represents a catalogue of Tinkerbell hardware manifests to be used with Tinkerbells Kubefied back-end.
func NewCatalogue ¶ added in v0.9.0
func NewCatalogue(opts ...CatalogueOption) *Catalogue
NewCatalogue creates a new Catalogue instance.
func (*Catalogue) AllBMCs ¶ added in v0.9.0
func (c *Catalogue) AllBMCs() []*pbnjv1alpha1.BMC
AllBMCs retrieves a copy of the catalogued BMC instances.
func (*Catalogue) AllHardware ¶ added in v0.9.0
AllHardware retrieves a copy of the catalogued Hardware instances.
func (*Catalogue) AllSecrets ¶ added in v0.9.0
AllSecrets retrieves a copy of the catalogued Secret instances.
func (*Catalogue) HardwareSpecMarshallable ¶ added in v0.9.0
func (*Catalogue) IndexBMCs ¶ added in v0.9.0
func (c *Catalogue) IndexBMCs(index string, fn KeyExtractorFunc)
IndexBMCs indexes BMC instances on index by extracfting the key using fn.
func (*Catalogue) IndexHardware ¶ added in v0.9.0
func (c *Catalogue) IndexHardware(index string, fn KeyExtractorFunc)
IndexHardware indexes Hardware instances on index by extracfting the key using fn.
func (*Catalogue) IndexSecret ¶ added in v0.9.0
func (c *Catalogue) IndexSecret(index string, fn KeyExtractorFunc)
IndexSecret indexes Secret instances on index by extracfting the key using fn.
func (*Catalogue) InsertBMC ¶ added in v0.9.0
func (c *Catalogue) InsertBMC(bmc *pbnjv1alpha1.BMC) error
InsertBMC inserts BMCs into the catalogue. If any indexes exist, the BMC is indexed.
func (*Catalogue) InsertHardware ¶ added in v0.9.0
InsertHardware inserts Hardware into the catalogue. If any indexes exist, the hardware is indexed.
func (*Catalogue) InsertSecret ¶ added in v0.9.0
InsertSecret inserts Secrets into the catalogue. If any indexes exist, the Secret is indexed.
func (*Catalogue) LookupBMC ¶ added in v0.9.0
func (c *Catalogue) LookupBMC(index, key string) ([]*pbnjv1alpha1.BMC, error)
LookupBMC retrieves BMC instances on index with a key of key. Multiple BMCs _may_ have the same key hence it can return multiple BMCs.
func (*Catalogue) LookupHardware ¶ added in v0.9.0
LookupHardware retrieves Hardware instances on index with a key of key. Multiple hardware _may_ have the same key hence it can return multiple Hardware.
func (*Catalogue) LookupSecret ¶ added in v0.9.0
LookupSecret retrieves Secret instances on index with a key of key. Multiple Secrets _may_ have the same key hence it can return multiple Secrets.
func (*Catalogue) TotalBMCs ¶ added in v0.9.0
TotalBMCs returns the total BMCs registered in the catalogue.
func (*Catalogue) TotalHardware ¶ added in v0.9.0
TotalHardware returns the total hardware registered in the catalogue.
func (*Catalogue) TotalSecrets ¶ added in v0.9.0
TotalSecrets returns the total Secrets registered in the catalogue.
func (*Catalogue) ValidateBMC ¶ added in v0.9.0
func (*Catalogue) ValidateBmcSecretRefs ¶ added in v0.9.0
func (*Catalogue) ValidateHardware ¶ added in v0.9.0
func (c *Catalogue) ValidateHardware(skipPowerActions, force bool, tinkHardwareMap map[string]*tinkhardware.Hardware, tinkWorkflowMap map[string]*tinkworkflow.Workflow) error
type CatalogueOption ¶ added in v0.9.0
type CatalogueOption func(*Catalogue)
CatalogueOption defines an option to be applied in Catalogue instantiation.
func WithBMCNameIndex ¶ added in v0.9.0
func WithBMCNameIndex() CatalogueOption
WithBMCNameIndex creates a BMC index using BMCNameIndex on BMC.ObjectMeta.Name.
func WithHardwareBMCRefIndex ¶ added in v0.9.0
func WithHardwareBMCRefIndex() CatalogueOption
WithHardwareBMCRefIndex creates a Hardware index using HardwareBMCRefIndex on Hardware.Spec.BmcRef.
func WithHardwareIDIndex ¶ added in v0.9.0
func WithHardwareIDIndex() CatalogueOption
WithHardwareIDIndex creates a Hardware index using HardwareIDIndex on Hardware.Spec.ID values.
func WithSecretNameIndex ¶ added in v0.9.0
func WithSecretNameIndex() CatalogueOption
WithSecretNameIndex creates a Secret index using SecretNameIndex on Secret.ObjectMeta.Name.
type CsvReader ¶
type CsvReader struct {
// contains filtered or unexported fields
}
CsvReader reads a CSV file and provides Machine instances. It satisfies the MachineReader interface. The Id field of the Machine is optional in the CSV. If unspecified, CsvReader will generate a UUID and apply it to the machine.
func NewCsvReader ¶
NewCsvReader returns a new CsvReader instance that consumes csv data from r. r should return io.EOF when no more records are available.
func NewCsvReaderWithUUIDGenerator ¶
NewCsvReaderWithUUIDGenerator returns a new CsvReader instance as defined in NewCsvReader with its internal UUID generator configured as generator.
type DefaultMachineValidator ¶
type DefaultMachineValidator struct {
// contains filtered or unexported fields
}
DefaultMachineValidator validated Machine instances.
func NewDefaultMachineValidator ¶
func NewDefaultMachineValidator() *DefaultMachineValidator
NewDefaultMachineValidator creates a machineValidator instance with default assertions registered.
func (*DefaultMachineValidator) Register ¶
func (mv *DefaultMachineValidator) Register(v ...MachineAssertion)
Register registers v MachineAssertions with m.
func (*DefaultMachineValidator) Validate ¶
func (mv *DefaultMachineValidator) Validate(machine Machine) error
Validate validates machine by executing its Validate() method and passing it to all registered MachineAssertions.
type ErrIncorrectType ¶ added in v0.9.0
ErrIncorrectType indicates an incorrect type was used with a FieldIndexer.
func (ErrIncorrectType) Error ¶ added in v0.9.0
func (e ErrIncorrectType) Error() string
type ErrUnknownIndex ¶ added in v0.9.0
type ErrUnknownIndex struct {
Field string
}
func (ErrUnknownIndex) Error ¶ added in v0.9.0
func (e ErrUnknownIndex) Error() string
type FieldIndexer ¶ added in v0.9.0
type FieldIndexer struct {
// contains filtered or unexported fields
}
FieldIndexer indexes collection of objects for a single type against one of its fields. FieldIndexer is not thread safe.
func NewFieldIndexer ¶ added in v0.9.0
func NewFieldIndexer(object interface{}) *FieldIndexer
NewFieldIndexer creates a new FieldIndexer instance. object is the object to be indexed and will be checked during Insert() calls. NewFieldIndexer will panic if object is nil.
func (*FieldIndexer) IndexField ¶ added in v0.9.0
func (i *FieldIndexer) IndexField(field string, fn KeyExtractorFunc)
IndexField registers a new index with i. field is the index name and should represent a path to the field such as `.Spec.ID`. fn is used to extract the lookup key on Insert() from the object to be inserted.
func (*FieldIndexer) Insert ¶ added in v0.9.0
func (i *FieldIndexer) Insert(v interface{}) error
Insert inserts v into i on all indexed fields registered with IndexField. If v is not of the expected type defined by NewFieldIndexer() ErrIncorrectType is returned. Multiple objects with the same index value may be inserted.
func (*FieldIndexer) Lookup ¶ added in v0.9.0
func (i *FieldIndexer) Lookup(field string, key string) ([]interface{}, error)
Lookup uses the index associated with field to find and return all objects associated with key. If field has no associated index created by IndexField ErrUnknownIndex is returned.
func (*FieldIndexer) Remove ¶ added in v0.9.0
func (i *FieldIndexer) Remove(v interface{}) error
Remove removes v from all indexes if present. If v is not present Remove is a no-op. If v is of an incorrect type ErrUnknownType is returned.
type Hardware ¶
type Hardware struct {
Id string `json:"id"`
Metadata *packet.Metadata `json:"metadata"`
Network *hardware.Hardware_Network `json:"network"`
}
Hardware describes the hardware json structure required by the Tinkerbell API when registering hardware.
type Indexer ¶ added in v0.9.0
type Indexer interface {
// Lookup retrieves objects associated with the index => value pair.
Lookup(index, value string) ([]interface{}, error)
// Insert inserts v int the index.
Insert(v interface{}) error
// IndexField associated index with fn such that Lookup may be used to retrieve objects.
IndexField(index string, fn KeyExtractorFunc)
}
Indexer provides indexing behavior for objects.
type Journal ¶
type Journal [][]byte
Journal is an io.Writer that records the byte data passed to Write() as distinct chunks.
type KeyExtractorFunc ¶ added in v0.9.0
type KeyExtractorFunc func(object interface{}) string
KeyExtractorFunc returns a key from object that can be used to look up the object.
type Machine ¶
type Machine struct {
Id string `csv:"id"`
IpAddress string `csv:"ip_address"`
Gateway string `csv:"gateway"`
Nameservers Nameservers `csv:"nameservers"`
Netmask string `csv:"netmask"`
MacAddress string `csv:"mac"`
Hostname string `csv:"hostname"`
BmcIpAddress string `csv:"bmc_ip"`
BmcUsername string `csv:"bmc_username"`
BmcPassword string `csv:"bmc_password"`
BmcVendor string `csv:"vendor"`
}
Machine is a machine configuration with optional BMC interface configuration.
type MachineAssertion ¶
MachineAssertion defines a condition that Machine must meet.
func UniqueBmcIpAddress ¶
func UniqueBmcIpAddress() MachineAssertion
UniqueBmcIpAddress asserts a given Machine instance has a unique BmcIpAddress field relative to previously seen Machine instances. If there is no Bmc configuration as defined by machine.HasBmc() the check is a noop. It is not thread safe. It has a 1 time use.
func UniqueHostnames ¶
func UniqueHostnames() MachineAssertion
UniqueHostnames asserts a given Machine instance has a unique Hostname field relative to previously seen Machine instances. It is not thread safe. It has a 1 time use.
func UniqueIds ¶
func UniqueIds() MachineAssertion
UniqueIds asserts a given Machine instance has a unique Id field relative to previously seen Machine instances. It is not thread safe. It has a 1 time use.
func UniqueIpAddress ¶
func UniqueIpAddress() MachineAssertion
UniqueIpAddress asserts a given Machine instance has a unique IpAddress field relative to previously seen Machine instances. It is not thread safe. It has a 1 time use.
func UniqueMacAddress ¶
func UniqueMacAddress() MachineAssertion
UniqueMacAddress asserts a given Machine instance has a unique MacAddress field relative to previously seen Machine instances. It is not thread safe. It has a 1 time use.
type MachineReader ¶
MachineReader reads single Machine configuration at a time. When there are no more Machine entries to be read, Read() returns io.EOF.
type MachineValidator ¶
MachineValidator validates an instance of Machine.
type MachineWriter ¶
MachineWriter writes Machine entries.
func MultiMachineWriter ¶
func MultiMachineWriter(writers ...MachineWriter) MachineWriter
MultiMachineWriter combines writers into a single MachineWriter instance. Passing no writers effectively creates a noop MachineWriter.
type Nameservers ¶
type Nameservers []string
Nameservers is a custom type that can unmarshal a CSV representation of nameservers.
func (*Nameservers) MarshalCSV ¶
func (n *Nameservers) MarshalCSV() (string, error)
MarshalCSV marshalls Nameservers into a string list of nameservers separated by NameserversSeparator.
func (*Nameservers) String ¶
func (n *Nameservers) String() string
func (*Nameservers) UnmarshalCSV ¶
func (n *Nameservers) UnmarshalCSV(s string) error
UnmarshalCSV unmarshalls s where is is a list of nameservers separated by NameserversSeparator.
type TinkerbellHardwareJson ¶
type TinkerbellHardwareJson struct {
// contains filtered or unexported fields
}
TinkerbellHardwareJson represents a discrete Tinkerbell hardware json file. It can only be written to once.
func NewTinkerbellHardwareJson ¶
func NewTinkerbellHardwareJson(w io.WriteCloser) *TinkerbellHardwareJson
NewTinkerbellHardwareJson creates a new TinkerbellHardwareJson instance that uses w as its destination for Write calls.
func (*TinkerbellHardwareJson) Write ¶
func (tj *TinkerbellHardwareJson) Write(m Machine) error
Write marshals m as a Tinkerbell hardware json object and writes it to tj's writer. Upon successfully completing the write, tj will close its writer. Subsequent calls to Write will return ErrTinkebellHardwareJsonRepeatWrites.
type TinkerbellHardwareJsonFactory ¶
type TinkerbellHardwareJsonFactory interface {
Create(name string) (*TinkerbellHardwareJson, error)
}
TinkerbellHardwareJsonFactory creates new TinkerbellHardwareJson instances.
func RecordingTinkerbellHardwareJsonFactory ¶
func RecordingTinkerbellHardwareJsonFactory(basepath string, journal *Journal) (TinkerbellHardwareJsonFactory, error)
RecordingTinkerbellHardwareJsonFactory creates a new TinkerbellHardwareJson where all writes to the TinkerbellHardwareJson are recorded in journal.
type TinkerbellHardwareJsonWriter ¶
type TinkerbellHardwareJsonWriter struct {
// contains filtered or unexported fields
}
TinkerbellHardwareJsonWriter writes discrete instances of TinkerbellHardwareJson's. Paths for files that were successfully written can be retrieved from Journal().
func NewTinkerbellHardwareJsonWriter ¶
func NewTinkerbellHardwareJsonWriter(factory TinkerbellHardwareJsonFactory) *TinkerbellHardwareJsonWriter
NewTinkerbellHardwareJsonWriter creates a newTinkerbellHardwareJsonWriter instance that uses factory to create TinkerbellHardwareJson instances and write to them.
func (*TinkerbellHardwareJsonWriter) Write ¶
func (tw *TinkerbellHardwareJsonWriter) Write(m Machine) error
Write creates a new TinkerbellHardwareJson instance and writes m to it.
type TinkerbellHardwarePusher ¶
type TinkerbellHardwarePusher interface {
PushHardware(ctx context.Context, hardware []byte) error
}
TinkerbellHardwarePusher registers hardware with a Tinkerbell stack.
type TinkerbellManifestYaml ¶
type TinkerbellManifestYaml struct {
// contains filtered or unexported fields
}
TinkerbellManifestYaml is a MachineWriter that writes Tinkerbell manifests to a destination.
func NewTinkerbellManifestYaml ¶
func NewTinkerbellManifestYaml(w io.Writer) *TinkerbellManifestYaml
NewTinkerbellManifestYaml creates a TinkerbellManifestYaml instance that writes its manifests to w.
func (*TinkerbellManifestYaml) Write ¶
func (yw *TinkerbellManifestYaml) Write(m Machine) error
Write m as a set of Kubernetes manifests for use with Cluster API Tinkerbell Provider. This includes writing a Hardware, BMC and Secret (for the BMC).