dispatcher

package
v0.0.0-...-0f279ed Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetermineCloud

func DetermineCloud(jobBase prowconfig.JobBase) string

DetermineCloud determines which cloud this job should run. It returns the value of ci-operator.openshift.io/cloud if it is none empty. The label is set by prow-gen for multistage tests. For template tests and hand-crafted tests, it returns the value of env. var. CLUSTER_TYPE from the job's spec.

func DetermineTargetCluster

func DetermineTargetCluster(cluster, determinedCluster, defaultCluster string, canBeRelocated bool, blocked sets.Set[string]) string

func FindMostUsedCluster

func FindMostUsedCluster(jc *prowconfig.JobConfig) string

func GetJobVolumesFromPrometheus

func GetJobVolumesFromPrometheus(ctx context.Context, prometheusAPI PrometheusAPI, ts time.Time) (map[string]float64, error)

GetJobVolumesFromPrometheus gets job volumes from a Prometheus server for the given time

func HasCapacityOrCapabilitiesChanged

func HasCapacityOrCapabilitiesChanged(prev, next ClusterMap) bool

func ReadGob

func ReadGob(filename string, data interface{}) error

func SaveConfig

func SaveConfig(config *Config, configPath string) error

SaveConfig saves config to a file

func WriteGob

func WriteGob(filename string, data interface{}) error

Types

type BuildFarmConfig

type BuildFarmConfig struct {
	FilenamesRaw []string         `json:"filenames,omitempty"`
	Filenames    sets.Set[string] `json:"-"`
}

type Client

type Client interface {
	ClusterForJob(jobName string) (string, error)
}

func NewClient

func NewClient(address string) Client

type ClusterInfo

type ClusterInfo struct {
	Provider     string
	Capacity     int
	Capabilities []string
}

ClusterInfo holds the provider, capacity, and capabilities.

type ClusterMap

type ClusterMap map[string]ClusterInfo

ClusterMap maps a cluster name to its corresponding ClusterInfo.

func LoadClusterConfig

func LoadClusterConfig(filePath string) (ClusterMap, sets.Set[string], error)

LoadClusterConfig loads cluster configuration from a YAML file, returning a ClusterMap and a set of blocked clusters.

type Config

type Config struct {
	// the job will be run on the same cloud as the one for the e2e test
	DetermineE2EByJob bool `json:"determineE2EByJob,omitempty"`
	// the job will be run on the target cloud if it otherwise runs on the source cloud.
	// The field has effect only when DetermineE2EByJob is true.
	CloudMapping map[api.Cloud]api.Cloud `json:"cloudMapping,omitempty"`
	// the cluster cluster name if no other condition matches
	Default api.Cluster `json:"default"`
	// the cluster name for ssh bastion jobs
	SSHBastion api.Cluster `json:"sshBastion"`
	// the cluster names for kvm jobs
	KVM []api.Cluster `json:"kvm"`
	// the cluster names for no-builds jobs
	NoBuilds []api.Cluster `json:"noBuilds,omitempty"`
	// Groups maps a group of jobs to a cluster
	Groups JobGroups `json:"groups"`
	// BuildFarm maps groups of jobs to a cloud provider, like GCP
	BuildFarm map[api.Cloud]map[api.Cluster]*BuildFarmConfig `json:"buildFarm,omitempty"`
	// BuildFarmCloud maps sets of clusters to a cloud provider, like GCP
	BuildFarmCloud map[api.Cloud][]string `json:"-"`
}

Config is the configuration file of this tools, which defines the cluster parameter for each Prow job, i.e., where it runs

func LoadConfig

func LoadConfig(configPath string) (*Config, error)

LoadConfig loads config from a file

func (*Config) DetermineCloudMapping

func (config *Config) DetermineCloudMapping(jobBase prowconfig.JobBase) string

DetermineCloudMapping determines if for a given cloud there is a replacement to map, eg for cost saving reasons

func (*Config) DetermineClusterForJob

