kube

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: Apache-2.0 Imports: 33 Imported by: 2

Documentation

Overview

Package kube is a backend implementation that uses the Tinkerbell CRDs to get DHCP data.

Index

Constants

View Source
const HardwareByAgentID = ".spec.agentID"
View Source
const HardwareNameIndex = ".metadata.name"

NameIndex is an index used with a controller-runtime client to lookup objects by name.

View Source
const IPAddrIndex = ".Spec.Interfaces.DHCP.IP"

IPAddrIndex is an index used with a controller-runtime client to lookup hardware by IP.

View Source
const MACAddrIndex = ".Spec.Interfaces.MAC"

MACAddrIndex is an index used with a controller-runtime client to lookup hardware by MAC.

View Source
const MachineNameIndex = ".metadata.name"
View Source
const WorkflowByAgentID = ".status.agentID"

Variables

View Source
var ErrInstanceNotFound = errors.New("instance not found")

ErrInstanceNotFound indicates an instance could not be found for the given identifier.

View Source
var Indexes = map[IndexType]Index{
	IndexTypeMACAddr: {
		Obj:          &tinkerbell.Hardware{},
		Field:        MACAddrIndex,
		ExtractValue: MACAddrs,
	},
	IndexTypeIPAddr: {
		Obj:          &tinkerbell.Hardware{},
		Field:        IPAddrIndex,
		ExtractValue: IPAddrs,
	},
	IndexTypeHardwareName: {
		Obj:          &tinkerbell.Hardware{},
		Field:        HardwareNameIndex,
		ExtractValue: HardwareNameFunc,
	},
	IndexTypeMachineName: {
		Obj:          &bmc.Machine{},
		Field:        MachineNameIndex,
		ExtractValue: MachineNameFunc,
	},
	IndexTypeWorkflowAgentID: {
		Obj:          &tinkerbell.Workflow{},
		Field:        WorkflowByAgentID,
		ExtractValue: WorkflowByAgentIDFunc,
	},
	IndexTypeHardwareAgentID: {
		Obj:          &tinkerbell.Hardware{},
		Field:        HardwareByAgentID,
		ExtractValue: HardwareByAgentIDFunc,
	},
}

Indexes that are currently known.

Functions

func GetIPs

func GetIPs(h *tinkerbell.Hardware) []string

GetIPs retrieves all IP addresses.

func GetMACs

func GetMACs(h *tinkerbell.Hardware) []string

GetMACs retrieves all MACs associated with h.

func HardwareByAgentIDFunc added in v0.19.0

func HardwareByAgentIDFunc(obj client.Object) []string

func HardwareNameFunc

func HardwareNameFunc(obj client.Object) []string

func IPAddrs

func IPAddrs(obj client.Object) []string

IPAddrs returns a list of IP addresses for a Hardware object.

func MACAddrs

func MACAddrs(obj client.Object) []string

MACAddrs returns a list of MAC addresses for a Hardware object.

func MachineNameFunc

func MachineNameFunc(obj client.Object) []string

func NewFileRestConfig

func NewFileRestConfig(kubeconfigPath, namespace string) (*rest.Config, error)

func WorkflowByAgentIDFunc added in v0.18.0

func WorkflowByAgentIDFunc(obj client.Object) []string

Types

type Backend

type Backend struct {

	// ConfigFilePath is the path to a kubernetes config file (kubeconfig).
	ConfigFilePath string
	// APIURL is the Kubernetes API URL.
	APIURL string
	// Namespace is an override for the Namespace the kubernetes client will watch.
	// The default is the Namespace the pod is running in.
	Namespace string
	// ClientConfig is a Kubernetes client config. If specified, it will be used instead of
	// constructing a client using the other configuration in this object. Optional.
	ClientConfig *rest.Config
	// Indexes to register
	Indexes       map[IndexType]Index
	DynamicClient dynamic.Interface
	// contains filtered or unexported fields
}

Backend is a backend implementation that uses the Tinkerbell CRDs to get DHCP data.

func NewBackend

func NewBackend(cfg Backend, opts ...cluster.Option) (*Backend, error)

