kube

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: Apache-2.0 Imports: 27 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 (
	IndexTypeMACAddr         IndexType = MACAddrIndex
	IndexTypeIPAddr          IndexType = IPAddrIndex
	IndexTypeHardwareName    IndexType = "hardware.metadata.name"
	IndexTypeMachineName     IndexType = "machine.metadata.name"
	IndexTypeWorkflowAgentID IndexType = WorkflowAgentIDIndex
	IndexTypeHardwareAgentID IndexType = HardwareAgentIDIndex
	IndexTypeInstanceID      IndexType = InstanceIDIndex

	// MACAddrIndex is an index used with a controller-runtime client to lookup hardware by MAC.
	MACAddrIndex = ".Spec.Interfaces.MAC"

	// IPAddrIndex is an index used with a controller-runtime client to lookup hardware by IP.
	IPAddrIndex = ".Spec.Interfaces.DHCP.IP"

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

	// WorkflowAgentIDIndex is an index used with a controller-runtime client to lookup workflows by their status agent id.
	WorkflowAgentIDIndex = ".status.agentID"

	// HardwareAgentIDIndex is an index used with a controller-runtime client to lookup hardware by their spec agent id.
	HardwareAgentIDIndex = ".spec.agentID"

	// InstanceIDIndex is an index used with a controller-runtime client to lookup hardware by its metadata instance id.
	InstanceIDIndex = ".Spec.Metadata.Instance.ID" // #nosec G101 - This is a field path, not a credential

)

Variables

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:        NameIndex,
		ExtractValue: HardwareName,
	},
	IndexTypeMachineName: {
		Obj:          &bmc.Machine{},
		Field:        NameIndex,
		ExtractValue: MachineName,
	},
	IndexTypeWorkflowAgentID: {
		Obj:          &tinkerbell.Workflow{},
		Field:        WorkflowAgentIDIndex,
		ExtractValue: WorkflowAgentID,
	},
	IndexTypeHardwareAgentID: {
		Obj:          &tinkerbell.Hardware{},
		Field:        HardwareAgentIDIndex,
		ExtractValue: HardwareAgentID,
	},
	IndexTypeInstanceID: {
		Obj:          &tinkerbell.Hardware{},
		Field:        InstanceIDIndex,
		ExtractValue: InstanceID,
	},
}

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 HardwareAgentID added in v0.23.0

func HardwareAgentID(obj client.Object) []string

HardwareAgentID extracts the agent ID from a Hardware's spec for field indexing.

func HardwareName added in v0.23.0

func HardwareName(obj client.Object) []string

HardwareName extracts the name of a Hardware object for field indexing.

func IPAddrs

func IPAddrs(obj client.Object) []string

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

func InstanceID added in v0.23.0

func InstanceID(obj client.Object) []string

InstanceID extracts the instance ID from a Hardware's metadata for field indexing.

func MACAddrs

func MACAddrs(obj client.Object) []string

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

func MachineName added in v0.23.0

func MachineName(obj client.Object) []string

MachineName extracts the name of a BMC Machine object for field indexing.

func NewFileRestConfig

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

func WorkflowAgentID added in v0.23.0

func WorkflowAgentID(obj client.Object) []string

WorkflowAgentID extracts the agent ID from a Workflow's status for field indexing.

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
	// QPS is the maximum queries per second to the Kubernetes API server.
	// If set to 0, defaults to 5. Negative values disable rate limiting.
	QPS float32
	// Burst is the maximum burst for throttle in the Kubernetes client.
	// If set to 0, defaults to 10. Negative values disable burst limiting.
	Burst int
	// 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, w *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.

This is most useful for look ups of References in Tinkerbell CRDs.

func (*Backend) FilterBMCMachine added in v0.23.0

func (b *Backend) FilterBMCMachine(ctx context.Context, opts data.HardwareFilter) (*data.BMCMachine, error)

FilterBMCMachine looks up a machine.bmc.tinkerbell.org object based on the bmcRef in the hardware object matching the given filter.

func (*Backend) FilterHardware added in v0.23.0

func (b *Backend) FilterHardware(ctx context.Context, opts data.HardwareFilter) (*v1alpha1.Hardware, error)

FilterHardware looks up a single Hardware object using selector-based list filtering. Exactly one result is expected; zero results returns a not-found error and multiple results returns a multiple-found error.

func (*Backend) ListHardware added in v0.23.0

func (b *Backend) ListHardware(ctx context.Context, opts data.HardwareFilter) ([]v1alpha1.Hardware, error)

func (*Backend) ListWorkflowRuleSets added in v0.23.0

func (b *Backend) ListWorkflowRuleSets(ctx context.Context, opts data.WorkflowFilter) ([]v1alpha1.WorkflowRuleSet, error)

func (*Backend) ListWorkflows added in v0.23.0

func (b *Backend) ListWorkflows(ctx context.Context, opts data.WorkflowFilter) ([]v1alpha1.Workflow, error)

func (*Backend) ReadAuthSecret added in v0.23.0

func (b *Backend) ReadAuthSecret(ctx context.Context, name, namespace string) (string, string, error)

ReadAuthSecret looks up a Secret by name and namespace using a direct Get. It expects the Secret to contain "username" and "password" keys in its data.

func (*Backend) ReadHardware added in v0.19.0

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

ReadHardware looks up a Hardware object by name and namespace using a direct Get.

func (*Backend) ReadWorkflow added in v0.23.0

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

func (*Backend) Start

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

Start starts the client-side cache.

func (*Backend) UpdateHardware added in v0.23.0

func (b *Backend) UpdateHardware(ctx context.Context, hw *v1alpha1.Hardware, opts data.UpdateOptions) error

func (*Backend) UpdateWorkflow added in v0.23.0

func (b *Backend) UpdateWorkflow(ctx context.Context, wf *v1alpha1.Workflow, opts data.UpdateOptions) 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

Jump to

Keyboard shortcuts

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