Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions cmd/ci-operator-prowgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (o *options) process() error {

// generateJobsToDir generates prow job configuration into the dir provided by
// consuming ci-operator configuration.
func (o *options) generateJobsToDir(subDir string, prowConfig map[string]*config.Prowgen) error {
func (o *options) generateJobsToDir(subDir string, prowConfig map[string]*cioperatorapi.Prowgen) error {
generated := map[string]*prowconfig.JobConfig{}
genJobsFunc := generateJobs(o.resolver, prowConfig, generated)
if err := o.OperateOnCIOperatorConfigDir(filepath.Join(o.fromDir, subDir), genJobsFunc); err != nil {
Expand All @@ -120,13 +120,21 @@ func (o *options) generateJobsToDir(subDir string, prowConfig map[string]*config
return writeToDir(o.toDir, generated)
}

func generateJobs(resolver registry.Resolver, cache map[string]*config.Prowgen, output map[string]*prowconfig.JobConfig) func(configSpec *cioperatorapi.ReleaseBuildConfiguration, info *config.Info) error {
func generateJobs(resolver registry.Resolver, cache map[string]*cioperatorapi.Prowgen, output map[string]*prowconfig.JobConfig) func(configSpec *cioperatorapi.ReleaseBuildConfiguration, info *config.Info) error {
return func(configSpec *cioperatorapi.ReleaseBuildConfiguration, info *config.Info) error {
orgRepo := fmt.Sprintf("%s/%s", info.Org, info.Repo)
pInfo := &prowgen.ProwgenInfo{Metadata: info.Metadata, Config: config.Prowgen{Private: false, Expose: false}}
pInfo := &prowgen.ProwgenInfo{
Metadata: info.Metadata,
Config: cioperatorapi.ProwgenExtras{
Prowgen: cioperatorapi.Prowgen{
Private: false,
Expose: false,
},
},
}
var ok bool
var err error
var orgConfig, repoConfig *config.Prowgen
var orgConfig, repoConfig *cioperatorapi.Prowgen

if orgConfig, ok = cache[info.Org]; !ok {
if cache[info.Org], err = config.LoadProwgenConfig(info.OrgPath); err != nil {
Expand All @@ -144,13 +152,17 @@ func generateJobs(resolver registry.Resolver, cache map[string]*config.Prowgen,

switch {
case orgConfig != nil:
pInfo.Config = *orgConfig
pInfo.Config.Prowgen = *orgConfig
if repoConfig != nil {
pInfo.Config.MergeDefaults(repoConfig)
}
case repoConfig != nil:
pInfo.Config = *repoConfig
pInfo.Config.Prowgen = *repoConfig
}
if configSpec.Prowgen == nil {
configSpec.Prowgen = &cioperatorapi.ProwgenExtras{}
}
configSpec.Prowgen.Prowgen = pInfo.Config.Prowgen
if resolver != nil {
resolved, err := registry.ResolveConfig(resolver, *configSpec)
if err != nil {
Expand Down Expand Up @@ -227,7 +239,7 @@ func main() {
args = append(args, "")
}
logger := logrus.WithFields(logrus.Fields{"target": opt.toDir, "source": opt.fromDir})
config := map[string]*config.Prowgen{}
config := map[string]*cioperatorapi.Prowgen{}
for _, subDir := range args {
logger = logger.WithFields(logrus.Fields{"subdir": subDir})
if err := opt.generateJobsToDir(subDir, config); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/ci-operator-prowgen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"testing"

"github.com/openshift/ci-tools/pkg/config"
"github.com/openshift/ci-tools/pkg/api"
"github.com/openshift/ci-tools/pkg/testhelper"
)

Expand Down Expand Up @@ -293,7 +293,7 @@ tests:
}

o := options{fromDir: fullConfigPath, toDir: baseProwConfigDir}
if err := o.generateJobsToDir("", map[string]*config.Prowgen{}); err != nil {
if err := o.generateJobsToDir("", map[string]*api.Prowgen{}); err != nil {
t.Fatalf("Unexpected error generating jobs from config: %v", err)
}

Expand Down
120 changes: 120 additions & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package api

import (
"fmt"
"regexp"
"slices"
"strings"

"k8s.io/apimachinery/pkg/util/sets"
Expand All @@ -24,6 +26,116 @@ func IsPromotionJob(jobLabels map[string]string) bool {
return ok
}

// ProwgenExtras holds fields that control Prow job generation behavior.
// TODO: After migration, remove the Prowgen embedding.
type ProwgenExtras struct {
Prowgen `json:"-"`

// DisableRehearsals prevents all tests in config from being rehearsed.
DisableRehearsals *bool `json:"disable_rehearsals,omitempty"`
}

func (p *ProwgenExtras) AreRehearsalsDisabled() bool {
if p.DisableRehearsals != nil {
return *p.DisableRehearsals
}
return p.Rehearsals.DisableAll
}

func (p *ProwgenExtras) IsRehearsalDisabledForTest(config *ReleaseBuildConfiguration, testName string) bool {
if p.AreRehearsalsDisabled() {
return true
}

for _, test := range config.Tests {
if test.As == testName {
if test.DisableRehearsal != nil {
return *test.DisableRehearsal
}
}
}

return slices.Contains(p.Rehearsals.DisabledRehearsals, testName)
}

// Prowgen holds the configuration from a .config.prowgen file.
type Prowgen struct {
Private bool `json:"private,omitempty"`
Expose bool `json:"expose,omitempty"`
Rehearsals Rehearsals `json:"rehearsals,omitempty"`
SlackReporterConfigs []SlackReporterConfig `json:"slack_reporter,omitempty"`
SkipOperatorPresubmits []SkipOperatorPresubmit `json:"skip_operator_presubmits,omitempty"`
EnableSecretsStoreCSIDriver bool `json:"enable_secrets_store_csi_driver,omitempty"`
}

type Rehearsals struct {
DisableAll bool `json:"disable_all,omitempty"`
DisabledRehearsals []string `json:"disabled_rehearsals,omitempty"`
}

type SlackReporterConfig struct {
Channel string `json:"channel,omitempty"`
JobStatesToReport []prowv1.ProwJobState `json:"job_states_to_report,omitempty"`
ReportTemplate string `json:"report_template,omitempty"`
JobNames []string `json:"job_names,omitempty"`
JobNamePatterns []string `json:"job_name_patterns,omitempty"`
ExcludedVariants []string `json:"excluded_variants,omitempty"`
ExcludedJobPatterns []string `json:"excluded_job_patterns,omitempty"`
}

type SkipOperatorPresubmit struct {
Branch string `json:"branch,omitempty"`
Variant string `json:"variant,omitempty"`
}

func (p *Prowgen) MergeDefaults(defaults *Prowgen) {
if defaults.Private {
p.Private = true
}
if defaults.Expose {
p.Expose = true
}
if defaults.EnableSecretsStoreCSIDriver {
p.EnableSecretsStoreCSIDriver = true
}
if defaults.Rehearsals.DisableAll {
p.Rehearsals.DisableAll = true
}
p.Rehearsals.DisabledRehearsals = append(p.Rehearsals.DisabledRehearsals, defaults.Rehearsals.DisabledRehearsals...)
}

func (p *Prowgen) GetSlackReporterConfigForJobName(fullJobName, testName, variant string) *SlackReporterConfig {
nextSlackReporterConfig:
for _, s := range p.SlackReporterConfigs {
if slices.Contains(s.ExcludedVariants, variant) {
continue
}
for _, excludePattern := range s.ExcludedJobPatterns {
if matched, err := regexp.MatchString(excludePattern, fullJobName); err == nil && matched {
continue nextSlackReporterConfig
}
}
if slices.Contains(s.JobNames, testName) {
return &s
}
for _, pattern := range s.JobNamePatterns {
if matched, err := regexp.MatchString(pattern, testName); err == nil && matched {
return &s
}
}
}
return nil
}

func (p *Prowgen) SkipPresubmits(branch string, variant string) bool {
for _, skip := range p.SkipOperatorPresubmits {
if skip.Branch == branch && skip.Variant == variant {
return true
}
}
return false
}

// ReleaseBuildConfiguration describes how release
// artifacts are built from a repository of source
// code. The configuration is made up of two parts:
Expand All @@ -39,6 +151,9 @@ type ReleaseBuildConfiguration struct {

InputConfiguration `json:",inline"`

// Prowgen holds fields that control Prow job generation behavior.
Prowgen *ProwgenExtras `json:"prowgen,omitempty"`

// BinaryBuildCommands will create a "bin" image based on "src" that
// contains the output of this command. This allows reuse of binary artifacts
// across other steps. If empty, no "bin" image will be created.
Expand Down Expand Up @@ -859,6 +974,11 @@ type TestStepConfiguration struct {
// RestrictNetworkAccess restricts network access to RedHat intranet.
RestrictNetworkAccess *bool `json:"restrict_network_access,omitempty"`

// DisableRehearsal prevents this specific test from being picked up for rehearsals.
// Note: this cannot re-enable rehearsals if they are globally disabled via
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the note here is irrelevant since you will depreciate that. Also, we need to override it. So if its globaly disabled, then enabling it here should override the global setting. So the comment is wrong too.

// prowgen.disable_rehearsals or .config.prowgen's disable_all setting.
DisableRehearsal *bool `json:"disable_rehearsal,omitempty"`

// ShardCount describes the number of jobs that should be generated as shards for this test
// Each generated job will be a duplication, but contain a suffix and the necessary SHARD_ARGS will be passed to the steps
// Only applicable to presubmits and periodics
Expand Down
30 changes: 30 additions & 0 deletions pkg/api/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading