Skip to content

Commit

Permalink
(fix): don't consider bundle deprecated if the package is deprecated
Browse files Browse the repository at this point in the history
Signed-off-by: everettraven <everettraven@gmail.com>
  • Loading branch information
everettraven committed Jan 12, 2024
1 parent 1e6ad96 commit 6f651c7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 10 deletions.
22 changes: 14 additions & 8 deletions internal/catalogmetadata/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,23 @@ func (b *Bundle) HasDeprecation() bool {

// IsDeprecated returns true if the bundle
// has been explicitly deprecated. This can occur
// in one of two ways:
// - the olm.package the bundle belongs to has been deprecated
// - the bundle itself has been deprecated
// if the bundle itself has been deprecated.
// this function does not take into consideration
// olm.channel deprecations associated with the bundle
// as a bundle can be present in multiple channels with
// some channels being deprecated and some not.
// olm.channel or olm.package deprecations associated
// with the bundle as a bundle can be present in multiple
// channels with some channels being deprecated and some not
// Similarly if the package is deprecated then all the bundles
// are deprecated and there should be no special treatment
func (b *Bundle) IsDeprecated() bool {
for _, dep := range b.Deprecations {
if dep.Reference.Schema == declcfg.SchemaPackage && dep.Reference.Name == b.Package {
return true
// 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 {
Expand Down
52 changes: 52 additions & 0 deletions internal/catalogmetadata/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,55 @@ func TestBundleHasDeprecation(t *testing.T) {
})
}
}

func TestBundleIsDeprecated(t *testing.T) {
for _, tt := range []struct {
name string
bundle *catalogmetadata.Bundle
deprecated bool
}{
{
name: "has package and channel deprecations, not deprecated",
bundle: &catalogmetadata.Bundle{
Deprecations: []declcfg.DeprecationEntry{
{
Reference: declcfg.PackageScopedReference{
Schema: "olm.package",
},
},
{
Reference: declcfg.PackageScopedReference{
Schema: "olm.channel",
Name: "foo",
},
},
},
},
},
{
name: "has no deprecation entries, not deprecated",
bundle: &catalogmetadata.Bundle{},
},
{
name: "has bundle deprecation entry, deprecated",
bundle: &catalogmetadata.Bundle{
Bundle: declcfg.Bundle{
Name: "foo",
},
Deprecations: []declcfg.DeprecationEntry{
{
Reference: declcfg.PackageScopedReference{
Schema: "olm.bundle",
Name: "foo",
},
},
},
},
deprecated: true,
},
} {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.deprecated, tt.bundle.IsDeprecated())
})
}
}
4 changes: 2 additions & 2 deletions internal/controllers/clusterextension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ func SetDeprecationStatus(ext *ocv1alpha1.ClusterExtension, bundle *catalogmetad
}

// There are two early return scenarios here:
// 1) The bundle is not deprecated (i.e no package or bundle deprecations)
// 1) The bundle is not deprecated (i.e bundle deprecations)
// AND there are no other deprecations associated with the bundle
// 2) The bundle is not deprecated, there are deprecations associated
// with the bundle (i.e at least one channel the bundle is present in is deprecated),
// with the bundle (i.e at least one channel the bundle is present in is deprecated OR whole package is deprecated),
// and the ClusterExtension does not specify a channel. This is because the channel deprecations
// are a loose deprecation coupling on the bundle. A ClusterExtension installation is only
// considered deprecated by a channel deprecation when a deprecated channel is specified via
Expand Down

0 comments on commit 6f651c7

Please sign in to comment.