pjutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package pjutil contains helpers for working with ProwJobs.

Package pjutil contains helpers for working with ProwJobs.

Index

Constants

This section is empty.

Variables

View Source
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"
)
View Source
var OkToTestRe = regexp.MustCompile(`(?m)^/ok-to-test\s*$`)
View Source
var RetestRe = regexp.MustCompile(`(?m)^/retest\s*$`)

RetestRe provides the regex for `/retest`

View Source
var RetestRequiredRe = regexp.MustCompile(`(?m)^/retest-required\s*$`)

RetestRe provides the regex for `/retest-required`

View Source
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.String, sets.String, sets.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 BatchSpec

func BatchSpec(p config.Presubmit, refs prowapi.Refs) prowapi.ProwJobSpec

BatchSpec initializes a ProwJobSpec for a given batch job and ref spec.

func ClusterToCtx

func ClusterToCtx(cluster string) string

ClusterToCtx converts the prow job's cluster to a cluster context

func CompletePrimaryRefs

func CompletePrimaryRefs(refs prowapi.Refs, jb config.JobBase) *prowapi.Refs

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

func GetBuildID(name, totURL string) (string, error)

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

HelpMessage returns a user friendly help message with the

available /test commands that can be triggered

func JobURL

func JobURL(plank config.Plank, pj prowapi.ProwJob, log *logrus.Entry) (string, error)

JobURL returns the expected URL for ProwJobStatus.

TODO(fejta): consider moving default JobURLTemplate and JobURLPrefix out of plank

func MayNeedHelpComment

func MayNeedHelpComment(body string) bool

func NewPresubmit

func NewPresubmit(pr github.PullRequest, baseSHA string, job config.Presubmit, eventGUID string, additionalLabels map[string]string) 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.

func NewProwJob

func NewProwJob(spec prowapi.ProwJobSpec, extraLabels, extraAnnotations map[string]string) prowapi.ProwJob

NewProwJob initializes a ProwJob out of a ProwJobSpec.

func PartitionActive

func PartitionActive(pjs []prowapi.ProwJob) (pending, triggered, aborted chan prowapi.ProwJob)

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 PatchProwjob(ctx context.Context, pjc prowClient, log *logrus.Entry, srcPJ prowapi.ProwJob, destPJ prowapi.ProwJob) (*prowapi.ProwJob, error)

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

func PresubmitSpec(p config.Presubmit, refs prowapi.Refs) prowapi.ProwJobSpec

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

func ProwJobFields(pj *prowapi.ProwJob) logrus.Fields

ProwJobFields extracts logrus fields from a prowjob useful for logging.

func ShouldRespondWithHelp

func ShouldRespondWithHelp(body string, toRunOrSkip int) (bool, string)

func TerminateOlderJobs

func TerminateOlderJobs(pjc patchClient, log *logrus.Entry, pjs []prowapi.ProwJob) error

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

func (*AggregateFilter) ShouldRun

func (nf *AggregateFilter) ShouldRun(p config.Presubmit) (bool, bool, bool)

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 NewArbitraryFilter(override func(p config.Presubmit) (shouldRun bool, forcedToRun bool, defaultBehavior bool), name string) *ArbitraryFilter

func (*ArbitraryFilter) Name

func (af *ArbitraryFilter) Name() string

func (*ArbitraryFilter) ShouldRun

func (af *ArbitraryFilter) ShouldRun(p config.Presubmit) (shouldRun bool, forcedToRun bool, defaultBehavior bool)

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

func (*CommandFilter) ShouldRun

func (cf *CommandFilter) ShouldRun(p config.Presubmit) (bool, bool, bool)

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

func NewHealthOnPort(port int) *Health

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 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.String) *RetestFilter

func (*RetestFilter) Name

func (rf *RetestFilter) Name() string

func (*RetestFilter) ShouldRun

func (rf *RetestFilter) ShouldRun(p config.Presubmit) (bool, bool, bool)

type RetestRequiredFilter

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

func NewRetestRequiredFilter

func NewRetestRequiredFilter(failedContexts, allContexts sets.String) *RetestRequiredFilter

func (*RetestRequiredFilter) Name

func (rrf *RetestRequiredFilter) Name() string

func (*RetestRequiredFilter) ShouldRun

func (rrf *RetestRequiredFilter) ShouldRun(ps config.Presubmit) (bool, bool, bool)

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

func (*TestAllFilter) ShouldRun

func (tf *TestAllFilter) ShouldRun(p config.Presubmit) (bool, bool, bool)

Directories

Path Synopsis
Package pprof contains helpers for profiling binaries.
Package pprof contains helpers for profiling binaries.

Jump to

Keyboard shortcuts

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