jobs

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 25 Imported by: 2

Documentation

Index

Constants

View Source
const (
	NodeCollectorName = "node-collector"

	// job headers
	TrivyCollectorName = "trivy.collector.name"
	TrivyAutoCreated   = "trivy.automatic.created"
	TrivyResourceName  = "trivy.resource.name"
	TrivyResourceKind  = "trivy.resource.kind"
)

Variables

View Source
var ErrTimeout = errors.New("runner received timeout")

ErrTimeout is returned when Runner's Run method fails due to a timeout event.

Functions

func ComputeHash

func ComputeHash(obj interface{}) string

ComputeHash returns a hash value calculated from a given object. The hash will be safe encoded to avoid bad words.

func GetActiveDeadlineSeconds

func GetActiveDeadlineSeconds(d time.Duration) *int64

func GetAuth added in v0.6.0

func GetJob

func GetJob(opts ...JobOption) (*batchv1.Job, error)

func GetTerminatedContainersStatusesByPod

func GetTerminatedContainersStatusesByPod(pod *corev1.Pod) map[string]*corev1.ContainerStateTerminated

GetTerminatedContainersStatusesByPod collect information about contianer status by pod

func IsPodControlledByJobNotFound

func IsPodControlledByJobNotFound(err error) bool

Types

type AuthBuilder added in v0.6.0

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

type AuthOption added in v0.6.0

type AuthOption func(*AuthBuilder)

func WithServiceAccountNamespace added in v0.6.0

func WithServiceAccountNamespace(namespace string) AuthOption

type Collector

type Collector interface {
	ApplyAndCollect(ctx context.Context, nodeName string) (string, error)
	Apply(ctx context.Context, nodeName string) (*batchv1.Job, error)
	AppendLabels(opts ...CollectorOption)
	Cleanup(ctx context.Context)
}

func NewCollector

func NewCollector(
	cluster k8s.Cluster,
	opts ...CollectorOption,
) Collector

type CollectorOption

type CollectorOption func(*jobCollector)

func WithCollectorTimeout added in v0.6.0

func WithCollectorTimeout(timeout time.Duration) CollectorOption

func WithContainerResourceRequirements added in v0.6.0

func WithContainerResourceRequirements(rr corev1.ResourceRequirements) CollectorOption

func WithContainerSecurityContext added in v0.5.0

func WithContainerSecurityContext(securityContext *corev1.SecurityContext) CollectorOption

func WithImageRef

func WithImageRef(imageRef string) CollectorOption

func WithJobAffinity added in v0.6.4

func WithJobAffinity(affinity *corev1.Affinity) CollectorOption

func WithJobAnnotation added in v0.5.5

func WithJobAnnotation(annotation map[string]string) CollectorOption

func WithJobLabels

func WithJobLabels(labels map[string]string) CollectorOption

func WithJobNamespace

func WithJobNamespace(namespace string) CollectorOption

func WithJobTemplateName

func WithJobTemplateName(name string) CollectorOption

func WithJobTolerations

func WithJobTolerations(tolerations []corev1.Toleration) CollectorOption

func WithName

func WithName(name string) CollectorOption

func WithNodeConfig added in v0.6.1

func WithNodeConfig(nodeConfig bool) CollectorOption

func WithPodImagePullSecrets added in v0.5.0

func WithPodImagePullSecrets(imagePullSecrets []corev1.LocalObjectReference) CollectorOption

func WithPodPriorityClassName added in v0.5.8

func WithPodPriorityClassName(priorityClassName string) CollectorOption

func WithPodSpecSecurityContext added in v0.5.0

func WithPodSpecSecurityContext(podSecurityContext *corev1.PodSecurityContext) CollectorOption

func WithServiceAccount

func WithServiceAccount(sa string) CollectorOption

func WithTimetout

func WithTimetout(timeout time.Duration) CollectorOption

func WithUseNodeSelector added in v0.6.2

func WithUseNodeSelector(useNodeSelector bool) CollectorOption

func WithVolumes added in v0.5.0

