job

package
v0.0.780 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: Apache-2.0 Imports: 12 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// JenkinsXAgent is the agent type for running Jenkins X pipelines
	JenkinsXAgent = "jenkins-x"

	// LegacyDefaultAgent is a backwards compatible way of dealing with legacy cases of "tekton" as the default agent, but meaning Jenkins X
	LegacyDefaultAgent = "tekton"

	// TektonPipelineAgent is the agent type for running Tekton Pipeline pipelines
	TektonPipelineAgent = "tekton-pipeline"
)

Various agents.

View Source
const (
	// LighthouseJobTypeLabel is added in resources created by lighthouse and
	// carries the job type (presubmit, postsubmit, periodic, batch)
	// that the pod is running.
	LighthouseJobTypeLabel = "lighthouse.jenkins-x.io/type"
	// LighthouseJobIDLabel is added in resources created by lighthouse and
	// carries the ID of the LighthouseJob that the pod is fulfilling.
	// We also name resources after the LighthouseJob that spawned them but
	// this allows for multiple resources to be linked to one
	// LighthouseJob.
	LighthouseJobIDLabel = "lighthouse.jenkins-x.io/id"
	// CreatedByLighthouseLabel is added on resources created by Lighthosue.
	// Since resources often live in another cluster/namespace,
	// the k8s garbage collector would immediately delete these
	// resources
	CreatedByLighthouseLabel = "created-by-lighthouse"
)
View Source
const (
	// DefaultClusterAlias specifies the default context for resources owned by jobs (pods/builds).
	DefaultClusterAlias = "default"
)

Variables

This section is empty.

Functions

func AvailablePipelineAgentTypes

func AvailablePipelineAgentTypes() []string

AvailablePipelineAgentTypes returns a slice of all available pipeline agent types

func Labels added in v0.0.766

func Labels() []string

Labels returns a string slice with label consts from kube.

func MergePreset

func MergePreset(preset Preset, labels map[string]string, pod *v1.PodSpec) error

MergePreset merges a preset and labels with a pod spec

func ValidateLabels added in v0.0.766

func ValidateLabels(labels map[string]string) error

ValidateLabels validates labels (not using reserved labels, valid names and valid values)

Types

type Base

type Base struct {
	UtilityConfig
	// The name of the job. Must match regex [A-Za-z0-9-._]+
	// e.g. pull-test-infra-bazel-build
	Name string `json:"name"`
	// Labels are added to LighthouseJobs and pods created for this job.
	Labels map[string]string `json:"labels,omitempty"`
	// Annotations are unused by prow itself, but provide a space to configure other automation.
	Annotations map[string]string `json:"annotations,omitempty"`
	// MaximumConcurrency of this job, 0 implies no limit.
	MaxConcurrency int `json:"max_concurrency,omitempty"`
	// Agent that will take care of running this job.
	Agent string `json:"agent"`
	// Cluster is the alias of the cluster to run this job in.
	// (Default: kube.DefaultClusterAlias)
	Cluster string `json:"cluster,omitempty"`
	// Namespace is the namespace in which pods schedule.
	//   nil: results in config.PodNamespace (aka pod default)
	//   empty: results in config.LighthouseJobNamespace (aka same as LighthouseJob)
	Namespace *string `json:"namespace,omitempty"`
	// ErrorOnEviction indicates that the LighthouseJob should be completed and given
	// the ErrorState status if the pod that is executing the job is evicted.
	// If this field is unspecified or false, a new pod will be created to replace
	// the evicted one.
	ErrorOnEviction bool `json:"error_on_eviction,omitempty"`
	// SourcePath contains the path where this job is defined
	SourcePath string `json:"-"`
	// Spec is the Kubernetes pod spec used if Agent is kubernetes.
	Spec *v1.PodSpec `json:"spec,omitempty"`
	// PipelineRunSpec is the Tekton PipelineRun spec used if agent is tekton-pipeline
	PipelineRunSpec *tektonv1beta1.PipelineRunSpec `json:"pipeline_run_spec,omitempty"`
	// PipelineRunParams are the params used by the pipeline run
	PipelineRunParams []PipelineRunParam `json:"pipeline_run_params,omitempty"`
}

