config

package
v0.0.0-...-fe50fa5 Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package config knows how to read and parse config.yaml.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetRegexes

func SetRegexes(js []Presubmit) error

SetRegexes compiles and validates all the regural expressions for the provided presubmits.

func ValidateController

func ValidateController(c *Controller) error

ValidateController validates the provided controller config.

Types

type Agent

type Agent struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Agent watches a path and automatically loads the config stored therein.

func (*Agent) Config

func (ca *Agent) Config() *Config

Config returns the latest config. Do not modify the config.

func (*Agent) Set

func (ca *Agent) Set(c *Config)

Set sets the config. Useful for testing.

func (*Agent) Start

func (ca *Agent) Start(path string) error

Start will begin polling the config file at the path. If the first load fails, Start with return the error and abort. Future load failures will log the failure message but continue attempting to load.

type Branch

type Branch struct {
	Policy
}

type BranchProtection

type BranchProtection struct {
	Policy
	ProtectTested bool           `json:"protect-tested-repos,omitempty"`
	Orgs          map[string]Org `json:"orgs,omitempty"`
}

BranchProtection specifies the global branch protection policy

type Brancher

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

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

func (Brancher) RunsAgainstAllBranch

func (br Brancher) RunsAgainstAllBranch() bool

func (Brancher) RunsAgainstBranch

func (br Brancher) RunsAgainstBranch(branch string) bool

type Branding

type Branding struct {
	Logo string `json:"logo,omitempty"`
	// Favicon is the location of the favicon that will be loaded in deck.
	Favicon string `json:"favicon,omitempty"`
	// BackgroundColor is the color of the background.
	BackgroundColor string `json:"background_color,omitempty"`
	// HeaderColor is the color of the header.
	HeaderColor string `json:"header_color,omitempty"`
}

Branding holds branding configuration for deck.

type ChangedFilesProvider

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

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

	Tide             Tide             `json:"tide,omitempty"`
	Plank            Plank            `json:"plank,omitempty"`
	Sinker           Sinker           `json:"sinker,omitempty"`
	Deck             Deck             `json:"deck,omitempty"`
	BranchProtection BranchProtection `json:"branch-protection,omitempty"`
	Gerrit           Gerrit           `json:"gerrit,omitempty"`

	// TODO: Move this out of the main config.
	JenkinsOperators []JenkinsOperator `json:"jenkins_operators,omitempty"`

	// ProwJobNamespace is the namespace in the cluster that prow
	// components will use for looking up ProwJobs. The namespace
	// needs to exist and will not be created by prow.
	// Defaults to "default".
	ProwJobNamespace string `json:"prowjob_namespace,omitempty"`
	// PodNamespace is the namespace in the cluster that prow
	// components will use for looking up Pods owned by ProwJobs.
	// The namespace needs to exist and will not be created by prow.
	// Defaults to "default".
	PodNamespace string `json:"pod_namespace,omitempty"`

	// LogLevel enables dynamically updating the log level of the
	// standard logger that is used by all prow components.
	//
	// Valid values:
	//
	// "debug", "info", "warn", "warning", "error", "fatal", "panic"
	//
	// Defaults to "info".
	LogLevel string `json:"log_level,omitempty"`

	// PushGateway is a prometheus push gateway.
	PushGateway PushGateway `json:"push_gateway,omitempty"`

	// OwnersDirBlacklist is used to configure which directories to ignore when
	// searching for OWNERS{,_ALIAS} files in a repo.
	OwnersDirBlacklist OwnersDirBlacklist `json:"owners_dir_blacklist,omitempty"`
}

Config is a read-only snapshot of the config.

func Load

func Load(path string) (*Config, error)

Load loads and parses the config at path.

func (*Config) AllPeriodics

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

AllPostsubmits 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) GetBranchProtection

func (c *Config) GetBranchProtection(org, repo, branch string) (*Policy, error)

func (*Config) GetPresubmit

func (c *Config) GetPresubmit(repo, jobName string) *Presubmit

GetPresubmit returns the presubmit job for the provided repo and job name.

func (*Config) MatchingPresubmits

func (c *Config) MatchingPresubmits(fullRepoName, body string, testAll bool) []Presubmit

func (*Config) RetestPresubmits

func (c *Config) RetestPresubmits(fullRepoName string, skipContexts, runContexts map[string]bool) []Presubmit

RetestPresubmits returns all presubmits that should be run given a /retest command. This is the set of all presubmits intersected with ((alwaysRun + runContexts) - skipContexts)

func (*Config) SetPresubmits

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

type Controller

