Skip to content

Commit 1fc2413

Browse files
author
Hector Vido
committed
Respecting always_run from config file
1 parent 310734c commit 1fc2413

File tree

6 files changed

+56
-22
lines changed

6 files changed

+56
-22
lines changed

cmd/ci-operator-prowgen/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
prowgen
2+
=======
3+
4+
Prowgen is a tool that converts [ci-operator configuration](https://docs.ci.openshift.org/docs/architecture/ci-operator/)
5+
into [Prowjobs](https://docs.prow.k8s.io/docs/jobs/).
6+
7+
The objetive is to made `ci-operator configuration` the only source of truth for jobs created
8+
by **prowgen**, based on configurations inside `openshift/ci-operator/config/`, replacing any
9+
user manual modification directly on `openshift/ci-operator/jobs/`.
10+
11+
Prowgen is normally executed by `make update/make jobs` inside `openshift/release` folder.
12+
13+
Testing
14+
-------
15+
16+
`Prowgen` is hardcoded to use `GOPATH` + `src/github.com/openshift/release`, if you want to test it on your machine
17+
you can use a symbolic link ponting to your `openshift/release` clone:
18+
19+
```bash
20+
# generally GOPATH=~/go
21+
ln -s ~/cloned-repos/openshift/release ~/go/src/github.com/openshift/release
22+
```
23+
24+
Then you can execute `ci-operator-prowgen`:
25+
26+
```bash
27+
ci-operator-prowgen \
28+
--from-release-repo \
29+
--to-release-repo \
30+
--known-infra-file infra-build-farm-periodics.yaml \
31+
--known-infra-file infra-periodics.yaml \
32+
--known-infra-file infra-image-mirroring.yaml \
33+
--known-infra-file infra-periodics-origin-release-images.yaml
34+
```

cmd/ci-operator-prowgen/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ func writeToDir(dir string, c map[string]*prowconfig.JobConfig) error {
195195
errCh := make(chan error)
196196
map_ := func() error {
197197
for x := range ch {
198-
i := strings.Index(x.k, "/")
199-
org, repo := x.k[:i], x.k[i+1:]
198+
i := strings.Split(x.k, "/")
199+
org, repo := i[0], i[1]
200200
if err := jc.WriteToDir(dir, org, repo, x.v, prowgen.Generator, nil); err != nil {
201201
errCh <- err
202202
}

pkg/jobconfig/files.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func WriteToDir(jobDir, org, repo string, jobConfig *prowconfig.JobConfig, gener
365365
return nil
366366
}
367367

368-
// Given two JobConfig, merge jobs from the `source` one to to `destination`
368+
// Given two JobConfig, merge jobs from the `source` one to `destination`
369369
// one. Jobs are matched by name. All jobs from `source` will be present in
370370
// `destination` - if there were jobs with the same name in `destination`, they
371371
// will be updated. All jobs in `destination` that are not overwritten this
@@ -471,9 +471,6 @@ func mergeJobConfig(destination, source *prowconfig.JobConfig, allJobs sets.Set[
471471
func mergePresubmits(old, new *prowconfig.Presubmit) prowconfig.Presubmit {
472472
merged := *new
473473

474-
merged.AlwaysRun = old.AlwaysRun
475-
merged.RunIfChanged = old.RunIfChanged
476-
merged.SkipIfOnlyChanged = old.SkipIfOnlyChanged
477474
merged.MaxConcurrency = old.MaxConcurrency
478475
merged.SkipReport = old.SkipReport
479476
merged.Cluster = func() string {
@@ -485,20 +482,23 @@ func mergePresubmits(old, new *prowconfig.Presubmit) prowconfig.Presubmit {
485482
return ""
486483
}()
487484

488-
if new.RunIfChanged != "" || new.SkipIfOnlyChanged != "" || new.Annotations["pipeline_run_if_changed"] != "" {
489-
merged.RunIfChanged = new.RunIfChanged
490-
merged.SkipIfOnlyChanged = new.SkipIfOnlyChanged
491-
merged.AlwaysRun = new.AlwaysRun
492-
}
493-
494-
// TODO(muller): Special case images jobs for now. Some repos are marking
495-
// images jobs as optional for which we do not have syntax in ci-operator (should we?).
496-
// Tolerate manual changes for these jobs for now
485+
// TODO(muller): Special case images jobs for now. Some repos are marking
486+
// images jobs as optional for which we do not have syntax in ci-operator (should we?).
487+
// Tolerate manual changes for these jobs for now
488+
// TODO(hector): Image jobs should keep considering always_run for now.
497489
if strings.HasSuffix(merged.Name, "-images") {
498490
merged.Optional = old.Optional
499491
if new.Optional {
500492
merged.Optional = new.Optional
501493
}
494+
merged.RunIfChanged = old.RunIfChanged
495+
merged.SkipIfOnlyChanged = old.SkipIfOnlyChanged
496+
merged.AlwaysRun = old.AlwaysRun
497+
if new.RunIfChanged != "" || new.SkipIfOnlyChanged != "" || new.Annotations["pipeline_run_if_changed"] != "" {
498+
merged.RunIfChanged = new.RunIfChanged
499+
merged.SkipIfOnlyChanged = new.SkipIfOnlyChanged
500+
merged.AlwaysRun = new.AlwaysRun
501+
}
502502
}
503503

504504
return merged

pkg/prowgen/prowgen.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ type generatePresubmitOptions struct {
245245
disableRehearsal bool
246246
}
247247

248+
func (opts *generatePresubmitOptions) shouldAlwaysRun() bool {
249+
return opts.runIfChanged == "" && opts.skipIfOnlyChanged == "" && !opts.defaultDisable && opts.pipelineRunIfChanged == ""
250+
}
251+
248252
type generatePresubmitOption func(options *generatePresubmitOptions)
249253

250254
func generatePresubmitForTest(jobBaseBuilder *prowJobBaseBuilder, name string, info *ProwgenInfo, options ...generatePresubmitOption) *prowconfig.Presubmit {
@@ -269,7 +273,7 @@ func generatePresubmitForTest(jobBaseBuilder *prowJobBaseBuilder, name string, i
269273
}
270274
pj := &prowconfig.Presubmit{
271275
JobBase: base,
272-
AlwaysRun: opts.runIfChanged == "" && opts.skipIfOnlyChanged == "" && !opts.defaultDisable && opts.pipelineRunIfChanged == "",
276+
AlwaysRun: opts.shouldAlwaysRun(),
273277
Brancher: prowconfig.Brancher{Branches: sets.List(sets.New[string](jc.ExactlyBranch(info.Branch), jc.FeatureBranch(info.Branch)))},
274278
Reporter: prowconfig.Reporter{
275279
Context: fmt.Sprintf("ci/prow/%s", shortName),

test/integration/ci-operator-prowgen/input/jobs/super/duper/super-duper-master-presubmits.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
presubmits:
22
super/duper:
33
- agent: kubernetes
4-
always_run: false
4+
always_run: true
55
branches:
66
- ^master$
77
- ^master-
88
context: ci/prow/images
99
decorate: true
1010
max_concurrency: 100
1111
name: pull-ci-super-duper-master-images
12-
optional: true
1312
rerun_command: /test images
14-
run_if_changed: changes
1513
skip_cloning: true
1614
skip_report: true
1715
spec:

test/integration/ci-operator-prowgen/output/jobs/super/duper/super-duper-master-presubmits.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ presubmits:
180180
secretName: result-aggregator
181181
trigger: (?m)^/test( | .* )e2e,?($|\s.*)
182182
- agent: kubernetes
183-
always_run: false
183+
always_run: true
184184
branches:
185185
- ^master$
186186
- ^master-
@@ -193,9 +193,7 @@ presubmits:
193193
pj-rehearse.openshift.io/can-be-rehearsed: "true"
194194
max_concurrency: 100
195195
name: pull-ci-super-duper-master-images
196-
optional: true
197196
rerun_command: /test images
198-
run_if_changed: changes
199197
skip_report: true
200198
spec:
201199
containers:

0 commit comments

Comments
 (0)