Skip to content

Commit

Permalink
(bugfix): update operator-sdk run bundle(-upgrade) to ignore channe…
Browse files Browse the repository at this point in the history
…ls in the bundle and use a default one (#6042)

* fix run bundle(-upgrade) to no longer stall

Signed-off-by: Bryce Palmer <[email protected]>

* add changelog

Signed-off-by: Bryce Palmer <[email protected]>

* add err check and log warning for linter

Signed-off-by: Bryce Palmer <[email protected]>

* update run bundle(-upgrade) to use a default channel

Signed-off-by: Bryce Palmer <[email protected]>

* update channel name checks

Signed-off-by: Bryce Palmer <[email protected]>

* add changelog

Signed-off-by: Bryce Palmer <[email protected]>

* update changelog

Signed-off-by: Bryce Palmer <[email protected]>

Signed-off-by: Bryce Palmer <[email protected]>
  • Loading branch information
everettraven authored Sep 28, 2022
1 parent 8fc9626 commit b97d84f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
10 changes: 10 additions & 0 deletions changelog/fragments/rbu-channel-fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# entries is a list of entries to include in
# release notes and/or the migration guide
entries:
- description: >
`operator-sdk run bundle(-upgrade)`: fixed bug that made it so bundles weren't properly upgraded if the
channel used in the bundle wasn't in the same channel as the bundle installed via `operator-sdk run bundle`.
Using `operator-sdk run bundle` will now use a default channel instead of the one in the bundle.
kind: "bugfix"
breaking: false
10 changes: 3 additions & 7 deletions internal/olm/operator/bundle/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package bundle
import (
"context"
"fmt"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -121,11 +120,8 @@ func (i *Install) setup(ctx context.Context) error {
UseHTTP: i.UseHTTP,
}

if _, hasChannelMetadata := labels[registrybundle.ChannelsLabel]; hasChannelMetadata {
f.ChannelName = strings.Split(labels[registrybundle.ChannelsLabel], ",")[0]
} else {
f.ChannelName = fbcutil.DefaultChannel
}
// ignore channels for the bundle and instead use the default
f.ChannelName = fbcutil.DefaultChannel

// generate an fbc if an fbc specific label is found on the image or for a default index image.
content, err := generateFBCContent(ctx, f, i.BundleImage, i.IndexImageCatalogCreator.IndexImage)
Expand All @@ -140,7 +136,7 @@ func (i *Install) setup(ctx context.Context) error {
i.OperatorInstaller.CatalogSourceName = operator.CatalogNameForPackage(i.OperatorInstaller.PackageName)
i.OperatorInstaller.StartingCSV = csv.Name
i.OperatorInstaller.SupportedInstallModes = operator.GetSupportedInstallModes(csv.Spec.InstallModes)
i.OperatorInstaller.Channel = strings.Split(labels[registrybundle.ChannelsLabel], ",")[0]
i.OperatorInstaller.Channel = fbcutil.DefaultChannel

i.IndexImageCatalogCreator.PackageName = i.OperatorInstaller.PackageName
i.IndexImageCatalogCreator.BundleImage = i.BundleImage
Expand Down
8 changes: 0 additions & 8 deletions internal/olm/operator/bundleupgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package bundleupgrade

import (
"context"
"strings"

"github.com/operator-framework/api/pkg/operators/v1alpha1"
registrybundle "github.com/operator-framework/operator-registry/pkg/lib/bundle"
Expand Down Expand Up @@ -79,19 +78,12 @@ func (u *Upgrade) setup(ctx context.Context) error {
u.OperatorInstaller.CatalogSourceName = operator.CatalogNameForPackage(u.OperatorInstaller.PackageName)
u.OperatorInstaller.StartingCSV = csv.Name
u.OperatorInstaller.SupportedInstallModes = operator.GetSupportedInstallModes(csv.Spec.InstallModes)
u.OperatorInstaller.Channel = strings.Split(labels[registrybundle.ChannelsLabel], ",")[0]

// Since an existing CatalogSource will have an annotation containing the existing index image,
// defer defaulting the bundle add mode to after the existing CatalogSource is retrieved.
u.IndexImageCatalogCreator.PackageName = u.OperatorInstaller.PackageName
u.IndexImageCatalogCreator.BundleImage = u.BundleImage
u.IndexImageCatalogCreator.IndexImage = fbcutil.DefaultIndexImage

if _, hasChannelMetadata := labels[registrybundle.ChannelsLabel]; hasChannelMetadata {
u.IndexImageCatalogCreator.ChannelName = strings.Split(labels[registrybundle.ChannelsLabel], ",")[0]
} else {
u.IndexImageCatalogCreator.ChannelName = fbcutil.DefaultChannel
}

return nil
}
9 changes: 9 additions & 0 deletions internal/olm/operator/registry/index_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,15 @@ func upgradeFBC(ctx context.Context, f *fbcutil.FBCContext, originalDeclCfg *dec
// then deletes existing registry pod based on annotation name found in catalog source object
func (c IndexImageCatalogCreator) UpdateCatalog(ctx context.Context, cs *v1alpha1.CatalogSource, subscription *v1alpha1.Subscription) error {
var prevRegistryPodName string

if subscription != nil && c.ChannelName == "" {
c.ChannelName = subscription.Spec.Channel
}

if c.ChannelName == "" {
c.ChannelName = fbcutil.DefaultChannel
}

if annotations := cs.GetAnnotations(); len(annotations) != 0 {
if value, hasAnnotation := annotations[indexImageAnnotation]; hasAnnotation && value != "" {
c.IndexImage = value
Expand Down

0 comments on commit b97d84f

Please sign in to comment.