type Controller struct {
	// JobURLTemplateString compiles into JobURLTemplate at load time.
	JobURLTemplateString string `json:"job_url_template,omitempty"`
	// JobURLTemplate is compiled at load time from JobURLTemplateString. It
	// will be passed a kube.ProwJob and is used to set the URL for the
	// "Details" link on GitHub as well as the link from deck.
	JobURLTemplate *template.Template `json:"-"`

	// ReportTemplateString compiles into ReportTemplate at load time.
	ReportTemplateString string `json:"report_template,omitempty"`
	// ReportTemplate is compiled at load time from ReportTemplateString. It
	// will be passed a kube.ProwJob and can provide an optional blurb below
	// the test failures comment.
	ReportTemplate *template.Template `json:"-"`

	// MaxConcurrency is the maximum number of tests running concurrently that
	// will be allowed by the controller. 0 implies no limit.
	MaxConcurrency int `json:"max_concurrency,omitempty"`

	// MaxGoroutines is the maximum number of goroutines spawned inside the
	// controller to handle tests. Defaults to 20. Needs to be a positive
	// number.
	MaxGoroutines int `json:"max_goroutines,omitempty"`

	// AllowCancellations enables aborting presubmit jobs for commits that
	// have been superseded by newer commits in Github pull requests.
	AllowCancellations bool `json:"allow_cancellations,omitempty"`
}

Controller holds configuration applicable to all agent-specific prow controllers.

type Cookie struct {
	Secret string `json:"secret,omitempty"`
}

type Deck

type Deck struct {
	// TideUpdatePeriodString compiles into TideUpdatePeriod at load time.
	TideUpdatePeriodString string `json:"tide_update_period,omitempty"`
	// TideUpdatePeriod specifies how often Deck will fetch status from Tide. Defaults to 10s.
	TideUpdatePeriod time.Duration `json:"-"`
	// HiddenRepos is a list of orgs and/or repos that should not be displayed by Deck.
	HiddenRepos []string `json:"hidden_repos,omitempty"`
	// ExternalAgentLogs ensures external agents can expose
	// their logs in prow.
	ExternalAgentLogs []ExternalAgentLog `json:"external_agent_logs,omitempty"`
	// Branding of the frontend
	Branding *Branding `json:"branding,omitempty"`
}

Deck holds config for deck.

type ExternalAgentLog

type ExternalAgentLog struct {
	// Agent is an external prow agent that supports exposing
	// logs via deck.
	Agent string `json:"agent,omitempty"`
	// SelectorString compiles into Selector at load time.
	SelectorString string `json:"selector,omitempty"`
	// Selector can be used in prow deployments where the workload has
	// been sharded between controllers of the same agent. For more info
	// see https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
	Selector labels.Selector `json:"-"`
	// URLTemplateString compiles into URLTemplate at load time.
	URLTemplateString string `json:"url_template,omitempty"`
	// URLTemplate is compiled at load time from URLTemplateString. It
	// will be passed a kube.ProwJob and the generated URL should provide
	// logs for the ProwJob.
	URLTemplate *template.Template `json:"-"`
}

ExternalAgentLog ensures an external agent like Jenkins can expose its logs in prow.

type Gerrit

type Gerrit struct {
	// TickInterval is how often we do a sync with binded gerrit instance
	TickIntervalString string        `json:"tick_interval,omitempty"`
	TickInterval       time.Duration `json:"-"`
	// RateLimit defines how many changes to query per gerrit API call
	// default is 5
	RateLimit int `json:"ratelimit,omitempty"`
}

Gerrit is config for the gerrit controller.

type GithubOAuthConfig

type GithubOAuthConfig struct {
	ClientID         string   `json:"client_id"`
	ClientSecret     string   `json:"client_secret"`
	RedirectURL      string   `json:"redirect_url"`
	Scopes           []string `json:"scopes,omitempty"`
	FinalRedirectURL string   `json:"final_redirect_url"`

	CookieStore *sessions.CookieStore `json:"-"`
}

GithubOAuthConfig is a config for requesting users access tokens from Github API. It also has a Cookie Store that retains user credentials deriving from Github API.

func (*GithubOAuthConfig) InitGithubOAuthConfig

func (gac *GithubOAuthConfig) InitGithubOAuthConfig(cookie *sessions.CookieStore)

Initialise a GithubOAuthConfig. It creates a OAuthClient using GithubOAuth config and a Cookie Store to retain user credentials.

type JenkinsOperator

type JenkinsOperator struct {
	Controller `json:",inline"`
	// LabelSelectorString compiles into LabelSelector at load time.
	// If set, this option needs to match --label-selector used by
	// the desired jenkins-operator. This option is considered
	// invalid when provided with a single jenkins-operator config.
	//
	// For label selector syntax, see below:
	// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
	LabelSelectorString string `json:"label_selector,omitempty"`
	// LabelSelector is used so different jenkins-operator replicas
	// can use their own configuration.
	LabelSelector labels.Selector `json:"-"`
}

