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 RegisterDefaultAssertions(validator *DefaultMachineValidator)
- 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
- type CSVReader
- 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 DefaultMachineValidator
- type ErrIncorrectType
- type ErrUnknownIndex
- type FieldIndexer
- type Hardware
- type Indexer
- type Journal
- type KeyExtractorFunc
- type Labels
- 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 ¶ added in v0.9.1
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 RegisterDefaultAssertions ¶ added in v0.9.1
func RegisterDefaultAssertions(validator *DefaultMachineValidator)
RegisterDefaultAssertions applies a set of default assertions to validator. The default assertions include UniqueHostnames and UniqueIDs.
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.
Types ¶
type CSVReader ¶ added in v0.9.1
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 ¶ added in v0.9.1
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 ¶ added in v0.9.1
NewCSVReaderWithUUIDGenerator returns a new CSVReader instance as defined in NewCSVReader with its internal UUID generator configured as generator.
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 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 Labels ¶ added in v0.9.1
Labels defines a lebsl set. It satisfies https://pkg.go.dev/k8s.io/apimachinery/pkg/labels#Labels.
func (Labels) Get ¶ added in v0.9.1
See https://pkg.go.dev/k8s.io/apimachinery/pkg/labels#Labels
func (*Labels) UnmarshalCSV ¶ added in v0.9.1
type Machine ¶
type Machine struct { ID string `csv:"id"` Hostname string `csv:"hostname"` IPAddress string `csv:"ip_address"` Netmask string `csv:"netmask"` Gateway string `csv:"gateway"` Nameservers Nameservers `csv:"nameservers"` MACAddress string `csv:"mac"` // Labels to be applied to the Hardware resource. Labels Labels `csv:"labels"` BMCIPAddress string `csv:"bmc_ip"` BMCUsername string `csv:"bmc_username"` BMCPassword string `csv:"bmc_password"` BMCVendor string `csv:"bmc_vendor"` }
Machine is a machine configuration with optional BMC interface configuration.
type MachineAssertion ¶
MachineAssertion defines a condition that Machine must meet.
func StaticMachineAssertions ¶ added in v0.9.1
func StaticMachineAssertions() MachineAssertion
StaticMachineAssertions defines all static data assertions performed on a Machine.
func UniqueBMCIPAddress ¶ added in v0.9.1
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 ¶ added in v0.9.1
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 ¶ added in v0.9.1
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 ¶ added in v0.9.1
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 ¶ added in v0.9.1
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 ¶ added in v0.9.1
func NewTinkerbellHardwareJSON(w io.WriteCloser) *TinkerbellHardwareJSON
NewTinkerbellHardwareJSON creates a new TinkerbellHardwareJSON instance that uses w as its destination for Write calls.
func (*TinkerbellHardwareJSON) Write ¶ added in v0.9.1
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 ¶ added in v0.9.1
type TinkerbellHardwareJSONFactory interface {
Create(name string) (*TinkerbellHardwareJSON, error)
}
TinkerbellHardwareJSONFactory creates new TinkerbellHardwareJSON instances.
func RecordingTinkerbellHardwareJSONFactory ¶ added in v0.9.1
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 ¶ added in v0.9.1
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 ¶ added in v0.9.1
func NewTinkerbellHardwareJSONWriter(factory TinkerbellHardwareJSONFactory) *TinkerbellHardwareJSONWriter
NewTinkerbellHardwareJSONWriter creates a newTinkerbellHardwareJSONWriter instance that uses factory to create TinkerbellHardwareJSON instances and write to them.
func (*TinkerbellHardwareJSONWriter) Write ¶ added in v0.9.1
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 ¶ added in v0.9.1
type TinkerbellManifestYAML struct {
// contains filtered or unexported fields
}
TinkerbellManifestYAML is a MachineWriter that writes Tinkerbell manifests to a destination.
func NewTinkerbellManifestYAML ¶ added in v0.9.1
func NewTinkerbellManifestYAML(w io.Writer) *TinkerbellManifestYAML
NewTinkerbellManifestYAML creates a TinkerbellManifestYAML instance that writes its manifests to w.
func (*TinkerbellManifestYAML) Write ¶ added in v0.9.1
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).