dpucluster

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: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HealthStatusHealthy is the status of the dpu cluster when it is healthy
	HealthStatusHealthy = "Healthy"
	// HealthStatusUnhealthy is the status of the dpu cluster when it is unhealthy
	HealthStatusUnhealthy = "Unhealthy"
	// HealthStatusUnknown is the status of the dpu cluster when it is unknown
	HealthStatusUnknown = "Unknown"
)
View Source
const (
	// DefaultMaxRetries is the default maximum number of retries
	DefaultMaxRetries = 5
	// DefaultMaxBackoff is the default maximum backoff duration
	DefaultMaxBackoff = 10 * time.Minute
)

Variables

View Source
var ErrDPUClusterNoConnectionAvailable = fmt.Errorf("no connection available")

ErrDPUClusterNoConnectionAvailable is returned when no connection is available for a DPU cluster.

View Source
var ErrDPUClusterNotConnected = fmt.Errorf("dpu cluster is not connected")

ErrDPUClusterNotConnected is returned when a DPU cluster is not connected.

Functions

This section is empty.

Types

type Backoff

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

Backoff is a struct that implements a backoff algorithm.

func NewBackoff

func NewBackoff(d time.Duration, factor, jitter float64) *Backoff

NewBackoff creates a new Backoff instance. It takes a duration, a factor and a jitter as parameters.

func (*Backoff) GetNextBackOff

func (b *Backoff) GetNextBackOff(attempt int) time.Duration

GetNextBackOff returns the backoff duration for the given attempt. The backoff is calculated as:

temp = backoff * factor ^ attempt
interval = temp * (1 - jitter) + rand.Int64N(2 * jitter * temp)

e.g backoff = 1s, factor = 2, jitter = 0.1 interval will be >= 0.9s and < 1.1s which means 10% jitter

type ClientOption

type ClientOption interface {
	Apply(options *ClientOptions)
}

type ClientOptionConfigHost

type ClientOptionConfigHost struct {
	Host string
}

ClientOptionConfigHost overrides the host used for the REST config.

func (ClientOptionConfigHost) Apply

func (o ClientOptionConfigHost) Apply(options *ClientOptions)

type ClientOptionScheme

type ClientOptionScheme struct {
	Scheme *runtime.Scheme
}

ClientOptionScheme is the scheme used for the client.

func (ClientOptionScheme) Apply

func (o ClientOptionScheme) Apply(options *ClientOptions)

type ClientOptionSkipVerifyTLS

type ClientOptionSkipVerifyTLS struct {
	SkipVerifyTLS bool
}

ClientOptionSkipVerifyTLS is the option to skip TLS verification for the REST config.

func (ClientOptionSkipVerifyTLS) Apply

func (o ClientOptionSkipVerifyTLS) Apply(options *ClientOptions)

type ClientOptionTimeout

type ClientOptionTimeout struct {
	Timeout time.Duration
}

ClientOptionTimeout is the timeout used for the REST config, client and cache.

func (ClientOptionTimeout) Apply

func (o ClientOptionTimeout) Apply(options *ClientOptions)

type ClientOptionUserAgent

type ClientOptionUserAgent struct {
	UserAgent string
}

ClientOptionUserAgent is the user agent used for the REST config, client and cache.

func (ClientOptionUserAgent) Apply

func (o ClientOptionUserAgent) Apply(options *ClientOptions)

type ClientOptions

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

ClientOptions holds the options for the client.

type ClusterClientProvider

type ClusterClientProvider interface {
	// GetClient returns a client for the specified DPUCluster
	GetClient(clusterKey client.ObjectKey) (client.Client, error)
	// ListClients returns a list of clients for all DPUClusters known
	// to the provider.
	ListClients() ([]client.Client, error)
}

ClusterClientProvider is the interface that is used by the DPUClusterHelper to get clients for DPUClusters.

func NewStaticClusterClientProvider

func NewStaticClusterClientProvider(clients map[client.ObjectKey]client.Client) ClusterClientProvider

NewStaticClusterClientProvider creates a new ClusterClientProvider that returns statically configured clients

type Config

type Config struct {
	// Cluster is the DPU cluster for which the config is being fetched.
	Cluster *provisioningv1.DPUCluster
	// contains filtered or unexported fields
}

Config hold the cluster configuration. It provides methods to get the client, clientset, and rest config for the cluster.

func GetConfigs

func GetConfigs(ctx context.Context, c client.Client) ([]*Config, error)

GetConfigs returns a list of Configs for all DPU clusters.

func NewConfig

func NewConfig(c client.Reader, cluster *provisioningv1.DPUCluster) *Config

NewConfig returns a new Config.

func (*Config) CACertHashes

func (cc *Config) CACertHashes(ctx context.Context) ([]string, error)

CACertHashes returns the hashes of the CAs contained in the cluster config. These hashes are used to authenticate with kubelet when joining nodes to the cluster. The reference implementation for this function is from kubeadm: https://github.com/kubernetes/kubernetes/blob/78cb3862f11225135afdf76f3424e2d7b33104c7/cmd/kubeadm/app/cmd/util/join.go#L52