JenkinsOperator is config for the jenkins-operator controller.

type Org

type Org struct {
	Policy
	Repos map[string]Repo `json:"repos,omitempty"`
}

type OwnersDirBlacklist

type OwnersDirBlacklist struct {
	// Repos configures a directory blacklist per repo (or org)
	Repos map[string][]string `json:"repos"`
	// Default configures a default blacklist for repos (or orgs) not
	// specifically configured
	Default []string `json:"default"`
}

OwnersDirBlacklist is used to configure which directories to ignore when searching for OWNERS{,_ALIAS} files in a repo.

type Periodic

type Periodic struct {
	Name string `json:"name"`
	// Labels are added in prowjobs created for this job.
	Labels map[string]string `json:"labels"`
	// 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"`
	// Kubernetes pod spec.
	Spec *v1.PodSpec `json:"spec,omitempty"`
	// (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"`
	// Run these jobs after successfully running this one.
	RunAfterSuccess []Periodic `json:"run_after_success"`

	UtilityConfig
	// contains filtered or unexported fields
}

Periodic runs on a timer.

func (*Periodic) GetInterval

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

func (*Periodic) SetInterval

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

type Plank

type Plank struct {
	Controller `json:",inline"`
	// PodPendingTimeoutString compiles into PodPendingTimeout at load time.
	PodPendingTimeoutString string `json:"pod_pending_timeout,omitempty"`
	// PodPendingTimeout is after how long the controller will perform a garbage
	// collection on pending pods. Defaults to one day.
	PodPendingTimeout time.Duration `json:"-"`
	// DefaultDecorationConfig are defaults for shared fields for ProwJobs
	// that request to have their PodSpecs decorated
	DefaultDecorationConfig *kube.DecorationConfig `json:"default_decoration_config,omitempty"`
}

Plank is config for the plank controller.

type Policy

type Policy struct {
	Protect *bool `json:"protect-by-default,omitempty"`
	// TODO(fejta): add all protection options
	Contexts []string `json:"require-contexts,omitempty"`
	Pushers  []string `json:"allow-push,omitempty"`
}

func (Policy) Apply

func (parent Policy) Apply(child Policy) Policy

apply returns a policy that merges the child into the parent

type Postsubmit

type Postsubmit struct {
	Name string `json:"name"`
	// Labels are added in prowjobs created for this job.
	Labels map[string]string `json:"labels"`
	// 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"`
	// Kubernetes pod spec.
	Spec *v1.PodSpec `json:"spec,omitempty"`
	// Maximum number of this job running concurrently, 0 implies no limit.
	MaxConcurrency int `json:"max_concurrency"`

	Brancher

	UtilityConfig

	// Run these jobs after successfully running this one.
	RunAfterSuccess []Postsubmit `json:"run_after_success"`
}

Postsubmit runs on push events.

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 {
	// eg kubernetes-pull-build-test-e2e-gce
	Name string `json:"name"`
	// Labels are added in prowjobs created for this job.
	Labels map[string]string `json:"labels"`
	// Run for every PR, or only when a comment triggers it.
	AlwaysRun bool `json:"always_run"`
	// Run if the PR modifies a file that matches this regex.
	RunIfChanged string `json:"run_if_changed"`
	// Context line for GitHub status.
	Context string `json:"context"`
	// eg @k8s-bot e2e test this
	Trigger string `json:"trigger"`
	// Valid rerun command to give users. Must match Trigger.
	RerunCommand string `json:"rerun_command"`
	// Whether or not to skip commenting and setting status on GitHub.
	SkipReport bool `json:"skip_report"`
	// Maximum number of this job running concurrently, 0 implies no limit.
	MaxConcurrency int `json:"max_concurrency"`
	// 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"`
	// Kubernetes pod spec.
	Spec *v1.PodSpec `json:"spec,omitempty"`
	// Run these jobs after successfully running this one.
	RunAfterSuccess []Presubmit `json:"run_after_success"`
	// Consider job optional for branch protection.
	Optional bool `json:"optional,omitempty"`

	Brancher

	UtilityConfig
	// contains filtered or unexported fields
}

Presubmit is the job-specific trigger info.

func (Presubmit) RunsAgainstChanges

func (ps Presubmit) RunsAgainstChanges(changes []string) bool

func (Presubmit) TriggerMatches

func (ps Presubmit) TriggerMatches(body string) bool

type PushGateway

type PushGateway struct {
	// Endpoint is the location of the prometheus pushgateway
	// where prow will push metrics to.
	Endpoint string `json:"endpoint,omitempty"`
	// IntervalString compiles into Interval at load time.
	IntervalString string `json:"interval,omitempty"`
	// Interval specifies how often prow will push metrics
	// to the pushgateway. Defaults to 1m.
	Interval time.Duration `json:"-"`
}

