common

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Finalizer            = "kaiwo.silogen.ai/finalizer"
	KaiwoQueueConfigName = "kaiwo"
)
View Source
const (
	KaiwoLabelBase    = "kaiwo.silogen.ai"
	KaiwoUserLabel    = KaiwoLabelBase + "/user"
	KaiwoNameLabel    = KaiwoLabelBase + "/name"
	KaiwoTypeLabel    = KaiwoLabelBase + "/type"
	KaiwoRunIdLabel   = KaiwoLabelBase + "/run-id"
	KaiwoManagedLabel = KaiwoLabelBase + "/managed"
	QueueLabel        = "kueue.x-k8s.io/queue-name"
)
View Source
const (
	DataStoragePostfix = "data"
	HfStoragePostfix   = "hf"
)

Variables

View Source
var DefaultClusterQueueName = baseutils.GetEnv("DEFAULT_CLUSTER_QUEUE_NAME", "kaiwo")
View Source
var DefaultRequeueDuration = 2 * time.Second

Functions

func CopyLabels

func CopyLabels(kaiwoLabels map[string]string, objectMeta *v1.ObjectMeta)

CopyLabels copies labels from kaiwoLabels to objectMeta.Labels, skipping keys that already exist

func SetKaiwoSystemLabels

func SetKaiwoSystemLabels(kaiwoLabelContext KaiwoLabelContext, objectMeta *v1.ObjectMeta)

SetKaiwoSystemLabels sets the Kaiwo system labels on an ObjectMeta instance

Types

type KaiwoLabelContext

type KaiwoLabelContext struct {
	User    string
	Name    string
	Type    string
	RunId   string
	Managed string
}

func GetKaiwoLabelContext

func GetKaiwoLabelContext(k KaiwoWorkload) KaiwoLabelContext

type KaiwoWorkload

type KaiwoWorkload interface {
	client.Object
	GetUser() string
	GetObjectMeta() *metav1.ObjectMeta
	GetStatusString() string
	GetType() string
	GetServices(ctx context.Context, k8sClient client.Client) ([]corev1.Service, error)
	GetDuration() *metav1.Duration
	GetStartTime() *metav1.Time
	GetClusterQueue() string
	GetGPUVendor() string
	GetCommonStatusSpec() *v1alpha1.CommonStatusSpec
}

type LocalQueueReconciler

type LocalQueueReconciler struct {
	ResourceReconcilerBase[*kueuev1beta1.LocalQueue]
}

func NewLocalQueueReconciler

func NewLocalQueueReconciler(objectKey client.ObjectKey) *LocalQueueReconciler

func (*LocalQueueReconciler) Build

func (*LocalQueueReconciler) GetEmptyObject

func (r *LocalQueueReconciler) GetEmptyObject() *kueuev1beta1.LocalQueue

type Reconciler

type Reconciler[T client.Object] interface {
	// Reconcile runs through the reconciliation loop
	Reconcile(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme) (ctrl.Result, error)
}

Reconciler manages the reconciliation of a Kaiwo resource (job or service)

type ReconcilerBase

type ReconcilerBase[T client.Object] struct {
	ObjectKey client.ObjectKey
	Object    T
	Self      Reconciler[T]
}

type ResourceReconciler

type ResourceReconciler[T client.Object] interface {
	// Build will build the client object without creating it
	Build(ctx context.Context, k8sClient client.Client) (desired T, err error)

	// Get will fetch the client object
	Get(ctx context.Context, k8sClient client.Client) (actual T, err error)

	// Create will create the client object
	Create(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme, desired T, owner client.Object, recorder record.EventRecorder) error

	// Update will update the client object
	Update(ctx context.Context, k8sClient client.Client, desired *T, actual T, recorder record.EventRecorder) error

	// Reconcile will build and then create
	Reconcile(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme, owner client.Object, recorder record.EventRecorder) (actual T, result *ctrl.Result, err error)

	// ShouldContinue returns a reconciliation result if there is an intermediate result to return
	ShouldContinue(ctx context.Context, actual T) *ctrl.Result

	GetEmptyObject() T

	// ValidateBeforeCreateOrUpdate provides a way to abort the reconciliation based on the currently existing object's state
	ValidateBeforeCreateOrUpdate(ctx context.Context, actual T) (*ctrl.Result, error)
}

ResourceReconciler ensures that a single dependent resource is reconciled to a desired state

type ResourceReconcilerBase

type ResourceReconcilerBase[T client.Object] struct {
	ObjectKey client.ObjectKey
	Self      ResourceReconciler[T]
	Desired   T
}

func (*ResourceReconcilerBase[T]) Create

func (d *ResourceReconcilerBase[T]) Create(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme, desired T, owner client.Object, recorder record.EventRecorder) error

func (*ResourceReconcilerBase[T]) Get

func (d *ResourceReconcilerBase[T]) Get(ctx context.Context, k8sClient client.Client) (actual T, err error)

func (*ResourceReconcilerBase[T]) Reconcile

func (d *ResourceReconcilerBase[T]) Reconcile(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme, owner client.Object, recorder record.EventRecorder) (actual T, result *ctrl.Result, err error)

Reconcile ensures that the resource exists and is in the desired state. The object is first built based on the reconciler object (kaiwo job or service), and the remote object is fetched. If it exists, it is updated, otherwise it is created.

func (*ResourceReconcilerBase[T]) ShouldContinue

func (d *ResourceReconcilerBase[T]) ShouldContinue(ctx context.Context, actual T) *ctrl.Result

func (*ResourceReconcilerBase[T]) Update

func (d *ResourceReconcilerBase[T]) Update(_ context.Context, _ client.Client, desired *T, actual T, recorder record.EventRecorder) error

Update updates the object. By default, nothing is done, and desired is set to actual

func (*ResourceReconcilerBase[T]) ValidateBeforeCreateOrUpdate

func (d *ResourceReconcilerBase[T]) ValidateBeforeCreateOrUpdate(ctx context.Context, actual T) (*ctrl.Result, error)

type StorageReconciler

type StorageReconciler struct {
	ResourceReconcilerBase[*corev1.PersistentVolumeClaim]
	Amount           string
	StorageClassName string
	AccessMode       corev1.PersistentVolumeAccessMode
}

func NewStorageReconciler

func NewStorageReconciler(
	storageConfig configapi.KaiwoStorageConfig,
	objectKey client.ObjectKey,
	accessMode corev1.PersistentVolumeAccessMode,
	storageClassName string,
	amount string,
) *StorageReconciler

func (*StorageReconciler) Build

func (*StorageReconciler) GetEmptyObject

func (r *StorageReconciler) GetEmptyObject() *corev1.PersistentVolumeClaim

Jump to

Keyboard shortcuts

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