func WithVolumes(volumes []corev1.Volume) CollectorOption

func WithVolumesMount added in v0.5.0

func WithVolumesMount(volumesMount []corev1.VolumeMount) CollectorOption

type JobBuilder

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

type JobOption

type JobOption func(*JobBuilder)

func WithAffinity added in v0.6.4

func WithAffinity(affinity *corev1.Affinity) JobOption

func WithAnnotation

func WithAnnotation(annotations map[string]string) JobOption

func WithContainerVolumeMounts added in v0.5.0

func WithContainerVolumeMounts(volumeMounts []corev1.VolumeMount) JobOption

func WithImagePullSecrets added in v0.5.0

func WithImagePullSecrets(imagePullSecrets []corev1.LocalObjectReference) JobOption

func WithJobName

func WithJobName(name string) JobOption

func WithJobServiceAccount

func WithJobServiceAccount(sa string) JobOption

func WithJobTimeout added in v0.6.0

func WithJobTimeout(timeout time.Duration) JobOption

func WithLabels

func WithLabels(labels map[string]string) JobOption

func WithNamespace

func WithNamespace(namespace string) JobOption

func WithNodeCollectorImageRef

func WithNodeCollectorImageRef(imageRef string) JobOption

func WithNodeConfiguration added in v0.6.1

func WithNodeConfiguration(nodeConfig bool) JobOption

func WithNodeName added in v0.6.4

func WithNodeName(nodeName string) JobOption

func WithPodVolumes added in v0.5.0

func WithPodVolumes(volumes []corev1.Volume) JobOption

func WithPriorityClassName added in v0.5.8

func WithPriorityClassName(priorityClassName string) JobOption

func WithReplaceResourceReq added in v0.6.5

func WithReplaceResourceReq(replaceResourceReq bool) JobOption

func WithResourceRequirements added in v0.6.0

func WithResourceRequirements(rr corev1.ResourceRequirements) JobOption

func WithTemplate

func WithTemplate(template string) JobOption

func WithTolerations

func WithTolerations(tolerations []corev1.Toleration) JobOption

func WithUseNodeSelectorParam added in v0.6.4

func WithUseNodeSelectorParam(useNodeSelector bool) JobOption

type LogsReader

type LogsReader interface {
	GetLogsByJobAndContainerName(ctx context.Context, job *batchv1.Job, containerName string) (io.ReadCloser, error)
	GetTerminatedContainersStatusesByJob(ctx context.Context, job *batchv1.Job) (map[string]*corev1.ContainerStateTerminated, error)
}

LogsReader responsible for collecting container status and logs

func NewLogsReader

func NewLogsReader(clientset kubernetes.Interface) LogsReader

NewLogsReader instansiate new log reader

type ObjectRef

type ObjectRef struct {
	Kind      string
	Name      string
	Namespace string
}

type Runnable

type Runnable interface {
	Run(ctx context.Context) error
}

Runnable is the interface that wraps the basic Run method.

Run should be implemented by any task intended to be executed by the Runner.

func NewRunnableJob

func NewRunnableJob(
	clientset kubernetes.Interface,
	job *batchv1.Job,
) Runnable

NewRunnableJob constructs a new Runnable task defined as Kubernetes

type RunnableFunc

type RunnableFunc func(ctx context.Context) error

The RunnableFunc type is an adapter to allow the use of ordinary functions as Runnable tasks. If f is a function with the appropriate signature, RunnableFunc(f) is a Runnable that calls f.

func (RunnableFunc) Run

func (f RunnableFunc) Run(ctx context.Context) error

Run calls f()

type Runner

type Runner interface {
	Run(ctx context.Context, task Runnable) error
}

Runner is the interface that wraps the basic Run method.

Run executes submitted Runnable tasks.

func New

func New(opts ...RunnerOption) Runner

New constructs a new ready-to-use Runner for running a Runnable task.

type RunnerOption

type RunnerOption func(*runner)

func WithTimeout

func WithTimeout(timeout time.Duration) RunnerOption

Jump to

Keyboard shortcuts

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