Base contains attributes common to all job types

func (*Base) SetDefaults

func (b *Base) SetDefaults(namespace string)

SetDefaults initializes default values

func (*Base) Validate added in v0.0.766

func (b *Base) Validate(jobType PipelineKind, podNamespace string) error

Validate validates job base

func (*Base) ValidateAgent added in v0.0.766

func (b *Base) ValidateAgent(podNamespace string) error

ValidateAgent validates job agent

func (*Base) ValidatePodSpec added in v0.0.766

func (b *Base) ValidatePodSpec(jobType PipelineKind) error

ValidatePodSpec validates job pod spec

type Brancher

type Brancher struct {
	// Do not run against these branches. Default is no branches.
	SkipBranches []string `json:"skip_branches,omitempty"`
	// Only run against these branches. Default is all branches.
	Branches []string `json:"branches,omitempty"`
	// contains filtered or unexported fields
}

Brancher is for shared code between jobs that only run against certain branches. An empty brancher runs against all branches.

func (Brancher) GetRE

func (br Brancher) GetRE() *regexp.Regexp

GetRE returns the branch regexp

func (Brancher) GetRESkip

func (br Brancher) GetRESkip() *regexp.Regexp

GetRESkip return the branch skip regexp

func (Brancher) Intersects

func (br Brancher) Intersects(other Brancher) bool

Intersects checks if other Brancher would trigger for the same branch.

func (Brancher) RunsAgainstAllBranch

func (br Brancher) RunsAgainstAllBranch() bool

RunsAgainstAllBranch returns true if there are both branches and skip_branches are unset

func (Brancher) SetBrancherRegexes

func (br Brancher) SetBrancherRegexes() (Brancher, error)

SetBrancherRegexes validates and compiles internal regexes

func (Brancher) ShouldRun

func (br Brancher) ShouldRun(branch string) bool

ShouldRun returns true if the input branch matches, given the includes/excludes.

type ChangedFilesProvider

type ChangedFilesProvider func() ([]string, error)

ChangedFilesProvider returns a slice of modified files.

func NewGitHubDeferredChangedFilesProvider

func NewGitHubDeferredChangedFilesProvider(client scmClient, org, repo string, num int) ChangedFilesProvider

NewGitHubDeferredChangedFilesProvider uses a closure to lazily retrieve the file changes only if they are needed. We only have to fetch the changes if there is at least one RunIfChanged job that is not being force run (due to a `/retest` after a failure or because it is explicitly triggered with `/test foo`).

type Config

type Config struct {
	// Presets apply to all job types.
	Presets []Preset `json:"presets,omitempty"`
	// Full repo name (such as "kubernetes/kubernetes") -> list of jobs.
	Presubmits  map[string][]Presubmit  `json:"presubmits,omitempty"`
	Postsubmits map[string][]Postsubmit `json:"postsubmits,omitempty"`
	// Periodics are not associated with any repo.
	Periodics []Periodic `json:"periodics,omitempty"`
}

Config is config for all prow jobs

func (*Config) AllPeriodics

func (c *Config) AllPeriodics() []Periodic

AllPeriodics returns all prow periodic jobs.

func (*Config) AllPostsubmits

func (c *Config) AllPostsubmits(repos []string) []Postsubmit

AllPostsubmits returns all prow postsubmit jobs in repos. if repos is empty, return all postsubmits.

func (*Config) AllPresubmits

func (c *Config) AllPresubmits(repos []string) []Presubmit

AllPresubmits returns all prow presubmit jobs in repos. if repos is empty, return all presubmits.

func (*Config) DecorationRequested

func (c *Config) DecorationRequested() bool

DecorationRequested checks if decoration was requested

func (*Config) Init added in v0.0.766

func (c *Config) Init(lh lighthouse.Config) error

Init sets defaults and initializes Config

func (*Config) Merge added in v0.0.766

func (c *Config) Merge(other Config) error

Merge merges one Config with another one

func (*Config) SetPostsubmits

func (c *Config) SetPostsubmits(jobs map[string][]Postsubmit) error

SetPostsubmits updates c.Postsubmits to jobs, after compiling and validating their regexes.

