hardware

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultHardwareManifestYamlFilename = "hardware.yaml"

DefaultHardwareManifestYamlFilename is the default file for writing yinkerbell yaml manifests

View Source
const DefaultJsonDir = "json"

DefaultJsonDir is the default directory for writing hardware json files.

View Source
const DefaultManifestDir = "hardware-manifests"

DefaultManifestDir is the default directory for writing Tinkerbell hardware files.

View Source
const NameserversSeparator = "|"

NameserversSeparator is used to unmarshal Nameservers.

Variables

View Source
var ErrTinkebellHardwareJsonRepeatWrites = errors.New("TinkerbellHardwareJson can only be written to once")

ErrTinkebellHardwareJsonRepeatWrites occurs when a TinkerbellHardwareJson receives multiple calls to Write().

Functions

func CreateDefaultJsonDir

func CreateDefaultJsonDir(basepath string) (string, error)

CreateDefaultJsonDir creates the defaut directory where hardware json files are written returning it as the string parameter.

func CreateManifestDir

func CreateManifestDir(path string) (string, error)

CreateDefaultManifestDir creates the defaut directory where hardware files are written returning it as the string parameter.

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

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 NewCsvReaderWithUUIDGenerator

func NewCsvReaderWithUUIDGenerator(r io.Reader, generator func() string) (CsvReader, error)

NewCsvReaderWithUUIDGenerator returns a new CsvReader instance as defined in NewCsvReader with its internal UUID generator configured as generator.

func (CsvReader) Read

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

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

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

type HardwareConfig struct {
	Hardwares []tinkv1alpha1.Hardware
	Bmcs      []pbnjv1alpha1.BMC
	Secrets   []corev1.Secret
}

func (*HardwareConfig) ParseHardwareConfig

func (hc *HardwareConfig) ParseHardwareConfig(hardwareFileName string) error

func (*HardwareConfig) ValidateBMC

func (hc *HardwareConfig) ValidateBMC() error

func (*HardwareConfig) ValidateBmcSecretRefs

func (hc *HardwareConfig) ValidateBmcSecretRefs() error

func (*HardwareConfig) ValidateHardware

func (hc *HardwareConfig) ValidateHardware(skipPowerActions bool, tinkHardwareMap map[string]*tinkhardware.Hardware, tinkWorkflowMap map[string]*tinkworkflow.Workflow) error

type Journal

type Journal [][]byte

Journal is an io.Writer that records the byte data passed to Write() as distinct chunks.

func (*Journal) Write

func (journal *Journal) Write(b []byte) (int, error)

Write records b as a distinct chunk in journal before returning len(b). It never returns an error.

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.

func (*Machine) HasBmc

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.

func (*Machine) Validate

func (m *Machine) Validate() error

Validate ensures all fields on m are valid. Bmc configurationis only validated if m.HasBmc() returns true.

type MachineAssertion

type MachineAssertion func(Machine) error

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

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.

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.

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

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

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