hardware

package
v0.15.4 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const BMCNameIndex = ".ObjectMeta.Name"
View Source
const HardwareBMCRefIndex = ".Spec.BmcRef"
View Source
const HardwareIDIndex = ".Spec.Metadata.Instance.ID"
View Source
const LabelsSeparator = "|"

LabelSSeparator is used to separate key value label pairs.

View Source
const NameserversSeparator = "|"

NameserversSeparator is used to unmarshal Nameservers.

View Source
const OwnerNameLabel string = "v1alpha1.tinkerbell.org/ownerName"

OwnerNameLabel is the label set by CAPT to mark a hardware as part of a cluster.

View Source
const SecretNameIndex = ".ObjectMeta.Name"

Variables

This section is empty.

Functions

func BuildHardwareYAML added in v0.15.0

func BuildHardwareYAML(path string) ([]byte, error)

BuildHardwareYAML builds a hardware yaml from the csv at the provided path.

func CreateOrStdout added in v0.9.2

func CreateOrStdout(path string) (*os.File, error)

CreateOrStdout will create path and return an *os.File if path is not empty. If path is empty os.Stdout is returned.

func LabelsMatchSelector added in v0.9.2

func LabelsMatchSelector(selector v1alpha1.HardwareSelector, labels Labels) bool

LabelsMatchSelector ensures all selector key-value pairs can be found in labels. If selector is empty true is always returned.

func MarshalCatalogue added in v0.9.2

func MarshalCatalogue(c *Catalogue) ([]byte, error)

MarshalCatalogue marshals c into YAML that can be submitted to a Kubernetes cluster.

func ParseYAMLCatalogue added in v0.9.0

func ParseYAMLCatalogue(catalogue *Catalogue, r io.Reader) error

ParseYAMLCatalogue 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

func ParseYAMLCatalogueFromFile(catalogue *Catalogue, filename string) error

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 RegisterDefaultNormalizations added in v0.9.2

func RegisterDefaultNormalizations(n *Normalizer)

RegisterDefaultNormalizations registers a set of default normalizations on n.

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 BMCCatalogueWriter added in v0.9.2

type BMCCatalogueWriter struct {
	// contains filtered or unexported fields
}

BMCCatalogueWriter converts Machine instances to Tinkerbell Machine and inserts them in a catalogue.

func NewBMCCatalogueWriter added in v0.9.2

func NewBMCCatalogueWriter(catalogue *Catalogue) *BMCCatalogueWriter

NewBMCCatalogueWriter creates a new BMCCatalogueWriter instance.

func (*BMCCatalogueWriter) Write added in v0.9.2

func (w *BMCCatalogueWriter) Write(m Machine) error

Write converts m to a Tinkerbell Machine and inserts it into w's Catalogue.

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

func NewCSVReader(r io.Reader) (CSVReader, error)

NewCSVReader returns a new CSVReader instance that consumes csv data from r. r should return io.EOF when no more records are available.

func (CSVReader) Read added in v0.9.1

func (cr CSVReader) Read() (Machine, error)

Read reads a single entry from the CSV data source and returns a new Machine representation.

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() []*v1alpha1.Machine

AllBMCs retrieves a copy of the catalogued BMC instances.

func (*Catalogue) AllHardware added in v0.9.0

func (c *Catalogue) AllHardware() []*tinkv1alpha1.Hardware

AllHardware retrieves a copy of the catalogued Hardware instances.

func (*Catalogue) AllSecrets added in v0.9.0

func (c *Catalogue) AllSecrets() []*corev1.Secret

AllSecrets retrieves a copy of the catalogued Secret instances.

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 *v1alpha1.Machine) error

InsertBMC inserts BMCs into the catalogue. If any indexes exist, the BMC is indexed.

func (*Catalogue) InsertHardware added in v0.9.0

func (c *Catalogue) InsertHardware(hardware *tinkv1alpha1.Hardware) error

InsertHardware inserts Hardware into the catalogue. If any indexes exist, the hardware is indexed.

func (*Catalogue) InsertSecret added in v0.9.0