func (*Config) SetPresubmits

func (c *Config) SetPresubmits(jobs map[string][]Presubmit) error

SetPresubmits updates c.Presubmits to jobs, after compiling and validating their regexes.

func (*Config) Validate added in v0.0.766

func (c *Config) Validate(lh lighthouse.Config) error

Validate validates Config

type Periodic

type Periodic struct {
	Base
	// Cron representation of job trigger time
	Cron string `json:"cron"`
	// Tags for config entries
	Tags []string `json:"tags,omitempty"`
}

Periodic runs on a timer.

func (*Periodic) SetDefaults

func (p *Periodic) SetDefaults(namespace string)

SetDefaults initializes default values

type PipelineKind added in v0.0.766

type PipelineKind string

PipelineKind specifies how the job is triggered.

const (
	// PresubmitJob means it runs on unmerged PRs.
	PresubmitJob PipelineKind = "presubmit"
	// PostsubmitJob means it runs on each new commit.
	PostsubmitJob PipelineKind = "postsubmit"
	// Periodic job means it runs on a time-basis, unrelated to git changes.
	PeriodicJob PipelineKind = "periodic"
	// BatchJob tests multiple unmerged PRs at the same time.
	BatchJob PipelineKind = "batch"
)

Various job types.

type PipelineRunParam

type PipelineRunParam struct {
	// Name is the name of the param
	Name string `json:"name,omitempty"`
	// ValueTemplate is the template used to build the value from well know variables
	ValueTemplate string `json:"value_template,omitempty"`
}

PipelineRunParam represents a param used by the pipeline run

type Postsubmit

type Postsubmit struct {
	Base

	RegexpChangeMatcher

	Brancher

	// TODO(krzyzacy): Move existing `Report` into `Skip_Report` once this is deployed
	Reporter
}

Postsubmit runs on push events.

func (Postsubmit) CouldRun

func (p Postsubmit) CouldRun(baseRef string) bool

CouldRun determines if the postsubmit could run against a specific base ref

func (*Postsubmit) SetDefaults

func (p *Postsubmit) SetDefaults(namespace string)

SetDefaults initializes default values

func (*Postsubmit) SetRegexes

func (p *Postsubmit) SetRegexes() error

SetRegexes compiles and validates all the regular expressions

func (Postsubmit) ShouldRun

func (p Postsubmit) ShouldRun(baseRef string, changes ChangedFilesProvider) (bool, error)

ShouldRun determines if the postsubmit should run in response to a set of changes. This is evaluated lazily, if necessary.

type Preset

type Preset struct {
	Labels       map[string]string `json:"labels"`
	Env          []v1.EnvVar       `json:"env"`
	Volumes      []v1.Volume       `json:"volumes"`
	VolumeMounts []v1.VolumeMount  `json:"volumeMounts"`
}

Preset is intended to match the k8s' PodPreset feature, and may be removed if that feature goes beta.

type Presubmit

type Presubmit struct {
	Base
	Brancher
	RegexpChangeMatcher
	Reporter
	// AlwaysRun automatically for every PR, or only when a comment triggers it.
	AlwaysRun bool `json:"always_run"`
	// Optional indicates that the job's status context should not be required for merge.
	Optional bool `json:"optional,omitempty"`
	// Trigger is the regular expression to trigger the job.
	// e.g. `@k8s-bot e2e test this`
	// RerunCommand must also be specified if this field is specified.
	// (Default: `(?m)^/test (?:.*? )?<job name>(?: .*?)?$`)
	Trigger string `json:"trigger,omitempty"`
	// The RerunCommand to give users. Must match Trigger.
	// Trigger must also be specified if this field is specified.
	// (Default: `/test <job name>`)
	RerunCommand string `json:"rerun_command,omitempty"`
}

Presubmit runs on PRs.

func (*Presubmit) ClearCompiledRegexes added in v0.0.766

func (p *Presubmit) ClearCompiledRegexes()

ClearCompiledRegexes compiles and validates all the regular expressions

func (Presubmit) ContextRequired

func (p Presubmit) ContextRequired() bool

ContextRequired checks whether a context is required from github points of view (required check).

func (Presubmit) CouldRun

