utils

package
v0.1.0-latest-stable Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NSIObjectsNamespace is the DPF-owned namespace where all NodeServiceInterfaces objects live.
	NSIObjectsNamespace = "dpf-operator-system"

	// NSINodeFieldKey is the cache field-index key for NodeServiceInterfaces.spec.node.
	NSINodeFieldKey = "spec.node"

	// NSITypeFieldKey is the cache field-index key for NodeServiceInterfaces.spec.type.
	NSITypeFieldKey = "spec.type"
)
View Source
const ServiceInterfaceNodeFieldKey = "spec.node"

ServiceInterfaceNodeFieldKey is the ServiceInterface spec.node field index key registered by ServiceInterfaceSetReconciler.

Variables

View Source
var ErrDPFOperatorConfigNotFound = errors.New("no DPFOperatorConfig exists")

ErrDPFOperatorConfigNotFound is returned by GetDPFOperatorConfig when no DPFOperatorConfig exists. Callers can tell it apart from a failed read, which must not be treated as absence.

Functions

func DownloadFile

func DownloadFile(ctx context.Context, url string, dst string, fileMode os.FileMode) error

DownloadFile downloads a file from a URL to a destination file.

func DownloadFileWithClient

func DownloadFileWithClient(ctx context.Context, httpClient *http.Client, url string, dst string, fileMode os.FileMode) error

DownloadFileWithClient behaves like DownloadFile but performs the request with the provided HTTP client. This lets callers supply a custom TLS configuration (e.g. RootCAs built from the DPF CA trust bundle) when downloading from an HTTPS endpoint such as the bfb-registry.

func EnsureNamespace

func EnsureNamespace(ctx context.Context, c client.Client, namespace string) error

EnsureNamespace ensures the namespace exists in the cluster by creating it if it does not exist.

func GetAllocatableResources

func GetAllocatableResources(total corev1.ResourceList, reserved corev1.ResourceList) (corev1.ResourceList, error)

GetAllocatableResources returns the available resources after subtracting the reserved ones from the total ones

func GetDPFOperatorConfig

func GetDPFOperatorConfig(ctx context.Context, c client.Client) (*operatorv1.DPFOperatorConfig, error)

GetDPFOperatorConfig returns the DPFOperatorConfig object. It returns an error if there is more than one DPFOperatorConfig object or if there is no DPFOperatorConfig object.

func GetMatchingDPUClusters

func GetMatchingDPUClusters(dpuClusters []*dpucluster.Config, clusterSelector *metav1.LabelSelector) ([]*dpucluster.Config, error)

GetMatchingDPUClusters returns a list of DPUCluster Configs from the given list that match the given selector. In case no selector is provided, it returns the entire list.

func GetOOBBridgeName

func GetOOBBridgeName(ctx context.Context, c client.Client) (string, error)

GetOOBBridgeName returns the out-of-band bridge name from the cluster DPFOperatorConfig.

func GetRandomKVPair

func GetRandomKVPair[T any](m map[string]T) (string, T)

func HTTPClientWithCABundle

func HTTPClientWithCABundle(caBundlePath string) (*http.Client, error)

HTTPClientWithCABundle returns an HTTP client whose TLS config trusts the host's system roots plus any PEM certificates found in caBundlePath. Callers that need CA rotation to take effect without a restart should call this before each request so the bundle is re-read from disk (e.g. a non-subPath ConfigMap volume that kubelet keeps in sync).

When caBundlePath is empty or the file does not exist, the returned client falls back to the system trust store only. A present-but-unparseable bundle is treated as a configuration error.

func HasMatchingNonTerminatingNSIEntry

func HasMatchingNonTerminatingNSIEntry(ctx context.Context, c client.Client, si *dpuservicev1.ServiceInterface) (bool, error)

HasMatchingNonTerminatingNSIEntry reports whether the given ServiceInterface has a matching non-terminating entry on the node's SFC-typed NodeServiceInterfaces shard. Match criteria: both set-ownership labels from the SI (name + namespace) must be present and non-empty, match the entry labels, and the entry namespace must equal si.Namespace. Returns (false, nil) when the SI has no node or either ownership label is missing or empty.

func LabelSelectorAsSelector

func LabelSelectorAsSelector(labelSelector *metav1.LabelSelector) (labels.Selector, error)

LabelSelectorAsSelector is a wrapper around metav1.LabelSelectorAsSelector() to not select labels.Nothing() when the input is nil. If the input is nil, it returns labels.Everything().

func ListInterfacesForNode

func ListInterfacesForNode(
	ctx context.Context,
	c client.Client,
	nodeName, namespace string,
	nsiTypes ...string,
) ([]*dpuservicev1.ServiceInterface, error)

ListInterfacesForNode returns every legacy and non-terminating NSI (restricted to nsiTypes) interface for nodeName as ServiceInterface objects. Interfaces are deduplicated by name, with NSI entries taking priority over a legacy ServiceInterface sharing the same name, mirroring the resolver's precedence.

func NSINodeIndexFunc

func NSINodeIndexFunc(o client.Object) []string

NSINodeIndexFunc extracts the node name from a NodeServiceInterfaces object for field indexing.

func NSITypeIndexFunc

func NSITypeIndexFunc(o client.Object) []string

NSITypeIndexFunc extracts the type from a NodeServiceInterfaces object for field indexing.

func ResolveServiceInterfaceByLabels

func ResolveServiceInterfaceByLabels(
	ctx context.Context,
	c client.Client,
	nodeName, namespace string,
	matchLabels map[string]string,
	nsiTypes ...string,
) (*dpuservicev1.ServiceInterface, error)

ResolveServiceInterfaceByLabels resolves a single ServiceInterface for the given node and namespace matching matchLabels. It tries the NSI path first and falls back to the legacy ServiceInterface path if no match is found. Returns an error if more than one entry matches on either path.

nsiTypes restricts which NSI shards are searched. Pass one or more type strings (e.g. "sfc") to limit the search, or pass nothing to search across all shards. The SFC controller should pass "sfc" since it only manages OVS ports for that shard; the pod-ipam-injector passes nothing because service interfaces can live in any shard.

The caller's manager cache must have the NSI spec.node field index registered via SetupNSINodeIndexer.

func ServiceInterfaceNodeIndexFunc

func ServiceInterfaceNodeIndexFunc(o client.Object) []string

func SetupNSINodeIndexer

func SetupNSINodeIndexer(ctx context.Context, mgr ctrl.Manager) error

SetupNSINodeIndexer registers the spec.node and spec.type field indexes for NodeServiceInterfaces.

func SetupServiceInterfaceNodeIndexer

func SetupServiceInterfaceNodeIndexer(ctx context.Context, mgr ctrl.Manager) error

Types

type ResourcesExceedError

type ResourcesExceedError struct {
	// AdditionalResourcesRequired are the extra resources needed so that the they can fit the total resources
	AdditionalResourcesRequired []string
	// contains filtered or unexported fields
}

ResourcesExceedError is an error returned by GetAllocatableResources() that indicates that the reserved resources exceed the total resources

func (*ResourcesExceedError) Error

func (e *ResourcesExceedError) Error() string

Error is the error message of that error struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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