PushGateway is a prometheus push gateway.

type Repo

type Repo struct {
	Policy
	Branches map[string]Branch `json:"branches,omitempty"`
}

type Sinker

type Sinker struct {
	// ResyncPeriodString compiles into ResyncPeriod at load time.
	ResyncPeriodString string `json:"resync_period,omitempty"`
	// ResyncPeriod is how often the controller will perform a garbage
	// collection. Defaults to one hour.
	ResyncPeriod time.Duration `json:"-"`
	// MaxProwJobAgeString compiles into MaxProwJobAge at load time.
	MaxProwJobAgeString string `json:"max_prowjob_age,omitempty"`
	// MaxProwJobAge is how old a ProwJob can be before it is garbage-collected.
	// Defaults to one week.
	MaxProwJobAge time.Duration `json:"-"`
	// MaxPodAgeString compiles into MaxPodAge at load time.
	MaxPodAgeString string `json:"max_pod_age,omitempty"`
	// MaxPodAge is how old a Pod can be before it is garbage-collected.
	// Defaults to one day.
	MaxPodAge time.Duration `json:"-"`
}

Sinker is config for the sinker controller.

type Tide

type Tide struct {
	// SyncPeriodString compiles into SyncPeriod at load time.
	SyncPeriodString string `json:"sync_period,omitempty"`
	// SyncPeriod specifies how often Tide will sync jobs with Github. Defaults to 1m.
	SyncPeriod time.Duration `json:"-"`
	// StatusUpdatePeriodString compiles into StatusUpdatePeriod at load time.
	StatusUpdatePeriodString string `json:"status_update_period,omitempty"`
	// StatusUpdatePeriod specifies how often Tide will update Github status contexts.
	// Defaults to the value of SyncPeriod.
	StatusUpdatePeriod time.Duration `json:"-"`
	// Queries must not overlap. It must be impossible for any two queries to
	// ever return the same PR.
	// TODO: This will only be possible when we allow specifying orgs. At that
	//       point, verify the above condition.
	Queries TideQueries `json:"queries,omitempty"`

	// A key/value pair of an org/repo as the key and merge method to override
	// the default method of merge. Valid options are squash, rebase, and merge.
	MergeType map[string]github.PullRequestMergeType `json:"merge_method,omitempty"`

	// URL for tide status contexts.
	// We can consider allowing this to be set separately for separate repos, or
	// allowing it to be a template.
	TargetURL string `json:"target_url,omitempty"`

	// PRStatusBaseUrl is the base URL for the PR status page.
	// This is used to link to a merge requirements overview
	// in the tide status context.
	PRStatusBaseUrl string `json:"pr_status_base_url,omitempty"`

	// MaxGoroutines is the maximum number of goroutines spawned inside the
	// controller to handle org/repo:branch pools. Defaults to 20. Needs to be a
	// positive number.
	MaxGoroutines int `json:"max_goroutines,omitempty"`
}

Tide is config for the tide pool.

func (*Tide) MergeMethod

func (t *Tide) MergeMethod(org, repo string) github.PullRequestMergeType

MergeMethod returns the merge method to use for a repo. The default of merge is returned when not overridden.

type TideQueries

type TideQueries []TideQuery

func (TideQueries) AllPRsSince

func (tqs TideQueries) AllPRsSince(t time.Time) string

AllPRsSince returns all open PRs in the repos covered by the query that have changed since time t.

func (TideQueries) ByRepo

func (tqs TideQueries) ByRepo() map[string]TideQueries

ByRepo returns a mapping from "org/repo" -> TideQueries that apply to that repo.

type TideQuery

type TideQuery struct {
	Repos []string `json:"repos,omitempty"`

	ExcludedBranches []string `json:"excludedBranches,omitempty"`
	IncludedBranches []string `json:"includedBranches,omitempty"`

	Labels        []string `json:"labels,omitempty"`
	MissingLabels []string `json:"missingLabels,omitempty"`

	ReviewApprovedRequired bool `json:"reviewApprovedRequired,omitempty"`
}

TideQuery is turned into a GitHub search query. See the docs for details: https://help.github.com/articles/searching-issues-and-pull-requests/ If we choose to add orgs then be sure to update the logic for listing all PRs in the tide package.

func (*TideQuery) Query

func (tq *TideQuery) Query() string

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

	// ExtraRefs are auxiliary repositories that
	// need to be cloned, determined from config
	ExtraRefs []*kube.Refs `json:"extra_refs,omitempty"`

	// DecorationConfig holds configuration options for
	// decorating PodSpecs that users provide
	*kube.DecorationConfig
}

Jump to

Keyboard shortcuts

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