workloads

package
v0.0.8-internal Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KaiwoconfigFilename               = "kaiwoconfig"
	EnvFilename                       = "env"
	KaiwoUsernameLabel                = "kaiwo-cli/username"
	KaiwoDefaultStorageClassNameLabel = "kaiwo-cli/default-storage-class-name"
	KaiwoDefaultStorageQuantityLabel  = "kaiwo-cli/default-storage-quantity"
	CustomTemplateValuesFilename      = "custom-template-values.yaml"
)
View Source
const TemplateFileName = "template"

Variables

This section is empty.

Functions

func ApplyWorkload

func ApplyWorkload(
	ctx context.Context,
	k8sClient client.Client,
	workload Workload,
	execFlags ExecFlags,
	templateContext WorkloadTemplateConfig,
) error

ApplyWorkload runs the main workload submission routine

func Cleanup

func Cleanup(ctx context.Context, resource string, name string, namespace string, removeConfigMap bool) error

Cleanup removes a specified Kubernetes resource and optionally its associated ConfigMap.

func CreateLocalClusterQueueManifest

func CreateLocalClusterQueueManifest(ctx context.Context, k8sClient client.Client, templateContext WorkloadTemplateConfig) (*kueuev1beta1.LocalQueue, error)

Types

type DeploymentFlags

type DeploymentFlags struct {
	// The model to use
	Model string
}

DeploymentFlags contain flags specific to deployment-workloads

type ExecFlags

type ExecFlags struct {
	// Run without modifying resources
	DryRun bool

	// Create namespace if it doesn't already exist
	CreateNamespace bool

	// Custom template, if any
	Template string

	// Path to workload folder
	Path string

	// OverlayPath contains specific files that override files in Path
	OverlayPath string

	// The key used to store the GPU count per node in the resource flavor
	ResourceFlavorGpuNodeLabelKey string

	// WorkloadFiles list the files that are considered to be part of the workload after merging Path and OverlayPath
	// The map is from the workload path (how the workload would see it) to the true relative path (how the CLI client sees it)
	WorkloadFiles map[string]string
}

ExecFlags contain flags that are shared by all workloads during the resource-creation process, but are not passed into the template context

type JobFlags

type JobFlags struct {
	// The Kueue queue to use
	Queue string
}

JobFlags contain flags specific to job-workloads

type MetaFlags

type MetaFlags struct {
	// The name of the resource
	Name string

	// The namespace of the resource
	Namespace string

	// The base image to use
	Image string

	ImagePullSecret string

	Version string

	User string

	// Environment variables
	EnvVars []corev1.EnvVar

	// Secret volumes
	SecretVolumes []k8s.SecretVolume

	// Whether there is associated config map data
	HasConfigMap bool
}

MetaFlags contain flags that are shared by all workloads

type SchedulingFlags

type SchedulingFlags struct {
	// GPUsAvailablePerNode refers to the Kueue resource flavor's GPU count
	GPUsAvailablePerNode int

	RequestedGPUsPerReplica int

	// TotalRequestedGPUs refers to the total number of GPUs requested for the workload
	TotalRequestedGPUs int

	RequestedReplicas int

	// CalculatedGPUsPerReplica refers to the number of GPUs per replica, calculated from the available GPUs per node
	CalculatedGPUsPerReplica int

	// CalculatedNumReplicas refers to the number of replicas, calculated from the available GPUs per node
	CalculatedNumReplicas int

	Storage *StorageSchedulingFlags
}

SchedulingFlags for scheduling options

type StorageSchedulingFlags

type StorageSchedulingFlags struct {
	Quantity         string
	StorageClassName string
}

type Workload

type Workload interface {
	// GenerateTemplateContext creates the workload-specific context that can be passed to the template
	GenerateTemplateContext(ExecFlags) (any, error)

	// DefaultTemplate returns a default template to use for this workload
	DefaultTemplate() ([]byte, error)

	SetFromTemplate([]byte, WorkloadTemplateConfig) error

	// IgnoreFiles lists the files that should be ignored in the ConfigMap
	IgnoreFiles() []string

	// GenerateAdditionalResourceManifests returns additional manifests that are required for creating the workload
	GenerateAdditionalResourceManifests(context.Context, client.Client, WorkloadTemplateConfig) ([]client.Object, error)

	// Reload loads the current state from Kubernetes again
	Reload(context.Context, client.Client) error

	// LoadFromObjectKey loads the state from Kubernetes given an object key (name and namespace)
	LoadFromObjectKey(context.Context, client.Client, client.ObjectKey) error

	// ResolveStructure loads the current expanded structure from k8s to make it easier to interact with the workload
	ResolveStructure(ctx context.Context, k8sClient client.Client) error

	// ListKnownPods returns the pods that the reference is currently aware of
	ListKnownPods() []WorkloadPod

	// GetStatus returns a human-readable status of the workload
	GetStatus() string

	GetName() string

	GetObject() client.Object

	GetNamespace() string

	GetKaiwoUser() string

	GetServices(ctx context.Context, k8sClient client.Client) ([]corev1.Service, error)
}

Workload represents the generic workload object

type WorkloadBase

type WorkloadBase struct{}

WorkloadBase is the base object that all workloads share

func (WorkloadBase) GenerateAdditionalResourceManifests

func (wb WorkloadBase) GenerateAdditionalResourceManifests(_ context.Context, _ client.Client, _ WorkloadTemplateConfig) ([]client.Object, error)

func (WorkloadBase) GetKaiwoUser

func (wb WorkloadBase) GetKaiwoUser() string

func (WorkloadBase) GetName

func (wb WorkloadBase) GetName() string

func (WorkloadBase) GetNamespace

func (wb WorkloadBase) GetNamespace() string

func (WorkloadBase) GetObject

func (wb WorkloadBase) GetObject() client.Object

func (WorkloadBase) GetServices

func (wb WorkloadBase) GetServices(_ context.Context, _ client.Client) ([]corev1.Service, error)

func (WorkloadBase) LoadFromObjectKey

func (wb WorkloadBase) LoadFromObjectKey(ctx context.Context, k8sClient client.Client, key client.ObjectKey) error

LoadFromObjectKey loads the workload from Kubernetes based on the object key (name and namespace)

func (WorkloadBase) Reload

func (wb WorkloadBase) Reload(ctx context.Context, k8sClient client.Client) error

func (WorkloadBase) SetFromObject

func (wb WorkloadBase) SetFromObject(_ client.Object) error

func (WorkloadBase) SetFromTemplate

func (wb WorkloadBase) SetFromTemplate(workloadTemplate []byte, templateContext WorkloadTemplateConfig) error

type WorkloadPod

type WorkloadPod struct {
	Pod          corev1.Pod
	LogicalGroup string
}

type WorkloadTemplateConfig

type WorkloadTemplateConfig struct {
	// Workload-specific config
	Workload any

	// Workload type specific config
	WorkloadMeta any

	// Custom configuration from the user
	Custom any

	// Scheduling configuration for Kubernetes
	Scheduling SchedulingFlags

	// Meta configuration for Kubernetes
	Meta MetaFlags
}

WorkloadTemplateConfig is the config context that is passed to the workload templates

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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