job

package
v0.0.765 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2020 License: Apache-2.0 Imports: 9 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"
)

Variables

This section is empty.

Functions

func AvailablePipelineAgentTypes

func AvailablePipelineAgentTypes() []string

AvailablePipelineAgentTypes returns a slice of all available pipeline agent types

func ClearCompiledRegexes

func ClearCompiledRegexes(presubmits []Presubmit)

ClearCompiledRegexes removes compiled regexes from the presubmits, useful for testing when deep equality is needed between presubmits

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 SetPostsubmitRegexes

func SetPostsubmitRegexes(ps []Postsubmit) error

SetPostsubmitRegexes compiles and validates all the regular expressions for the provided postsubmits.

func SetPresubmitRegexes

func SetPresubmitRegexes(ps []Presubmit) error

SetPresubmitRegexes compiles and validates all the regular expressions for the provided presubmits.

Types

type Base

type Base struct {
	// 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"`

	UtilityConfig
}

Base contains attributes common to all job types

func (*Base) SetDefaults

func (b *Base) SetDefaults(namespace string)

SetDefaults initializes default values

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) 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.

type Periodic

type Periodic struct {
	Base

	// (deprecated)Interval to wait between two runs of the job.
	Interval string `json:"interval"`
	// Cron representation of job trigger time
	Cron string `json:"cron"`
	// Tags for config entries
	Tags []string `json:"tags,omitempty"`
	// contains filtered or unexported fields
}

Periodic runs on a timer.

func (*Periodic) GetInterval

func (p *Periodic) GetInterval() time.Duration

GetInterval returns interval, the frequency duration it runs.

func (*Periodic) SetDefaults

func (p *Periodic) SetDefaults(namespace string)

SetDefaults initializes default values

func (*Periodic) SetInterval

func (p *Periodic) SetInterval(d time.Duration)

SetInterval updates interval, the frequency duration it runs.

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

	// 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"`

	Brancher

	RegexpChangeMatcher

	Reporter
}

Presubmit runs on PRs.

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).

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