func (c *Catalogue) InsertSecret(secret *corev1.Secret) error

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) ([]*v1alpha1.Machine, 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

func (c *Catalogue) LookupHardware(index, key string) ([]*tinkv1alpha1.Hardware, error)

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

func (c *Catalogue) LookupSecret(index, key string) ([]*corev1.Secret, error)

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) RemoveHardwares added in v0.12.0

func (c *Catalogue) RemoveHardwares(hardware []tinkv1alpha1.Hardware) error

RemoveHardwares removes a slice of hardwares from the catalogue.

func (*Catalogue) TotalBMCs added in v0.9.0

func (c *Catalogue) TotalBMCs() int

TotalBMCs returns the total BMCs registered in the catalogue.

func (*Catalogue) TotalHardware added in v0.9.0

func (c *Catalogue) TotalHardware() int

TotalHardware returns the total hardware registered in the catalogue.

func (*Catalogue) TotalSecrets added in v0.9.0

func (c *Catalogue) TotalSecrets() int

TotalSecrets returns the total Secrets registered in the catalogue.

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 .ObjectMeta.Name.

func WithHardwareBMCRefIndex added in v0.9.0

func WithHardwareBMCRefIndex() CatalogueOption

WithHardwareBMCRefIndex creates a Hardware index using HardwareBMCRefIndex on .Spec.BmcRef.

func WithHardwareIDIndex added in v0.9.0

func WithHardwareIDIndex() CatalogueOption

WithHardwareIDIndex creates a Hardware index using HardwareIDIndex on .Spec.Metadata.Instance.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 ErrDiskNotFound added in v0.9.2

type ErrDiskNotFound struct {
	// A unique identifier for the selector, preferrably something useful to an end-user.
	SelectorID string
}

ErrDiskNotFound indicates a disk was not found for a given selector.

func (ErrDiskNotFound) Error added in v0.9.2

func (e ErrDiskNotFound) Error() string

func (ErrDiskNotFound) Is added in v0.9.2

func (ErrDiskNotFound) Is(t error) bool

type ErrIncorrectType added in v0.9.0

type ErrIncorrectType struct {
	Expected reflect.Type
	Received reflect.Type
}

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 HardwareCatalogueWriter added in v0.9.2

type HardwareCatalogueWriter struct {
	// contains filtered or unexported fields
}

HardwareCatalogueWriter converts Machine instances to Tinkerbell Hardware and inserts them in a catalogue.

func NewHardwareCatalogueWriter added in v0.9.2

func NewHardwareCatalogueWriter(catalogue *Catalogue) *HardwareCatalogueWriter

NewHardwareCatalogueWriter creates a new HardwareCatalogueWriter instance.

func (*HardwareCatalogueWriter) Write added in v0.9.2

Write converts m to a Tinkerbell Hardware and inserts it into w's Catalogue.

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)
	// Remove deletes v from the index.
	Remove(v interface{}) error
}

Indexer provides indexing behavior for objects.

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 KubeReader added in v0.15.0

type KubeReader struct {
	// contains filtered or unexported fields
}

KubeReader reads the tinkerbell hardware objects from the cluster. It holds the objects in a catalogue.

func NewKubeReader added in v0.15.0

func NewKubeReader(client client.Client) *KubeReader

NewKubeReader returns a new instance of KubeReader. Defines a new Catalogue for each KubeReader instance.

func (*KubeReader) GetCatalogue added in v0.15.0

func (kr *KubeReader) GetCatalogue() *Catalogue

GetCatalogue returns the KubeReader catalogue.

func (*KubeReader) LoadHardware added in v0.15.0

func (kr *KubeReader) LoadHardware(ctx context.Context) error

LoadHardware fetches the unprovisioned tinkerbell hardware objects and inserts in to KubeReader catalogue.

func (*KubeReader) LoadRufioMachines added in v0.15.0

func (kr *KubeReader) LoadRufioMachines(ctx context.Context) error

LoadRufioMachines fetches rufio machine objects from the cluster and inserts into KubeReader catalogue.

type Labels added in v0.9.1

type Labels map[string]string

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

func (l Labels) Get(k string) string

See https://pkg.go.dev/k8s.io/apimachinery/pkg/labels#Labels

func (Labels) Has added in v0.9.1

func (l Labels) Has(k string) bool

Get returns the value for the provided label.

func (*Labels) MarshalCSV added in v0.9.2

