Documentation ¶
Overview ¶
Package pjutil contains helpers for working with ProwJobs.
Package pjutil contains helpers for working with ProwJobs.
Index ¶
- Variables
- func AvailablePresubmits(changes config.ChangedFilesProvider, branch string, ...) (sets.Set[string], sets.Set[string], sets.Set[string], error)
- func BatchSpec(p config.Presubmit, refs prowapi.Refs) prowapi.ProwJobSpec
- func ClusterToCtx(cluster string) string
- func CompletePrimaryRefs(refs prowapi.Refs, jb config.JobBase) *prowapi.Refs
- func DecorateExtraRefs(refs []prowapi.Refs, jb config.JobBase) []prowapi.Refs
- func DecorateRefs(refs prowapi.Refs, jb config.JobBase) *prowapi.Refs
- func FilterPresubmits(filter Filter, changes config.ChangedFilesProvider, branch string, ...) ([]config.Presubmit, error)
- func GetBuildID(name, totURL string) (string, error)
- func GetLatestProwJobs(pjs []prowapi.ProwJob, jobType prowapi.ProwJobType) map[string]prowapi.ProwJob
- func HelpMessage(org, repo, branch, note string, ...) string
- func JobURL(plank config.Plank, pj prowapi.ProwJob, log *logrus.Entry) (string, error)
- func MayNeedHelpComment(body string) bool
- func NewPresubmit(pr github.PullRequest, baseSHA string, job config.Presubmit, eventGUID string, ...) prowapi.ProwJob
- func NewProwJob(spec prowapi.ProwJobSpec, extraLabels, extraAnnotations map[string]string, ...) prowapi.ProwJob
- func PartitionActive(pjs []prowapi.ProwJob) (pending, triggered, aborted chan prowapi.ProwJob)
- func PatchProwjob(ctx context.Context, pjc prowClient, log *logrus.Entry, srcPJ prowapi.ProwJob, ...) (*prowapi.ProwJob, error)
- func PeriodicSpec(p config.Periodic) prowapi.ProwJobSpec
- func PeriodicToJobSpec(periodic config.Periodic) *downwardapi.JobSpec
- func PostsubmitSpec(p config.Postsubmit, refs prowapi.Refs) prowapi.ProwJobSpec
- func PostsubmitToJobSpec(post config.Postsubmit) *downwardapi.JobSpec
- func PresubmitSpec(p config.Presubmit, refs prowapi.Refs) prowapi.ProwJobSpec
- func PresubmitToJobSpec(pre config.Presubmit) *downwardapi.JobSpec
- func ProwJobFields(pj *prowapi.ProwJob) logrus.Fields
- func ShouldRespondWithHelp(body string, toRunOrSkip int) (bool, string)
- func TerminateOlderJobs(pjc patchClient, log *logrus.Entry, pjs []prowapi.ProwJob) error
- func TriggerAndWatchProwJob(o prowflagutil.KubernetesOptions, prowjob *pjapi.ProwJob, ...) (succeeded bool, err error)
- type AggregateFilter
- type ArbitraryFilter
- type CommandFilter
- type Filter
- type Health
- type Modifier
- type Modifiers
- type ReadynessCheck
- type RetestFilter
- type RetestRequiredFilter
- type TestAllFilter
Constants ¶
This section is empty.
Variables ¶
var ( TestHelpRe = regexp.MustCompile(`(?m)^/test[ \t]*\?\s*$`) EmptyTestRe = regexp.MustCompile(`(?m)^/test\s*$`) RetestWithTargetRe = regexp.MustCompile(`(?m)^/retest[ \t]+\S+`) TestWithAnyTargetRe = regexp.MustCompile(`(?m)^/test[ \t]+\S+`) TestWithoutTargetNote = "The `/test` command needs one or more targets.\n" RetestWithTargetNote = "The `/retest` command does not accept any targets.\n" TargetNotFoundNote = "The specified target(s) for `/test` were not found.\n" ThereAreNoTestAllJobsNote = "No jobs can be run with `/test all`.\n" )
var OkToTestRe = regexp.MustCompile(`(?m)^/ok-to-test\s*$`)
var RetestRe = regexp.MustCompile(`(?m)^/retest\s*$`)
RetestRe provides the regex for `/retest`
var RetestRequiredRe = regexp.MustCompile(`(?m)^/retest-required\s*$`)
RetestRe provides the regex for `/retest-required`
var TestAllRe = regexp.MustCompile(`(?m)^/test all,?($|\s.*)`)
Functions ¶
func AvailablePresubmits ¶
func AvailablePresubmits(changes config.ChangedFilesProvider, branch string, presubmits []config.Presubmit, logger *logrus.Entry) (sets.Set[string], sets.Set[string], sets.Set[string], error)
AvailablePresubmits returns 3 sets of presubmits: 1. presubmits that can be run with '/test all' command. 2. optional presubmits commands that can be run with their trigger, e.g. '/test job' 3. required presubmits commands that can be run with their trigger, e.g. '/test job'
func ClusterToCtx ¶
ClusterToCtx converts the prow job's cluster to a cluster context
func CompletePrimaryRefs ¶
func DecorateExtraRefs ¶
func FilterPresubmits ¶
func FilterPresubmits(filter Filter, changes config.ChangedFilesProvider, branch string, presubmits []config.Presubmit, logger logrus.FieldLogger) ([]config.Presubmit, error)
FilterPresubmits determines which presubmits should run by evaluating the user-provided filter.
func GetBuildID ¶
GetBuildID calls out to `tot` in order to vend build identifier for the job
func GetLatestProwJobs ¶
func GetLatestProwJobs(pjs []prowapi.ProwJob, jobType prowapi.ProwJobType) map[string]prowapi.ProwJob
GetLatestProwJobs filters through the provided prowjobs and returns a map of jobType jobs to their latest prowjobs.
func HelpMessage ¶
func HelpMessage(org, repo, branch, note string, testAllNames, optionalTestCommands, requiredTestCommands sets.Set[string]) string
HelpMessage returns a user friendly help message with the
available /test commands that can be triggered
func JobURL ¶
JobURL returns the expected URL for ProwJobStatus.
TODO(fejta): consider moving default JobURLTemplate and JobURLPrefix out of plank
func MayNeedHelpComment ¶
func NewPresubmit ¶
func NewPresubmit(pr github.PullRequest, baseSHA string, job config.Presubmit, eventGUID string, additionalLabels map[string]string, modifiers ...Modifier) prowapi.ProwJob
NewPresubmit converts a config.Presubmit into a prowapi.ProwJob. The prowapi.Refs are configured correctly per the pr, baseSHA. The eventGUID becomes a github.EventGUID label. Presubmit is finally mutated according to the modifiers.
func NewProwJob ¶
func NewProwJob(spec prowapi.ProwJobSpec, extraLabels, extraAnnotations map[string]string, modifiers ...Modifier) prowapi.ProwJob
NewProwJob initializes a ProwJob out of a ProwJobSpec, with some extra modifiers.
func PartitionActive ¶
PartitionActive separates the provided prowjobs into pending and triggered and returns them inside channels so that they can be consumed in parallel by different goroutines. Complete prowjobs are filtered out. Controller loops need to handle pending jobs first so they can conform to maximum concurrency requirements that different jobs may have.
func PatchProwjob ¶
func PeriodicSpec ¶
func PeriodicSpec(p config.Periodic) prowapi.ProwJobSpec
PeriodicSpec initializes a ProwJobSpec for a given periodic job.
func PeriodicToJobSpec ¶
func PeriodicToJobSpec(periodic config.Periodic) *downwardapi.JobSpec
PeriodicToJobSpec generates a downwardapi.JobSpec out of a Periodic. Useful for figuring out GCS paths when parsing jobs out of a prow config.
func PostsubmitSpec ¶
func PostsubmitSpec(p config.Postsubmit, refs prowapi.Refs) prowapi.ProwJobSpec
PostsubmitSpec initializes a ProwJobSpec for a given postsubmit job.
func PostsubmitToJobSpec ¶
func PostsubmitToJobSpec(post config.Postsubmit) *downwardapi.JobSpec
PostsubmitToJobSpec generates a downwardapi.JobSpec out of a Postsubmit. Useful for figuring out GCS paths when parsing jobs out of a prow config.
func PresubmitSpec ¶
PresubmitSpec initializes a ProwJobSpec for a given presubmit job.
func PresubmitToJobSpec ¶
func PresubmitToJobSpec(pre config.Presubmit) *downwardapi.JobSpec
PresubmitToJobSpec generates a downwardapi.JobSpec out of a Presubmit. Useful for figuring out GCS paths when parsing jobs out of a prow config.
func ProwJobFields ¶
ProwJobFields extracts logrus fields from a prowjob useful for logging.
func ShouldRespondWithHelp ¶
func TerminateOlderJobs ¶
TerminateOlderJobs aborts all presubmit jobs from the given list that have a newer version. It does not set the prowjob to complete. The responsible agent is expected to react to the aborted state by aborting the actual test payload and then setting the ProwJob to completed.
func TriggerAndWatchProwJob ¶
func TriggerAndWatchProwJob(o prowflagutil.KubernetesOptions, prowjob *pjapi.ProwJob, config *prowconfig.Config, envVars map[string]string, dryRun bool) (succeeded bool, err error)
TriggerAndWatchProwJob would trigger the job provided by the prowjob parameter
Types ¶
type AggregateFilter ¶
type AggregateFilter struct {
// contains filtered or unexported fields
}
AggregateFilter builds a filter that evaluates the child filters in order and returns the first match
func NewAggregateFilter ¶
func NewAggregateFilter(filters []Filter) *AggregateFilter
func (*AggregateFilter) Name ¶
func (nf *AggregateFilter) Name() string
type ArbitraryFilter ¶
type ArbitraryFilter struct {
// contains filtered or unexported fields
}
ArbitraryFilter is a lazy filter that can be used ad hoc when consumer doesn't want to declare a new struct. One of the usage is in unit test.
func NewArbitraryFilter ¶
func (*ArbitraryFilter) Name ¶
func (af *ArbitraryFilter) Name() string
type CommandFilter ¶
type CommandFilter struct {
// contains filtered or unexported fields
}
CommandFilter builds a filter for `/test foo`
func NewCommandFilter ¶
func NewCommandFilter(body string) *CommandFilter
func (*CommandFilter) Name ¶
func (cf *CommandFilter) Name() string
type Filter ¶
type Filter interface { ShouldRun(p config.Presubmit) (shouldRun bool, forcedToRun bool, defaultBehavior bool) Name() string }
Filter digests a presubmit config to determine if:
- the presubmit matched the filter
- we know that the presubmit is forced to run
- what the default behavior should be if the presubmit runs conditionally and does not match trigger conditions
func PresubmitFilter ¶
func PresubmitFilter(honorOkToTest bool, contextGetter contextGetter, body string, logger logrus.FieldLogger) (Filter, error)
PresubmitFilter creates a filter for presubmits
type Health ¶
type Health struct {
// contains filtered or unexported fields
}
Health keeps a request multiplexer for health liveness and readiness endpoints
func NewHealth ¶
func NewHealth() *Health
NewHealth creates a new health request multiplexer and starts serving the liveness endpoint on the default port
func NewHealthOnPort ¶
NewHealth creates a new health request multiplexer and starts serving the liveness endpoint on the given port
func (*Health) ServeReady ¶
func (h *Health) ServeReady(readynessChecks ...ReadynessCheck)
ServeReady starts serving the readiness endpoint
type Modifier ¶
type Modifier func(*Modifiers)
Modifier configures a Modifiers value
func RequireScheduling ¶
RequireScheduling returns an Option that, if enabled, set the ProwJob initial state to SchedulingState
type Modifiers ¶
type Modifiers struct {
// contains filtered or unexported fields
}
Modifiers allows a client to set some fields when a ProwJob is being created.
type ReadynessCheck ¶
type ReadynessCheck func() bool
type RetestFilter ¶
type RetestFilter struct {
// contains filtered or unexported fields
}
RetestFilter builds a filter for `/retest`
func NewRetestFilter ¶
func NewRetestFilter(failedContexts, allContexts sets.Set[string]) *RetestFilter
func (*RetestFilter) Name ¶
func (rf *RetestFilter) Name() string
type RetestRequiredFilter ¶
type RetestRequiredFilter struct {
// contains filtered or unexported fields
}
func NewRetestRequiredFilter ¶
func NewRetestRequiredFilter(failedContexts, allContexts sets.Set[string]) *RetestRequiredFilter
func (*RetestRequiredFilter) Name ¶
func (rrf *RetestRequiredFilter) Name() string
type TestAllFilter ¶
type TestAllFilter struct{}
TestAllFilter builds a filter for the automatic behavior of `/test all`. Jobs that explicitly match `/test all` in their trigger regex will be handled by a commandFilter for the comment in question.
func NewTestAllFilter ¶
func NewTestAllFilter() *TestAllFilter
func (*TestAllFilter) Name ¶
func (tf *TestAllFilter) Name() string