NewBackend returns a controller-runtime cluster.Cluster with the Tinkerbell runtime scheme registered, and indexers for: * Hardware by MAC address * Hardware by IP address

Callers must instantiate the client-side cache by calling Start() before use.

func (*Backend) CreateHardware added in v0.19.0

func (b *Backend) CreateHardware(ctx context.Context, hw *v1alpha1.Hardware) error

func (*Backend) CreateWorkflow added in v0.18.0

func (b *Backend) CreateWorkflow(ctx context.Context, wf *v1alpha1.Workflow) error

func (*Backend) DynamicRead added in v0.18.0

func (b *Backend) DynamicRead(ctx context.Context, gvr schema.GroupVersionResource, name, namespace string) (map[string]interface{}, error)

DynamicRead reads any Kubernetes resource, defined via gvr, name, and namespace, and returns the spec field as a map[string]interface{}. It uses the Kubernetes dynamic client to perform the read operation.

func (*Backend) GetByIP

func (b *Backend) GetByIP(ctx context.Context, ip net.IP) (*data.DHCP, *data.Netboot, error)

GetByIP implements the handler.BackendReader interface and returns DHCP and netboot data based on an IP address.

func (*Backend) GetByMac

func (b *Backend) GetByMac(ctx context.Context, mac net.HardwareAddr) (*data.DHCP, *data.Netboot, error)

GetByMac implements the handler.BackendReader interface and returns DHCP and netboot data based on a mac address.

func (*Backend) GetEC2Instance

func (b *Backend) GetEC2Instance(ctx context.Context, ip string) (data.Ec2Instance, error)

GetEC2InstanceByIP satisfies ec2.Client.

func (*Backend) GetHackInstance

func (b *Backend) GetHackInstance(ctx context.Context, ip string) (data.HackInstance, error)

GetHackInstance returns a hack.Instance by calling the hwByIP method and converting the result. This is a method that the Tootles service uses.

func (*Backend) Read

func (b *Backend) Read(ctx context.Context, workflowID, namespace string) (*v1alpha1.Workflow, error)

func (*Backend) ReadAll

func (b *Backend) ReadAll(ctx context.Context, agentID string) ([]v1alpha1.Workflow, error)

func (*Backend) ReadBMCMachine

func (b *Backend) ReadBMCMachine(ctx context.Context, name string) (*data.BMCMachine, error)

ReadBMCMachine implements the handler.BackendReader interface and returns DHCP and netboot data based on a mac address.

func (*Backend) ReadHardware added in v0.19.0

func (b *Backend) ReadHardware(ctx context.Context, id, namespace string) (*v1alpha1.Hardware, error)

func (*Backend) ReadWorkflowRuleSets added in v0.18.0

func (b *Backend) ReadWorkflowRuleSets(ctx context.Context) ([]v1alpha1.WorkflowRuleSet, error)

func (*Backend) Start

func (b *Backend) Start(ctx context.Context) error

Start starts the client-side cache.

func (*Backend) Update added in v0.18.0

func (b *Backend) Update(ctx context.Context, wf *v1alpha1.Workflow) error

func (*Backend) WaitForAPIServer

func (b *Backend) WaitForAPIServer(ctx context.Context, log logr.Logger, maxWaitTime time.Duration, pollInterval time.Duration, client rest.Interface) error

waitForAPIServer waits for the Kubernetes API server to become healthy.

type Index

type Index struct {
	Obj          client.Object
	Field        string
	ExtractValue client.IndexerFunc
}

type IndexType

type IndexType string
const (
	IndexTypeMACAddr         IndexType = MACAddrIndex
	IndexTypeIPAddr          IndexType = IPAddrIndex
	IndexTypeHardwareName    IndexType = "hardware.metadata.name"
	IndexTypeMachineName     IndexType = "machine.metadata.name"
	IndexTypeWorkflowAgentID IndexType = WorkflowByAgentID
	IndexTypeHardwareAgentID IndexType = HardwareByAgentID
)

Jump to

Keyboard shortcuts

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