Skip to content
Merged
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
2 changes: 0 additions & 2 deletions config/serverless-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ repositories:
FIREWATCH_DEFAULT_JIRA_ASSIGNEE: maschmid@redhat.com
FIREWATCH_DEFAULT_JIRA_PROJECT: SRVCOM
OCP_VERSION: "4.22"
REPORT_TO_DR: "true"
REPORTPORTAL_CMP: Serverless-lp-interop
USER_TAGS: |
scenario serverless
Expand Down Expand Up @@ -486,7 +485,6 @@ repositories:
FIREWATCH_DEFAULT_JIRA_ASSIGNEE: maschmid@redhat.com
FIREWATCH_DEFAULT_JIRA_PROJECT: SRVCOM
OCP_VERSION: "4.22"
REPORT_TO_DR: "true"
REPORTPORTAL_CMP: Serverless-lp-interop
USER_TAGS: |
scenario serverless
Expand Down
132 changes: 56 additions & 76 deletions pkg/prowgen/prowgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ import (

"github.com/openshift-knative/hack/pkg/util"
"github.com/openshift/ci-tools/pkg/api/shardprowconfig"
ciconfig "github.com/openshift/ci-tools/pkg/config"
"sigs.k8s.io/yaml"

"github.com/coreos/go-semver/semver"
"golang.org/x/sync/errgroup"
prowapi "sigs.k8s.io/prow/pkg/apis/prowjobs/v1"
)

// Config is the prowgen configuration file struct.
Expand Down Expand Up @@ -149,11 +147,6 @@ func Main() {
return err
}

prowgenCfg := NewProwgenConfig(repository, inConfig.Config, cfgs)
if err := SaveProwgenConfig(outConfig, repository, prowgenCfg); err != nil {
return err
}