func (*Config) Client

func (cc *Config) Client(ctx context.Context, opts ...ClientOption) (client.Client, error)

Client returns a new client for the cluster.

func (*Config) Clientset

func (cc *Config) Clientset(ctx context.Context, opts ...ClientOption) (*kubernetes.Clientset, []byte, error)

Clientset returns a new clientset for the cluster.

func (*Config) ClusterNamespaceName

func (cc *Config) ClusterNamespaceName() string

func (*Config) Kubeconfig

func (cc *Config) Kubeconfig(ctx context.Context) (*clientcmdv1.Config, error)

Kubeconfig returns the kubeconfig for the cluster.

func (*Config) Server

func (cc *Config) Server(ctx context.Context) (string, error)

Server returns the server cluster.

type GetIndexerCallback

type GetIndexerCallback func(ctx context.Context, cache cache.Cache) error

GetIndexerCallback is called when a cache for a dpu cluster is created. The function should add field indexes to the cache before it is started.

type GetWatcherCallback

type GetWatcherCallback func(ctx context.Context, c client.Client, cluster client.ObjectKey) (Watcher, error)

GetWatcherCallback the function is called when a client for a dpu cluster is created. The function should return a Watcher that will be used to watch for events for the given cluster.

type Health

type Health struct {
	Backoff
	// contains filtered or unexported fields
}

Health is the struct that implements the health check for the dpu cluster.

func NewHealthServer

func NewHealthServer(client discovery.ServerVersionInterface, maxBackoff time.Duration, maxRetries int, interval time.Duration) *Health

NewHealthServer creates a new Health instance.

func (*Health) Check

func (h *Health) Check() (string, error)

Check checks the health of the dpu cluster. It returns the status of the dpu cluster and an error if the check fails after all retries. If the check is successful, it returns the status as "Healthy" and nil error.

func (*Health) GetNextCheckTime

func (h *Health) GetNextCheckTime() time.Duration

GetNextCheckTime returns the next check time for the health check. It uses the backoff algorithm to calculate the next check time.

type Option

type Option interface {
	Apply(options *Options)
}

type OptionByObject

type OptionByObject struct {
	ByObject map[client.Object]cache.ByObject
}

OptionByObject restricts the cache's ListWatch to the desired fields per GVK at the specified object.

func (OptionByObject) Apply

func (o OptionByObject) Apply(options *Options)

type OptionDefaultFieldSelector

type OptionDefaultFieldSelector struct {
	DefaultFieldSelector fields.Selector
}

OptionDefaultFieldSelector will be used as a field selector for all object types.

func (OptionDefaultFieldSelector) Apply

func (o OptionDefaultFieldSelector) Apply(options *Options)

type OptionDefaultLabelSelector

type OptionDefaultLabelSelector struct {
	DefaultLabelSelector labels.Selector
}

OptionDefaultLabelSelector will be used as a label selector for all objects.

func (OptionDefaultLabelSelector) Apply

func (o OptionDefaultLabelSelector) Apply(options *Options)

type OptionDefaultNamespaces

type OptionDefaultNamespaces struct {
	DefaultNamespaces map[string]cache.Config
}

OptionDefaultNamespaces maps namespace names to cache configs.

func (OptionDefaultNamespaces) Apply

func (o OptionDefaultNamespaces) Apply(options *Options)

type OptionDisableFor

type OptionDisableFor struct {
	DisableFor []client.Object
}

OptionDisableFor is a list of objects for which the cache should be disabled.

func (OptionDisableFor) Apply

func (o OptionDisableFor) Apply(options *Options)

type OptionGetIndexerCallbacks

type OptionGetIndexerCallbacks struct {
	GetIndexerCallbacks []GetIndexerCallback
}

OptionGetIndexerCallbacks is a list of functions that are called when a cache for a dpu cluster is created.

func (OptionGetIndexerCallbacks) Apply

func (o OptionGetIndexerCallbacks) Apply(options *Options)

type OptionGetWatcherCallbacks

type OptionGetWatcherCallbacks struct {
	GetWatcherCallbacks []GetWatcherCallback
}

OptionGetWatcherCallbacks is a list of functions that are called when a client for a dpu cluster is created.

func (OptionGetWatcherCallbacks) Apply

func (o OptionGetWatcherCallbacks) Apply(options *Options)

type OptionHostClient

type OptionHostClient struct {
	Client client.Reader
}

OptionHostClient is the client for the host cluster. It is used to fetch the kubeconfig secret.

func (OptionHostClient) Apply

func (o OptionHostClient) Apply(options *Options)

type OptionInitialSyncTimeout

type OptionInitialSyncTimeout struct {
	InitialSyncTimeout time.Duration
}

OptionInitialSyncTimeout is the timeout used when waiting for the cache to sync after cache start.

func (OptionInitialSyncTimeout) Apply

func (o OptionInitialSyncTimeout) Apply(options *Options)

type OptionRequeueAfter

type OptionRequeueAfter struct {
	RequeueAfter time.Duration
}

OptionRequeueAfter tells the remoteCacheReconciler to requeue after the given duration.

