runtime

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: GPL-3.0 Imports: 16 Imported by: 1

Documentation

Overview

Package runtime provides functions to manage the runtime environment of the application. It will provide abstractions around the Kubernetes runtime environment, creating an executing containers, and managing the lifecycle of the application.

Index

Constants

View Source
const (
	// LabelResource is the label used to identify the resource type.
	LabelResource = "resource"
	// LabelID is the label used to identify the resource ID.
	LabelID = "id"
	// LabelExecution is the label used to identify the execution type.
	// either a pipeline or a search
	LabelExecution = "execution"

	AnnotationVersion = "ocularproject.io/version"
)

Variables

This section is empty.

Functions

func BuildJob

func BuildJob(
	resourceName string,
	id schemas.ExecutionID,
	initContainers, containers []v1.Container,
	opts ...JobOpt,
) batchV1.Job

BuildJob creates a new Job object with the given parameters. It takes a resource name, an ID, and a list of containers. It also accepts a variadic number of JobOpt options to modify the Job object.

func BuildServiceForJob

func BuildServiceForJob(
	job *batchV1.Job,
	namespace string,
	port int32,
	opts ...ServiceOpt,
) v1.Service

BuildServiceForJob creates a Service object for a Job. It sets the name, namespace, and owner reference of the Service to match the Job. It also sets the selector to match the Job's labels.

func CreateAnnotations added in v0.1.1

func CreateAnnotations(additional map[string]string) map[string]string

func CreateContainer

func CreateContainer(
	name string,
	container schemas.UserContainer,
	secretVolumeName string,
	opts ...ContainerOpt,
) v1.Container

CreateContainer creates a new container with the given name and configuration. It will create the container based on the provided [types.UserContainer] and apply the ContainerOpt options to it. For any secrets that are mounted as files, it will create a volume mount for the secret and configure it to come from the volume with the name [secretVolumeName].

func CreateLabels

func CreateLabels(additional map[string]string) map[string]string

CreateLabels creates a map of labels for the container. It merges the labels defined in the configuration file with the additional labels provided as input.

func EnvForParameters

func EnvForParameters(
	params map[string]string,
	definitions map[string]schemas.ParameterDefinition,
) []v1.EnvVar

EnvForParameters converts a map of parameters to a list of environment variables that can be passed to a container. It will check that the parameters are defined in the parameter definitions and that the required parameters are set.

func GetJob

func GetJob(
	ctx context.Context,
	jobInterface typedBatchV1.JobInterface,
	id schemas.ExecutionID,
	resourceType string,
) (*batchV1.Job, error)

func IDFromJob

func IDFromJob(job *batchV1.Job) (schemas.ExecutionID, error)

func ListJobs

func ListJobs(
	ctx context.Context,
	jobInterface typedBatchV1.JobInterface,
	resourceType string,
	opts ...ListOption,
) ([]batchV1.Job, error)

func RunStatusFromJobStatus

func RunStatusFromJobStatus(s batchV1.JobStatus) schemas.RunStatus

RunStatusFromJobStatus converts a Kubernetes JobStatus to a [schema.RunStatus]. It will return a schemas.RunStatus based on the JobStatus. schemas.RunStatusUnknown is returned if the status cannot be determined. schemas.RunStatusError is returned if the job has failed, and the reason is not "Deleted". schemas.RunStatusCancelled is returned if the job has failed and the reason is "Deleted". schemas.RunStatusNotRan is never returned, as it is not applicable to JobStatus.

func StopJob

func StopJob(
	ctx context.Context,
	jobInterface typedBatchV1.JobInterface,
	id schemas.ExecutionID,
	resourceType string,
) error

StopJob stops a job with the given ID. It uses the provided typedBatchV1.JobInterface to delete the job. It returns an error if the job cannot be deleted or if it is not found.

Types

type ContainerOpt

type ContainerOpt = func(v1.Container) v1.Container

func ContainerArgsOpt

func ContainerArgsOpt(args ...string) ContainerOpt

func ContainerEnvOpt

func ContainerEnvOpt(envVars ...v1.EnvVar) ContainerOpt

func ContainerPortOpt

func ContainerPortOpt(ports ...v1.ContainerPort) ContainerOpt

func ContainerRestartPolicyOpt

func ContainerRestartPolicyOpt(restartPolicy v1.ContainerRestartPolicy) ContainerOpt

func ContainerVolumesOpt

func ContainerVolumesOpt(volumes ...v1.VolumeMount) ContainerOpt

func ContainerWorkingDirOpt

func ContainerWorkingDirOpt(workingDir string) ContainerOpt

type JobOpt

type JobOpt = func(job batchV1.Job) batchV1.Job

JobOpt is a function that modifies a Job object.

func JobOptWithAnnotations

func JobOptWithAnnotations(annotations map[string]string) JobOpt

JobOptWithAnnotations adds annotations to the Job object.

func JobOptWithLabels

func JobOptWithLabels(labels map[string]string) JobOpt

JobOptWithLabels adds labels to the Job object.

func JobOptWithServiceAccountName

func JobOptWithServiceAccountName(name string) JobOpt

JobOptWithServiceAccountName sets the service account name for the Job object. This is useful for setting the service account that the job should run as.

func JobOptWithTimeout

func JobOptWithTimeout(duration time.Duration) JobOpt

JobOptWithTimeout sets the timeout for the Job object.

func JobOptWithVolumes

func JobOptWithVolumes(volumes []v1.Volume) JobOpt

JobOptWithVolumes adds volumes to the Job object.

type ListOption

type ListOption = func(meta metav1.ListOptions) metav1.ListOptions

type ServiceOpt

type ServiceOpt = func(v1.Service) v1.Service

ServiceOpt is a function that modifies a Service object.

func ServiceOptPublishNotReadyAddresses

func ServiceOptPublishNotReadyAddresses(publishNotReadyAddresses bool) ServiceOpt

ServiceOptPublishNotReadyAddresses sets the 'PublishNotReadyAddresses' field of the Service object.

Jump to

Keyboard shortcuts

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