Skip to content

ci-operator: Use * to exclude images from promotion #4588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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: 2 additions & 0 deletions pkg/api/promotion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (

PromotionStepName = "promotion"
PromotionQuayStepName = "promotion-quay"

PromotionExcludeImageWildcard = "*"
)

// PromotionTargets adapts the single-target configuration to the multi-target paradigm.
Expand Down
7 changes: 4 additions & 3 deletions pkg/promotion/promotion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/prow/pkg/flagutil"

"github.com/openshift/ci-tools/pkg/api"
cioperatorapi "github.com/openshift/ci-tools/pkg/api"
"github.com/openshift/ci-tools/pkg/config"
)
Expand Down Expand Up @@ -39,13 +40,13 @@ func AllPromotionImageStreamTags(configSpec *cioperatorapi.ReleaseBuildConfigura
continue
}

disabled := sets.New[string](target.ExcludedImages...)
if !disabled.Has("*") {
disabled := sets.New(target.ExcludedImages...)
if !disabled.Has(api.PromotionExcludeImageWildcard) {
for _, image := range configSpec.Images {
result.Insert(fmt.Sprintf("%s/%s:%s", target.Namespace, target.Name, image.To))
}
}
for _, image := range disabled.Delete("*").UnsortedList() {
for _, image := range disabled.Delete(api.PromotionExcludeImageWildcard).UnsortedList() {
delete(result, image)
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/steps/release/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,17 @@ func toPromote(config api.PromotionTarget, images []api.ProjectDirectoryImageBui
names.Insert(tag)
}
}

for _, tag := range config.ExcludedImages {
if tag == api.PromotionExcludeImageWildcard {
clear(tagsByDst)
names.Clear()
break
}
delete(tagsByDst, tag)
names.Delete(tag)
}

for dst, src := range config.AdditionalImages {
tagsByDst[dst] = src
names.Insert(dst)
Expand Down
62 changes: 62 additions & 0 deletions pkg/steps/release/promote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,68 @@ func TestPromotedTagsWithRequiredImages(t *testing.T) {
},
expectedRequiredImages: sets.New[string]("base", "base-7", "base-8", "other"),
},
{
name: "promotion only cli-ocm to ci",
input: &api.ReleaseBuildConfiguration{
Images: []api.ProjectDirectoryImageBuildStepConfiguration{
{
From: "cli",
To: "cli-ocm",
},
{
From: "src",
To: "cli",
},
},
PromotionConfiguration: &api.PromotionConfiguration{
Targets: []api.PromotionTarget{
{
ExcludedImages: []string{api.PromotionExcludeImageWildcard},
Namespace: "ci",
Name: "cli-ocm",
AdditionalImages: map[string]string{
"latest": "cli-ocm",
},
},
{
Namespace: "ocp",
Name: "4.20",
},
},
},
Metadata: api.Metadata{
Org: "openshift",
Repo: "oc",
Branch: "master",
},
},
expected: map[string][]api.ImageStreamTagReference{
"cli-ocm": {
{Namespace: "ci", Name: "cli-ocm", Tag: "latest"},
{Namespace: "ocp", Name: "4.20", Tag: "cli-ocm"},
},
"cli": {
{Namespace: "ocp", Name: "4.20", Tag: "cli"},
},
},
expectedRequiredImages: sets.New("latest", "cli-ocm", "cli"),
},
{
name: "exclude everything",
input: &api.ReleaseBuildConfiguration{
Images: []api.ProjectDirectoryImageBuildStepConfiguration{
{To: "img_a"},
{To: "img_b"},
},
PromotionConfiguration: &api.PromotionConfiguration{
Targets: []api.PromotionTarget{{
ExcludedImages: []string{api.PromotionExcludeImageWildcard},
}},
},
},
expected: map[string][]api.ImageStreamTagReference{},
expectedRequiredImages: sets.New[string](),
},
}

for _, testCase := range testCases {
Expand Down