Skip to content

Commit 1d097c1

Browse files
Merge pull request #4588 from danilo-gemoli/feat/ci-operator/promotion-exclude-image-wildcard
ci-operator: Use * to exclude images from promotion
2 parents 8bf5e30 + 401b15b commit 1d097c1

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

pkg/api/promotion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const (
2020

2121
PromotionStepName = "promotion"
2222
PromotionQuayStepName = "promotion-quay"
23+
24+
PromotionExcludeImageWildcard = "*"
2325
)
2426

2527
// PromotionTargets adapts the single-target configuration to the multi-target paradigm.

pkg/promotion/promotion.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"k8s.io/apimachinery/pkg/util/sets"
99
"sigs.k8s.io/prow/pkg/flagutil"
1010

11+
"github.com/openshift/ci-tools/pkg/api"
1112
cioperatorapi "github.com/openshift/ci-tools/pkg/api"
1213
"github.com/openshift/ci-tools/pkg/config"
1314
)
@@ -39,13 +40,13 @@ func AllPromotionImageStreamTags(configSpec *cioperatorapi.ReleaseBuildConfigura
3940
continue
4041
}
4142

42-
disabled := sets.New[string](target.ExcludedImages...)
43-
if !disabled.Has("*") {
43+
disabled := sets.New(target.ExcludedImages...)
44+
if !disabled.Has(api.PromotionExcludeImageWildcard) {
4445
for _, image := range configSpec.Images {
4546
result.Insert(fmt.Sprintf("%s/%s:%s", target.Namespace, target.Name, image.To))
4647
}
4748
}
48-
for _, image := range disabled.Delete("*").UnsortedList() {
49+
for _, image := range disabled.Delete(api.PromotionExcludeImageWildcard).UnsortedList() {
4950
delete(result, image)
5051
}
5152

pkg/steps/release/promote.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,17 @@ func toPromote(config api.PromotionTarget, images []api.ProjectDirectoryImageBui
323323
names.Insert(tag)
324324
}
325325
}
326+
326327
for _, tag := range config.ExcludedImages {
328+
if tag == api.PromotionExcludeImageWildcard {
329+
clear(tagsByDst)
330+
names.Clear()
331+
break
332+
}
327333
delete(tagsByDst, tag)
328334
names.Delete(tag)
329335
}
336+
330337
for dst, src := range config.AdditionalImages {
331338
tagsByDst[dst] = src
332339
names.Insert(dst)

pkg/steps/release/promote_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,68 @@ func TestPromotedTagsWithRequiredImages(t *testing.T) {
594594
},
595595
expectedRequiredImages: sets.New[string]("base", "base-7", "base-8", "other"),
596596
},
597+
{
598+
name: "promotion only cli-ocm to ci",
599+
input: &api.ReleaseBuildConfiguration{
600+
Images: []api.ProjectDirectoryImageBuildStepConfiguration{
601+
{
602+
From: "cli",
603+
To: "cli-ocm",
604+
},
605+
{
606+
From: "src",
607+
To: "cli",
608+
},
609+
},
610+
PromotionConfiguration: &api.PromotionConfiguration{
611+
Targets: []api.PromotionTarget{
612+
{
613+
ExcludedImages: []string{api.PromotionExcludeImageWildcard},
614+
Namespace: "ci",
615+
Name: "cli-ocm",
616+
AdditionalImages: map[string]string{
617+
"latest": "cli-ocm",
618+
},
619+
},
620+
{
621+
Namespace: "ocp",
622+
Name: "4.20",
623+
},
624+
},
625+
},
626+
Metadata: api.Metadata{
627+
Org: "openshift",
628+
Repo: "oc",
629+
Branch: "master",
630+
},
631+
},
632+
expected: map[string][]api.ImageStreamTagReference{
633+
"cli-ocm": {
634+
{Namespace: "ci", Name: "cli-ocm", Tag: "latest"},
635+
{Namespace: "ocp", Name: "4.20", Tag: "cli-ocm"},
636+
},
637+
"cli": {
638+
{Namespace: "ocp", Name: "4.20", Tag: "cli"},
639+
},
640+
},
641+
expectedRequiredImages: sets.New("latest", "cli-ocm", "cli"),
642+
},
643+
{
644+
name: "exclude everything",
645+
input: &api.ReleaseBuildConfiguration{
646+
Images: []api.ProjectDirectoryImageBuildStepConfiguration{
647+
{To: "img_a"},
648+
{To: "img_b"},
649+
},
650+
PromotionConfiguration: &api.PromotionConfiguration{
651+
Targets: []api.PromotionTarget{{
652+
ExcludedImages: []string{api.PromotionExcludeImageWildcard},
653+
}},
654+
},
655+
},
656+
expected: map[string][]api.ImageStreamTagReference{},
657+
expectedRequiredImages: sets.New[string](),
658+
},
597659
}
598660

599661
for _, testCase := range testCases {

0 commit comments

Comments
 (0)