Skip to content

Commit

Permalink
bundles should still be sorted by deprecation even when package is de…
Browse files Browse the repository at this point in the history
…precated

Signed-off-by: everettraven <everettraven@gmail.com>
  • Loading branch information
everettraven committed Jan 15, 2024
1 parent 6f651c7 commit 6fdc060
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
29 changes: 29 additions & 0 deletions internal/catalogmetadata/sort/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,33 @@ func TestByDeprecated(t *testing.T) {
require.Len(t, toSort, 2)
assert.Equal(t, b2, toSort[0])
assert.Equal(t, b1, toSort[1])

b1.Deprecations = []declcfg.DeprecationEntry{
{
Reference: declcfg.PackageScopedReference{
Schema: "olm.package",
},
},
}
b2.Deprecations = append(b2.Deprecations, declcfg.DeprecationEntry{
Reference: declcfg.PackageScopedReference{
Schema: "olm.package",
},
}, declcfg.DeprecationEntry{
Reference: declcfg.PackageScopedReference{
Schema: "olm.bundle",
Name: "baz",
},
})

toSort = []*catalogmetadata.Bundle{b2, b1}
sort.SliceStable(toSort, func(i, j int) bool {
return catalogsort.ByDeprecated(toSort[i], toSort[j])
})
// Both are deprecated at package level, b2 is deprecated
// explicitly, b2 should be preferred less
require.Len(t, toSort, 2)
assert.Equal(t, b1, toSort[0])
assert.Equal(t, b2, toSort[1])

Check failure on line 162 in internal/catalogmetadata/sort/sort_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
}
10 changes: 0 additions & 10 deletions internal/catalogmetadata/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,6 @@ func (b *Bundle) HasDeprecation() bool {
// are deprecated and there should be no special treatment
func (b *Bundle) IsDeprecated() bool {
for _, dep := range b.Deprecations {
// references with the olm.package schema don't specify a name
// so we assume it is correctly associated with this bundle.
// We return false here so no special considerations are taken
// regarding deprecation status when the entire package is deprecated.
// Resolution when the package is deprecated is equivalent
// to resolution when nothing is deprecated
if dep.Reference.Schema == declcfg.SchemaPackage {
return false
}

if dep.Reference.Schema == declcfg.SchemaBundle && dep.Reference.Name == b.Name {
return true
}
Expand Down

0 comments on commit 6fdc060

Please sign in to comment.