kube

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 46 Imported by: 1 module, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
	// Namespaces are the namespaces the kubernetes client watches, one watch per
	// namespace and type. Empty means all namespaces.
	// Only the cache enforces them, so reads that bypass the cache must check them
	// themselves, with Watches.
	Namespaces []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

	// HardwareReferenceAllowListRules and HardwareReferenceDenyListRules are the Quamina rules
	// ResolveReferences applies. An empty deny list denies every reference.
	HardwareReferenceAllowListRules []string
	HardwareReferenceDenyListRules  []string
	// Rendering serves Hardware with the templates in its spec rendered.
	Rendering bool
	// Logger receives background rendering errors. Optional.
	Logger logr.Logger

	// 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) ApplyHardwareInBandAttributes added in v0.26.0

func (b *Backend) ApplyHardwareInBandAttributes(ctx context.Context, name, namespace string, attrs *v1alpha1.Attributes) error

ApplyHardwareInBandAttributes issues a Server-Side Apply patch for status.attributes.inBand, scoped to only that path so it never conflicts with Rufio's writes to the sibling status.attributes.outOfBand subtree.

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

ReadWorkflow returns the Workflow as currently stored by the API server, not as cached, so the result is never stale. A Workflow outside b.Namespaces is reported as not found.

func (*Backend) RenderedHardware added in v0.26.0

func (b *Backend) RenderedHardware(_ context.Context, hw *tinkerbell.Hardware) (*tinkerbell.Hardware, error)

RenderedHardware returns the rendering of hw to serve. Without rendering, it returns hw. A Hardware with no rendering to serve is not found.

func (*Backend) RenderedReader added in v0.26.0

func (b *Backend) RenderedReader() *RenderedReader

RenderedReader returns a reader of rendered Hardware.

func (*Backend) ResolveReferences added in v0.26.0

func (b *Backend) ResolveReferences(ctx context.Context, hw *tinkerbell.Hardware) (map[string]any, error)

ResolveReferences returns the objects hw's spec.references point to, keyed by reference name. When b.Namespaces is set, a reference outside them is reported in the error without being read. Otherwise a reference is read only if the allow list matches it or the deny list does not; with no deny list configured, an implicit deny-all rule is used and can still be overridden by an allow-list match. Denied and unreadable references are omitted from the map and reported in the error; other references are still returned.

func (*Backend) Start

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

Start starts the client-side cache and, with rendering, background rendering.

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.

func (*Backend) Watches added in v0.26.0

func (b *Backend) Watches(namespace string) bool

Watches reports whether namespace is one the backend watches.

type Index

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

type IndexType

type IndexType string

type RenderedReader added in v0.26.0

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

RenderedReader serves rendered Hardware. It only reads, so rendered Hardware cannot be written back over its templates.

func (*RenderedReader) FilterHardware added in v0.26.0

func (r *RenderedReader) FilterHardware(ctx context.Context, opts data.HardwareFilter) (*tinkerbell.Hardware, error)

FilterHardware is Backend.FilterHardware, returning the rendered Hardware.

Jump to

Keyboard shortcuts

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