func (p Presubmit) CouldRun(baseRef string) bool

CouldRun determines if the presubmit could run against a specific base ref

func (Presubmit) NeedsExplicitTrigger

func (p Presubmit) NeedsExplicitTrigger() bool

NeedsExplicitTrigger determines if the presubmit requires a human action to trigger it or not.

func (*Presubmit) SetDefaults

func (p *Presubmit) SetDefaults(namespace string)

SetDefaults initializes default values

func (*Presubmit) SetRegexes

func (p *Presubmit) SetRegexes() error

SetRegexes compiles and validates all the regular expressions

func (Presubmit) ShouldRun

func (p Presubmit) ShouldRun(baseRef string, changes ChangedFilesProvider, forced, defaults bool) (bool, error)

ShouldRun determines if the presubmit should run against a specific base ref, or in response to a set of changes. The latter mechanism is evaluated lazily, if necessary.

func (Presubmit) TriggerMatches

func (p Presubmit) TriggerMatches(body string) bool

TriggerMatches returns true if the comment body should trigger this presubmit.

This is usually a /test foo string.

func (Presubmit) TriggersConditionally

func (p Presubmit) TriggersConditionally() bool

TriggersConditionally determines if the presubmit triggers conditionally (if it may or may not trigger).

func (*Presubmit) Validate added in v0.0.766

func (p *Presubmit) Validate(podNamespace string) error

Validate validates job base

type RegexpChangeMatcher

type RegexpChangeMatcher struct {
	// RunIfChanged defines a regex used to select which subset of file changes should trigger this job.
	// If any file in the changeset matches this regex, the job will be triggered
	RunIfChanged string `json:"run_if_changed,omitempty"`
	// contains filtered or unexported fields
}

RegexpChangeMatcher is for code shared between jobs that run only when certain files are changed.

func (RegexpChangeMatcher) CouldRun

func (cm RegexpChangeMatcher) CouldRun() bool

CouldRun determines if its possible for a set of changes to trigger this condition

func (RegexpChangeMatcher) RunsAgainstChanges

func (cm RegexpChangeMatcher) RunsAgainstChanges(changes []string) bool

RunsAgainstChanges returns true if any of the changed input paths match the run_if_changed regex.

func (RegexpChangeMatcher) SetChangeRegexes

func (cm RegexpChangeMatcher) SetChangeRegexes() (RegexpChangeMatcher, error)

SetChangeRegexes validates and compiles internal regexes

func (RegexpChangeMatcher) ShouldRun

func (cm RegexpChangeMatcher) ShouldRun(changes ChangedFilesProvider) (determined bool, shouldRun bool, err error)

ShouldRun determines if we can know for certain that the job should run. We can either know for certain that the job should or should not run based on the matcher, or we can not be able to determine that fact at all.

type Reporter

type Reporter struct {
	// Context is the name of the GitHub status context for the job.
	// Defaults: the same as the name of the job.
	Context string `json:"context,omitempty"`
	// SkipReport skips commenting and setting status on GitHub.
	SkipReport bool `json:"skip_report,omitempty"`
}

Reporter keeps various details for status reporting

type UtilityConfig

type UtilityConfig struct {
	// Decorate determines if we decorate the PodSpec or not
	Decorate bool `json:"decorate,omitempty"`
	// PathAlias is the location under <root-dir>/src
	// where the repository under test is cloned. If this
	// is not set, <root-dir>/src/github.com/org/repo will
	// be used as the default.
	PathAlias string `json:"path_alias,omitempty"`
	// CloneURI is the URI that is used to clone the
	// repository. If unset, will default to
	// `https://github.com/org/repo.git`.
	CloneURI string `json:"clone_uri,omitempty"`
	// SkipSubmodules determines if submodules should be
	// cloned when the job is run. Defaults to true.
	SkipSubmodules bool `json:"skip_submodules,omitempty"`
	// CloneDepth is the depth of the clone that will be used.
	// A depth of zero will do a full clone.
	CloneDepth int `json:"clone_depth,omitempty"`
}

UtilityConfig holds decoration metadata, such as how to clone and additional containers/etc

Jump to

Keyboard shortcuts

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