func (l *Labels) MarshalCSV() (string, error)

func (Labels) String added in v0.9.1

func (l Labels) String() string

func (*Labels) UnmarshalCSV added in v0.9.1

func (l *Labels) UnmarshalCSV(s string) error

type Machine

type Machine struct {
	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"`

	// Disk used to populate the default workflow actions.
	// Currently needs to be the same for all hardware residing in the same group where a group
	// is either: control plane hardware, external etcd hard, or the definable worker node groups.
	Disk string `csv:"disk"`

	// Labels to be applied to the Hardware resource.
	Labels Labels `csv:"labels"`

	BMCIPAddress string `csv:"bmc_ip, omitempty"`
	BMCUsername  string `csv:"bmc_username, omitempty"`
	BMCPassword  string `csv:"bmc_password, omitempty"`
	VLANID       string `csv:"vlan_id, omitempty"`
}

Machine is a machine configuration with optional BMC interface configuration.

func LowercaseMACAddress added in v0.9.2

func LowercaseMACAddress(m Machine) Machine

LowercaseMACAddress ensures m's MACAddress field has lower chase characters.

func (*Machine) HasBMC added in v0.9.1

func (m *Machine) HasBMC() bool

HasBMC determines if m has a BMC configuration. A BMC configuration is present if any of the BMC fields contain non-empty strings.

type MachineAssertion

type MachineAssertion func(Machine) error

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 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

type MachineReader interface {
	Read() (Machine, error)
}

MachineReader reads single Machine configuration at a time. When there are no more Machine entries to be read, Read() returns io.EOF.

func NewNormalizedCSVReaderFromFile added in v0.9.2

func NewNormalizedCSVReaderFromFile(path string) (MachineReader, error)

NewNormalizedCSVReaderFromFile creates a MachineReader instance backed by a CSVReader reading from path that applies default normalizations to machines.

type MachineValidator

type MachineValidator interface {
	Validate(Machine) error
}

MachineValidator validates an instance of Machine.

type MachineWriter

type MachineWriter interface {
	Write(Machine) error
}

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.

func NewMachineCatalogueWriter added in v0.9.2

func NewMachineCatalogueWriter(catalogue *Catalogue) MachineWriter

NewMachineCatalogueWriter creates a MachineWriter instance that writes Machine instances to catalogue including its Machine and Secret data.

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 Normalizer added in v0.9.2

type Normalizer struct {
	// contains filtered or unexported fields
}

Normalizer is a decorator for a MachineReader that applies a set of normalization funcs to machines.

func NewNormalizer added in v0.9.2

func NewNormalizer(r MachineReader) *Normalizer

NewNormalizer creates a Normalizer instance that decorates r's Read(). A set of default normalization functions are pre-registered.

func NewRawNormalizer added in v0.9.2

func NewRawNormalizer(r MachineReader) *Normalizer

NewRawNormalizer returns a Normalizer with default normalizations registered by RegisterDefaultNormalizations.

func (Normalizer) Read added in v0.9.2

func (n Normalizer) Read() (Machine, error)

Read reads an Machine from the decorated MachineReader, applies all normalization funcs and returns the machine. If the decorated MachineReader errors, it is returned.

func (*Normalizer) Register added in v0.9.2

func (n *Normalizer) Register(fn NormalizerFunc)

Register fn to n such that fn is run over each machine read from the wrapped MachineReader.

type NormalizerFunc added in v0.9.2

type NormalizerFunc func(Machine) Machine

NormalizerFunc applies a normalization transformation to the Machine.

type SecretCatalogueWriter added in v0.9.2

type SecretCatalogueWriter struct {
	// contains filtered or unexported fields
}

SecretCatalogueWriter converts Machine instances to Tinkerbell BaseboardManagement and inserts them in a catalogue.

func NewSecretCatalogueWriter added in v0.9.2

func NewSecretCatalogueWriter(catalogue *Catalogue) *SecretCatalogueWriter

NewSecretCatalogueWriter creates a new SecretCatalogueWriter instance.

func (*SecretCatalogueWriter) Write added in v0.9.2

func (w *SecretCatalogueWriter) Write(m Machine) error

Write converts m to a Tinkerbell BaseboardManagement and inserts it into w's Catalogue.

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).

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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