scheduler

package
v2.0.0-...-3e3fc98 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentContainerName            = "agent"
	CopyAgentContainerName        = "copy-agent"
	ImageCheckContainerNamePrefix = "imagecheck-"
	CheckoutContainerName         = "checkout"
	CommandContainerName          = "container-0"
)

Variables

View Source
var ErrNoCommandModification = errors.New("modifying container commands or args via podSpecPatch is not supported")

Functions

func New

func New(logger *zap.Logger, client kubernetes.Interface, agentClient *api.AgentClient, cfg Config) *worker

func NewJobWatcher

func NewJobWatcher(logger *zap.Logger, k8sClient kubernetes.Interface, agentClient *api.AgentClient, cfg *config.Config) *jobWatcher

NewJobWatcher creates a JobWatcher.

func NewPodCompletionWatcher

func NewPodCompletionWatcher(logger *zap.Logger, k8s kubernetes.Interface) *completionsWatcher

func NewPodWatcher

func NewPodWatcher(logger *zap.Logger, k8s kubernetes.Interface, agentClient *api.AgentClient, cfg *config.Config) *podWatcher

NewPodWatcher creates an informer that does various things with pods and Buildkite jobs:

  • If an init container fails, the BK Agent REST API will be used to fail the job (since an agent hasn't run yet).
  • If a container stays in ImagePullBackOff or ErrImageNeverPull state for too long, the BK Agent REST API will be used to fail the job and the pod will be evicted.
  • If a container stays in ImagePullBackOff or ErrImageNeverPull, and the pod somehow got through all the init containers (including the image checks...) the Agent container should eventually detect a "lost client" and fail the job.
  • If a pod is pending, every so often Buildkite will be checked to see if the corresponding job has been cancelled so that the pod can be evicted early.

func PatchPodSpec

func PatchPodSpec(original *corev1.PodSpec, patch *corev1.PodSpec, cmdParams *config.CommandParams, k8sPlugin *KubernetesPlugin, allowUnsafeCmdMod bool) (*corev1.PodSpec, error)

Types

type BatchBuildkiteJobChecker

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

BatchBuildkiteJobChecker monitors Buildkite jobs for cancellation state changes. Unlike the old legacy BuildkiteJobChecker, this checker check all pending jobs together, relying on the new Stack API.

func NewBatchBuildkiteJobChecker

func NewBatchBuildkiteJobChecker(
	logger *zap.Logger,
	agentClient *api.AgentClient,
	k8s kubernetes.Interface,
	interval time.Duration,
) *BatchBuildkiteJobChecker

NewBatchBuildkiteJobChecker creates a new Batch Buildkite job checker.

func (*BatchBuildkiteJobChecker) AddJob

func (c *BatchBuildkiteJobChecker) AddJob(jobUUID uuid.UUID, podMeta metav1.ObjectMeta)

func (*BatchBuildkiteJobChecker) GetActiveCheckCount

func (c *BatchBuildkiteJobChecker) GetActiveCheckCount() int

GetActiveCheckCount returns the number of jobs currently being checked.

func (*BatchBuildkiteJobChecker) StartChecking

func (c *BatchBuildkiteJobChecker) StartChecking(ctx context.Context)

StartChecking starts a gorouting loop to periodically check job states for all jobs that it manages.

func (*BatchBuildkiteJobChecker) StopCheckingJob

func (c *BatchBuildkiteJobChecker) StopCheckingJob(jobUUID uuid.UUID)

type BuildkiteJobChecker

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

BuildkiteJobChecker monitors Buildkite jobs for cancellation state changes. It operate on individual jobs basis, relying on legacy Agent API. In the future version, we will get rid of it.

func NewBuildkiteJobChecker

func NewBuildkiteJobChecker(
	logger *zap.Logger,
	agentClient *api.AgentClient,
	k8s kubernetes.Interface,
	interval time.Duration,
) *BuildkiteJobChecker

NewBuildkiteJobChecker creates a new Buildkite job checker.

func (*BuildkiteJobChecker) GetActiveCheckCount

func (c *BuildkiteJobChecker) GetActiveCheckCount() int

GetActiveCheckCount returns the number of jobs currently being checked.

func (*BuildkiteJobChecker) StartChecking

func (c *BuildkiteJobChecker) StartChecking(ctx context.Context, log *zap.Logger, podMeta metav1.ObjectMeta, jobUUID uuid.UUID)

StartChecking starts monitoring a job for cancellation. This should only be called for jobs in pending state.

func (*BuildkiteJobChecker) StopChecking

func (c *BuildkiteJobChecker) StopChecking(jobUUID uuid.UUID)

StopChecking stops monitoring a job for cancellation. This should be called when jobs leave pending state.

type Config

type Config struct {
	Namespace                      string
	ID                             string
	Image                          string
	JobPrefix                      string
	AgentToken                     string
	AgentTokenSecretName           string
	JobTTL                         time.Duration
	JobActiveDeadlineSeconds       int
	AdditionalRedactedVars         []string
	WorkspaceVolume                *corev1.Volume
	AgentConfig                    *config.AgentConfig
	DefaultCheckoutParams          *config.CheckoutParams
	DefaultCommandParams           *config.CommandParams
	DefaultSidecarParams           *config.SidecarParams
	DefaultMetadata                config.Metadata
	DefaultImagePullPolicy         corev1.PullPolicy
	DefaultImageCheckPullPolicy    corev1.PullPolicy
	PodSpecPatch                   *corev1.PodSpec
	ProhibitK8sPlugin              bool
	AllowPodSpecPatchUnsafeCmdMod  bool
	SkipImageCheckContainers       bool
	ImageCheckContainerCPULimit    string
	ImageCheckContainerMemoryLimit string
	ResourceClasses                map[string]*config.ResourceClass
}

type FailureInfo

type FailureInfo struct {
	Message  string
	ExitCode int32
	Reason   string
}

FailureInfo contains data about a job failure for reporting to Buildkite.

type KubernetesPlugin

type KubernetesPlugin struct {
	PodSpec                  *corev1.PodSpec        `json:"podSpec,omitempty"`
	PodSpecPatch             *corev1.PodSpec        `json:"podSpecPatch,omitempty"`
	GitEnvFrom               []corev1.EnvFromSource `json:"gitEnvFrom,omitempty"`
	Sidecars                 []corev1.Container     `json:"sidecars,omitempty"`
	Metadata                 config.Metadata        `json:"metadata,omitempty"`
	ExtraVolumeMounts        []corev1.VolumeMount   `json:"extraVolumeMounts,omitempty"`
	CheckoutParams           *config.CheckoutParams `json:"checkout,omitempty"`
	CommandParams            *config.CommandParams  `json:"commandParams,omitempty"`
	SidecarParams            *config.SidecarParams  `json:"sidecarParams,omitempty"`
	JobActiveDeadlineSeconds int                    `json:"jobActiveDeadlineSeconds,omitempty"`
}

Jump to

Keyboard shortcuts

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