return nil
})
}
Expand Down Expand Up @@ -299,100 +292,81 @@ func SaveProwConfig(openShiftRelease Repository, repository Repository, config s

const slackReportTemplate = `{{if eq .Status.State "success"}} :rainbow: Job *{{.Spec.Job}}* ended with *{{.Status.State}}*. <{{.Status.URL}}|View logs> :rainbow: {{else}} :volcano: Job *{{.Spec.Job}}* ended with *{{.Status.State}}*. <{{.Status.URL}}|View logs> :volcano: {{end}}`

func NewProwgenConfig(r Repository, cc CommonConfig, cfgs []ReleaseBuildConfiguration) *ciconfig.Prowgen {
if r.SlackChannel == "" {
return nil
}

jobNameSet := make(map[string]struct{})
for _, cfg := range cfgs {
for _, test := range cfg.Tests {
if test.Cron != nil {
jobNameSet[test.As] = struct{}{}
}
}
}
func SaveReleaseBuildConfiguration(outConfig *string, cfg ReleaseBuildConfiguration) error {
dir := filepath.Join(*outConfig, filepath.Dir(cfg.Path))

if len(jobNameSet) == 0 {
return nil
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return err
}

jobNames := make([]string, 0, len(jobNameSet))
for name := range jobNameSet {
jobNames = append(jobNames, name)
out, err := yaml.Marshal(cfg.ReleaseBuildConfiguration)
if err != nil {
return err
}
sort.Strings(jobNames)

variantSet := make(map[string]struct{})
for _, branch := range cc.Branches {
if branch.Prowgen != nil && branch.Prowgen.Disabled {
continue
}
for _, ov := range branch.OpenShiftVersions {
if ov.SkipCron || ov.CandidateRelease {
variant := strings.ReplaceAll(ov.Version, ".", "")
variantSet[variant] = struct{}{}
}
if cfg.SlackChannel != "" {
out, err = addReporterConfigToTests(out, cfg.SlackChannel)
if err != nil {
return err
}
}

var excludedVariants []string
if len(variantSet) > 0 {
excludedVariants = make([]string, 0, len(variantSet))
for v := range variantSet {
excludedVariants = append(excludedVariants, v)
}
sort.Strings(excludedVariants)
if err := os.WriteFile(filepath.Join(*outConfig, cfg.Path), out, os.ModePerm); err != nil {
return err
}

return &ciconfig.Prowgen{
SlackReporterConfigs: []ciconfig.SlackReporterConfig{
{
Channel: r.SlackChannel,
JobStatesToReport: []prowapi.ProwJobState{prowapi.SuccessState, prowapi.FailureState, prowapi.ErrorState},
ReportTemplate: slackReportTemplate,
JobNames: jobNames,
ExcludedVariants: excludedVariants,
},
},
}
return copyOwnersFileIfNotPresent(dir)
}

func SaveProwgenConfig(outConfig *string, r Repository, prowgenCfg *ciconfig.Prowgen) error {
if prowgenCfg == nil {
return nil
// addReporterConfigToTests injects a reporter_config stanza into every test that
// has a cron field, so Slack notifications are configured directly in the
// ci-operator config yaml instead of via a separate .config.prowgen file.
func addReporterConfigToTests(out []byte, slackChannel string) ([]byte, error) {
var rawConfig interface{}
if err := yaml.Unmarshal(out, &rawConfig); err != nil {
return nil, err
}

dir := filepath.Join(*outConfig, r.RepositoryDirectory())
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return err
configMap, ok := rawConfig.(map[string]interface{})
if !ok {
return out, nil
}

out, err := yaml.Marshal(prowgenCfg)
if err != nil {
return err
testsRaw, ok := configMap["tests"]
if !ok {
return out, nil
}

return os.WriteFile(filepath.Join(dir, ciconfig.ProwgenFile), out, os.ModePerm)
}

func SaveReleaseBuildConfiguration(outConfig *string, cfg ReleaseBuildConfiguration) error {
dir := filepath.Join(*outConfig, filepath.Dir(cfg.Path))
tests, ok := testsRaw.([]interface{})
if !ok {
return out, nil
}

if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return err
reporterConfig := map[string]interface{}{
"channel": slackChannel,
"job_states_to_report": []interface{}{"success", "failure", "error"},
"report_template": slackReportTemplate,
Comment on lines +345 to +348
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@maschmid would updating ci-tools library bring new structure with "official" support of reporters etc.?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

indeed, let's do that #969

}

out, err := yaml.Marshal(cfg.ReleaseBuildConfiguration)
if err != nil {
return err
modified := false
for i, testRaw := range tests {
test, ok := testRaw.(map[string]interface{})
if !ok {
continue
}
if _, hasCron := test["cron"]; hasCron {
test["reporter_config"] = reporterConfig
tests[i] = test
modified = true
}
}

if err := os.WriteFile(filepath.Join(*outConfig, cfg.Path), out, os.ModePerm); err != nil {
return err
if !modified {
return out, nil
}

return copyOwnersFileIfNotPresent(dir)
configMap["tests"] = tests
return yaml.Marshal(rawConfig)
}

func copyOwnersFileIfNotPresent(dir string) error {
Expand Down Expand Up @@ -434,6 +408,12 @@ func InitializeOpenShiftReleaseRepository(ctx context.Context, openShiftRelease
for _, r := range inConfig.Repositories {
// TODO: skip automatic deletion for S-O for now
if strings.Contains(r.RepositoryDirectory(), "serverless-operator") {
// Delete .config.prowgen if it exists; the branch-based glob below won't catch it.
prowgenConfigPath := filepath.Join(*outputConfig, r.RepositoryDirectory(), ".config.prowgen")
if err := os.Remove(prowgenConfigPath); err != nil && !os.IsNotExist(err) {
return err
}

for branch, branchConfig := range inConfig.Config.Branches {
if branchConfig.Prowgen != nil && branchConfig.Prowgen.Disabled {
continue
Expand Down
7 changes: 5 additions & 2 deletions pkg/prowgen/prowgen_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ type ProjectDirectoryImageBuildStepConfigurationFunc func() (cioperatorapi.Proje
type ReleaseBuildConfiguration struct {
cioperatorapi.ReleaseBuildConfiguration

Path string
Branch string
Path string
Branch string
SlackChannel string
}

func NewGenerateConfigs(ctx context.Context, r Repository, cc CommonConfig, opts ...ReleaseBuildConfigurationOption) ([]ReleaseBuildConfiguration, error) {
Expand Down Expand Up @@ -326,6 +327,7 @@ func NewGenerateConfigs(ctx context.Context, r Repository, cc CommonConfig, opts
ReleaseBuildConfiguration: cfg,
Path: buildConfigPath,
Branch: branchName,
SlackChannel: r.SlackChannel,
})

if ov.CustomConfigs == nil || !ov.CustomConfigs.Enabled {
Expand Down Expand Up @@ -392,6 +394,7 @@ func NewGenerateConfigs(ctx context.Context, r Repository, cc CommonConfig, opts
ReleaseBuildConfiguration: *customBuildCfg,
Path: buildConfigPath,
Branch: branchName,
SlackChannel: r.SlackChannel,
})
}
}
Expand Down
Loading
Loading