Skip to content

Commit 9106c0c

Browse files
committed
Enable possibility to use capabilities in images jobs
Make additional architectures field deprecated and prefer capabilities over additional arches in prowgen Signed-off-by: Jakub Guzik <[email protected]>
1 parent 1801518 commit 9106c0c

6 files changed

+108
-6
lines changed

pkg/api/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,6 +2584,10 @@ type ProjectDirectoryImageBuildStepConfiguration struct {
25842584
// Ref is an optional string linking to the extra_ref in "org.repo" format that this belongs to
25852585
Ref string `json:"ref,omitempty"`
25862586

2587+
// Capabilities is the list of strings that
2588+
// define additional capabilities needed by the test runs
2589+
Capabilities []string `json:"capabilities,omitempty"`
2590+
25872591
// isBundleImage indicates that this build step is a bundle image
25882592
isBundleImage bool
25892593
}

pkg/prowgen/prowgen.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ func GenerateJobs(configSpec *cioperatorapi.ReleaseBuildConfiguration, info *Pro
129129
}
130130
imagesTestName := "images"
131131
jobBaseGen := newJobBaseBuilder().TestName(imagesTestName)
132-
injectArchitectureLabels(jobBaseGen, configSpec.Images)
132+
injectCapabilitiesForImgJobs(jobBaseGen, configSpec.Images)
133133

134134
jobBaseGen.PodSpec.Add(Targets(presubmitTargets...))
135135
presubmits[orgrepo] = append(presubmits[orgrepo], *generatePresubmitForTest(jobBaseGen, imagesTestName, info))
136136

137137
if configSpec.PromotionConfiguration != nil {
138138
jobBaseGen = newJobBaseBuilder().TestName(imagesTestName)
139-
injectArchitectureLabels(jobBaseGen, configSpec.Images)
139+
injectCapabilitiesForImgJobs(jobBaseGen, configSpec.Images)
140140

141141
jobBaseGen.PodSpec.Add(Promotion(), Targets(imageTargets.UnsortedList()...))
142142
if slackReporter := info.Config.GetSlackReporterConfigForTest(imagesTestName, configSpec.Metadata.Variant); slackReporter != nil {
@@ -398,10 +398,22 @@ func injectCapabilities(labels map[string]string, capabilities []string) {
398398
}
399399
}
400400

401-
func injectArchitectureLabels(g *prowJobBaseBuilder, imagesConfig []cioperatorapi.ProjectDirectoryImageBuildStepConfiguration) {
402-
for _, imageConfig := range imagesConfig {
403-
for _, arch := range imageConfig.AdditionalArchitectures {
404-
g.WithLabel(fmt.Sprintf("capability/%s", arch), arch)
401+
// injectCapabilitiesForImgJobs injects capabilities for image build jobs
402+
// If the image build job has capabilities, it will use them and skip architecture labels
403+
// If the image build job does not have capabilities, it will use architecture labels
404+
func injectCapabilitiesForImgJobs(g *prowJobBaseBuilder, imagesConfig []cioperatorapi.ProjectDirectoryImageBuildStepConfiguration) {
405+
var labels []string
406+
for _, img := range imagesConfig {
407+
labels = append(labels, img.Capabilities...)
408+
}
409+
410+
if len(labels) == 0 {
411+
for _, img := range imagesConfig {
412+
labels = append(labels, img.AdditionalArchitectures...)
405413
}
406414
}
415+
416+
for _, lbl := range labels {
417+
g.WithLabel(fmt.Sprintf("capability/%s", lbl), lbl)
418+
}
407419
}

pkg/prowgen/prowgen_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,52 @@ func TestGenerateJobs(t *testing.T) {
678678
},
679679
},
680680
},
681+
{
682+
id: "multiarch postsubmit images, using capabilities",
683+
config: &ciop.ReleaseBuildConfiguration{
684+
Images: []ciop.ProjectDirectoryImageBuildStepConfiguration{
685+
{
686+
From: "os",
687+
To: "ci-tools",
688+
Capabilities: []string{"arm64"},
689+
},
690+
{
691+
From: "os",
692+
To: "test",
693+
Capabilities: []string{"arm64", "ppc64-le"},
694+
},
695+
},
696+
PromotionConfiguration: &ciop.PromotionConfiguration{},
697+
},
698+
repoInfo: &ProwgenInfo{
699+
Metadata: ciop.Metadata{
700+
Org: "organization",
701+
Repo: "repository",
702+
Branch: "branch",
703+
},
704+
},
705+
},
706+
{
707+
id: "prefer capabilities over architecture labels",
708+
config: &ciop.ReleaseBuildConfiguration{
709+
Images: []ciop.ProjectDirectoryImageBuildStepConfiguration{
710+
{
711+
From: "os",
712+
To: "ci-tools",
713+
Capabilities: []string{"arm64"},
714+
AdditionalArchitectures: []string{"ppc64-le"},
715+
},
716+
},
717+
PromotionConfiguration: &ciop.PromotionConfiguration{},
718+
},
719+
repoInfo: &ProwgenInfo{
720+
Metadata: ciop.Metadata{
721+
Org: "organization",
722+
Repo: "repository",
723+
Branch: "branch",
724+
},
725+
},
726+
},
681727
{
682728
id: "multiarch test job",
683729
config: &ciop.ReleaseBuildConfiguration{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
postsubmits:
2+
organization/repository:
3+
- always_run: true
4+
labels:
5+
capability/arm64: arm64
6+
capability/ppc64-le: ppc64-le
7+
ci-operator.openshift.io/is-promotion: "true"
8+
max_concurrency: 1
9+
name: branch-ci-organization-repository-branch-images
10+
presubmits:
11+
organization/repository:
12+
- always_run: false
13+
labels:
14+
capability/arm64: arm64
15+
capability/ppc64-le: ppc64-le
16+
pj-rehearse.openshift.io/can-be-rehearsed: "true"
17+
name: pull-ci-organization-repository-branch-images
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
postsubmits:
2+
organization/repository:
3+
- always_run: true
4+
labels:
5+
capability/arm64: arm64
6+
ci-operator.openshift.io/is-promotion: "true"
7+
max_concurrency: 1
8+
name: branch-ci-organization-repository-branch-images
9+
presubmits:
10+
organization/repository:
11+
- always_run: false
12+
labels:
13+
capability/arm64: arm64
14+
pj-rehearse.openshift.io/can-be-rehearsed: "true"
15+
name: pull-ci-organization-repository-branch-images

pkg/webreg/zz_generated.ci_operator_reference.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ const ciOperatorReferenceYaml = "# The list of base images describe\n" +
190190
" name: ' '\n" +
191191
" # Value of the build arg.\n" +
192192
" value: ' '\n" +
193+
" # Capabilities is the list of strings that\n" +
194+
" # define additional capabilities needed by the test runs\n" +
195+
" capabilities:\n" +
196+
" - \"\"\n" +
193197
" # ContextDir is the directory in the project\n" +
194198
" # from which this build should be run.\n" +
195199
" context_dir: ' '\n" +
@@ -428,6 +432,10 @@ const ciOperatorReferenceYaml = "# The list of base images describe\n" +
428432
" name: ' '\n" +
429433
" # Value of the build arg.\n" +
430434
" value: ' '\n" +
435+
" # Capabilities is the list of strings that\n" +
436+
" # define additional capabilities needed by the test runs\n" +
437+
" capabilities:\n" +
438+
" - \"\"\n" +
431439
" # ContextDir is the directory in the project\n" +
432440
" # from which this build should be run.\n" +
433441
" context_dir: ' '\n" +

0 commit comments

Comments
 (0)