Skip to content

Commit b97d84f

Browse files
authored
(bugfix): update operator-sdk run bundle(-upgrade) to ignore channels 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]>
1 parent 8fc9626 commit b97d84f

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# entries is a list of entries to include in
2+
# release notes and/or the migration guide
3+
entries:
4+
- description: >
5+
`operator-sdk run bundle(-upgrade)`: fixed bug that made it so bundles weren't properly upgraded if the
6+
channel used in the bundle wasn't in the same channel as the bundle installed via `operator-sdk run bundle`.
7+
Using `operator-sdk run bundle` will now use a default channel instead of the one in the bundle.
8+
kind: "bugfix"
9+
breaking: false
10+

internal/olm/operator/bundle/install.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package bundle
1717
import (
1818
"context"
1919
"fmt"
20-
"strings"
2120

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

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

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

145141
i.IndexImageCatalogCreator.PackageName = i.OperatorInstaller.PackageName
146142
i.IndexImageCatalogCreator.BundleImage = i.BundleImage

internal/olm/operator/bundleupgrade/upgrade.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package bundleupgrade
1616

1717
import (
1818
"context"
19-
"strings"
2019

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

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

90-
if _, hasChannelMetadata := labels[registrybundle.ChannelsLabel]; hasChannelMetadata {
91-
u.IndexImageCatalogCreator.ChannelName = strings.Split(labels[registrybundle.ChannelsLabel], ",")[0]
92-
} else {
93-
u.IndexImageCatalogCreator.ChannelName = fbcutil.DefaultChannel
94-
}
95-
9688
return nil
9789
}

internal/olm/operator/registry/index_image.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ func upgradeFBC(ctx context.Context, f *fbcutil.FBCContext, originalDeclCfg *dec
339339
// then deletes existing registry pod based on annotation name found in catalog source object
340340
func (c IndexImageCatalogCreator) UpdateCatalog(ctx context.Context, cs *v1alpha1.CatalogSource, subscription *v1alpha1.Subscription) error {
341341
var prevRegistryPodName string
342+
343+
if subscription != nil && c.ChannelName == "" {
344+
c.ChannelName = subscription.Spec.Channel
345+
}
346+
347+
if c.ChannelName == "" {
348+
c.ChannelName = fbcutil.DefaultChannel
349+
}
350+
342351
if annotations := cs.GetAnnotations(); len(annotations) != 0 {
343352
if value, hasAnnotation := annotations[indexImageAnnotation]; hasAnnotation && value != "" {
344353
c.IndexImage = value

0 commit comments

Comments
 (0)