func (OptionRequeueAfter) Apply

func (o OptionRequeueAfter) Apply(options *Options)

type OptionScheme

type OptionScheme struct {
	Scheme *runtime.Scheme
}

OptionScheme is the scheme used for the client and the cache.

func (OptionScheme) Apply

func (o OptionScheme) Apply(options *Options)

type OptionSyncPeriod

type OptionSyncPeriod struct {
	SyncPeriod time.Duration
}

OptionSyncPeriod is the sync period of the cache.

func (OptionSyncPeriod) Apply

func (o OptionSyncPeriod) Apply(options *Options)

type OptionTimeout

type OptionTimeout struct {
	Timeout time.Duration
}

OptionTimeout is the timeout used for the REST config, client and cache.

func (OptionTimeout) Apply

func (o OptionTimeout) Apply(options *Options)

type OptionUserAgent

type OptionUserAgent struct {
	UserAgent string
}

OptionUserAgent is the user agent used for the REST config, client and cache.

func (OptionUserAgent) Apply

func (o OptionUserAgent) Apply(options *Options)

type Options

type Options struct {
	ClientOptions
	// contains filtered or unexported fields
}

type RemoteCache

type RemoteCache struct {

	// Lock to synchronize acess to accessors.
	sync.RWMutex
	// contains filtered or unexported fields
}

RemoteCache reconcile dpuClusters CRs and manges caches for those dpuClusters. It provides a way to watch dpuClusters and get cachedClients for dpuClusters. Specific objects can be watched in the dpu cluster.

func SetupRemoteCacheWithManager

func SetupRemoteCacheWithManager(ctx context.Context, mgr ctrl.Manager, opts ...Option) (*RemoteCache, error)

SetupRemoteCacheWithManager sets up a remoteCacheReconciler with the given Manager and Options. This will add a reconciler to the Manager and returns a remoteCacheReconciler which can be used to retrieve e.g. Clients for a given Cluster.

func (*RemoteCache) GetClient

func (rc *RemoteCache) GetClient(cluster client.ObjectKey) (client.Client, error)

GetClient returns a client for the given dpu cluster. It is a cached client that read from the given dpu cluster cache.

func (*RemoteCache) ListClients

func (rc *RemoteCache) ListClients() ([]client.Client, error)

ListClients returns a list of cached clients for all dpu clusters present in RemoteCache.

func (*RemoteCache) Reconcile

func (rc *RemoteCache) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error)

Reconcile reconciles Clusters and manages corresponding accessors.

func (*RemoteCache) Watch

func (rc *RemoteCache) Watch(ctx context.Context, cluster client.ObjectKey, watcher Watcher) error

Watch can be used to watch specific resources in the dpu cluster. e.g.:

err := RemoteCache.Watch(ctx, util.ObjectKey(cluster), clustercache.NewWatcher(clustercache.WatcherOptions{
	Name:         "watch-DPUNodes",
	Watcher:      r.controller,
	Kind:         &provisionningv1aplha1.DPUNode{},
	EventHandler: handler.EnqueueRequestsFromMapFunc(r.dpuNodeToVPC),
})

type SourceWatcher

type SourceWatcher[request comparable] interface {
	Watch(src source.TypedSource[request]) error
}

SourceWatcher is a scoped-down interface from Controller that only has the Watch func.

type TypedWatcherOptions

type TypedWatcherOptions[object client.Object, request comparable] struct {
	// Name represents a unique Watch request for the specified Cluster.
	Name string

	// Watcher is the watcher (controller) whose Reconcile() function will be called for events.
	Watcher SourceWatcher[request]

	// Kind is the type of resource to watch.
	Kind object

	// EventHandler contains the event handlers to invoke for resource events.
	EventHandler handler.TypedEventHandler[object, request]

	// Predicates is used to filter resource events.
	Predicates []predicate.TypedPredicate[object]
}

TypedWatcherOptions specifies the parameters used to establish a new watch for a dpu cluster. A source.TypedKind source (configured with Kind, TypedEventHandler and Predicates) will be added to the Watcher. To watch for events, the source.TypedKind will create an informer on the Cache that we have created and cached for the given Cluster.

type Watcher

type Watcher interface {
	Name() string
	Object() client.Object
	Watch(cache cache.Cache) error
}

Watcher is an interface that can start a Watch.

func NewWatcher

func NewWatcher[object client.Object, request comparable](options TypedWatcherOptions[object, request]) Watcher

NewWatcher creates a Watcher for the dpu cluster. A source.TypedKind source (configured with Kind, TypedEventHandler and Predicates) will be added to the SourceWatcher. To watch for events, the source.TypedKind will create an informer on the Cache that we have created and cached for the given Cluster.

type WatcherOptions

type WatcherOptions = TypedWatcherOptions[client.Object, ctrl.Request]

WatcherOptions specifies the parameters used to establish a new watch for a dpu cluster. A source.TypedKind source (configured with Kind, TypedEventHandler and Predicates) will be added to the Watcher. To watch for events, the source.TypedKind will create an informer on the Cache that we have created and cached for the given Cluster.

Jump to

Keyboard shortcuts

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