func (config *Config) DetermineClusterForJob(jobBase prowconfig.JobBase, path string, cm ClusterMap) (clusterName api.Cluster, mayBeRelocated bool, _ error)

DetermineClusterForJob return the cluster for a prow job and if it can be relocated to a cluster in build farm

func (*Config) GetBuildFarmSize

func (config *Config) GetBuildFarmSize() int

GetBuildFarmSize returns build farm size

func (*Config) GetClusterForJob

func (config *Config) GetClusterForJob(jobBase prowconfig.JobBase, path string, cm ClusterMap) (api.Cluster, error)

GetClusterForJob returns a cluster for a prow job

func (*Config) IsInBuildFarm

func (config *Config) IsInBuildFarm(clusterName api.Cluster) api.Cloud

IsInBuildFarm returns the cloudProvider if the cluster is in the build farm; empty string otherwise.

func (*Config) MatchingPathRegEx

func (config *Config) MatchingPathRegEx(path string) bool

MatchingPathRegEx returns true if the given path matches a path regular expression defined in a config's group

func (*Config) Validate

func (config *Config) Validate() error

Validate checks if the config is valid

type Group

type Group struct {
	// a list of job names
	Jobs []string `json:"jobs,omitempty"`
	// a list of regexes of the file paths
	Paths []string `json:"paths,omitempty"`

	PathREs []*regexp.Regexp `json:"-"`
}

Group is a group of jobs

type JobGroups

type JobGroups = map[api.Cluster]Group

JobGroups maps a group of jobs to a cluster

type PrometheusAPI

type PrometheusAPI interface {
	// Query performs a query for the given time.
	Query(ctx context.Context, query string, ts time.Time, opts ...prometheusapi.Option) (model.Value, prometheusapi.Warnings, error)
}

PrometheusAPI defines what we expect Prometheus to do in the package

type PrometheusOptions

type PrometheusOptions struct {
	PrometheusURL             string
	PrometheusUsername        string
	PrometheusPasswordPath    string
	PrometheusBearerTokenPath string
}

PrometheusOptions exposes options used in contacting a Prometheus instance

func (*PrometheusOptions) AddFlags

func (o *PrometheusOptions) AddFlags(fs *flag.FlagSet)

AddFlags sets up the flags for PrometheusOptions

func (*PrometheusOptions) NewPrometheusClient

func (o *PrometheusOptions) NewPrometheusClient(secretGetter func(string) []byte) (api.Client, error)

NewPrometheusClient return a Prometheus client

func (*PrometheusOptions) Validate

func (o *PrometheusOptions) Validate() error

Validate validates the values in the options

type Prowjobs

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

func NewProwjobs

func NewProwjobs(jobsStoragePath string) *Prowjobs

func (*Prowjobs) Get

func (pjs *Prowjobs) Get(pj string) string

func (*Prowjobs) GetDataCopy

func (pjs *Prowjobs) GetDataCopy() map[string]string

func (*Prowjobs) HasAnyOfClusters

func (pjs *Prowjobs) HasAnyOfClusters(clusters sets.Set[string]) bool

func (*Prowjobs) Regenerate

func (pjs *Prowjobs) Regenerate(prowjobs map[string]string)

type SchedulingRequest

type SchedulingRequest struct {
	Job string `json:"job"`
}

SchedulingRequest represents the incoming request structure

type SchedulingResponse

type SchedulingResponse struct {
	Cluster string `json:"cluster"`
}

Response represents the response structure

type Server

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

func NewServer

func NewServer(jobs *Prowjobs, dispatch func(bool)) *Server

func (*Server) EventHandler

func (s *Server) EventHandler(w http.ResponseWriter, r *http.Request)

EventHandler handles the /event route with dispatch logic

func (*Server) RequestHandler

func (s *Server) RequestHandler(w http.ResponseWriter, r *http.Request)

RequestHandler handles scheduling requests for jobs

Jump to

Keyboard shortcuts

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