Skip to content

Commit

Permalink
[v1.22.x] Bugfix: Generate just the extra FBC for run bundle-upgrade (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
openshift-cherrypick-robot committed Jun 30, 2022
1 parent cc1e350 commit 2fcc326
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
25 changes: 25 additions & 0 deletions changelog/fragments/run-bundle-upgrade-bugfix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# entries is a list of entries to include in
# release notes and/or the migration guide
entries:
- description: >
For run bundle-upgrade, generate just the extra FBC of the bundle instead of rendering the entire index and appending bundle contents to it.
# kind is one of:
# - addition
# - change
# - deprecation
# - removal
# - bugfix
kind: "bugfix"
# Is this a breaking change?
breaking: false
# NOTE: ONLY USE `pull_request_override` WHEN ADDING THIS
# FILE FOR A PREVIOUSLY MERGED PULL_REQUEST!
#
# The generator auto-detects the PR number from the commit
# message in which this file was originally added.
#
# What is the pull request number (without the "#")?
# pull_request_override: 0
17 changes: 10 additions & 7 deletions internal/olm/operator/registry/index_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,13 @@ func upgradeFBC(ctx context.Context, f *fbcutil.FBCContext, originalDeclCfg *dec
existingBundles[bundle.Name] = bundle.Package
}

extraDeclConfig := &declarativeconfig.DeclarativeConfig{}
// declcfg contains all the bundles we need to insert to form the new FBC
entries := []declarativeconfig.ChannelEntry{} // Used when generating a new channel
for i, bundle := range declcfg.Bundles {
// if it is not present in the bundles array or belongs to a different package, we can add it
if _, present := existingBundles[bundle.Name]; !present || existingBundles[bundle.Name] != bundle.Package {
originalDeclCfg.Bundles = append(originalDeclCfg.Bundles, bundle)
extraDeclConfig.Bundles = append(extraDeclConfig.Bundles, bundle)
}

// constructing a new entry to add
Expand All @@ -300,20 +301,21 @@ func upgradeFBC(ctx context.Context, f *fbcutil.FBCContext, originalDeclCfg *dec

// either add it to a new channel or an existing channel
if channelExists {
originalDeclCfg.Channels[channelIndex].Entries = append(originalDeclCfg.Channels[channelIndex].Entries, entry)
extraDeclConfig.Channels[channelIndex].Entries = []declarativeconfig.ChannelEntry{entry}
} else {
entries = append(entries, entry)
}
}

// create a new channel if it does not exist
if !channelExists {
originalDeclCfg.Channels = append(originalDeclCfg.Channels, declarativeconfig.Channel{
channel := declarativeconfig.Channel{
Schema: fbcutil.SchemaChannel,
Name: f.ChannelName,
Package: f.Package,
Entries: entries,
})
}
extraDeclConfig.Channels = []declarativeconfig.Channel{channel}
}

// check if package already exists
Expand All @@ -327,14 +329,15 @@ func upgradeFBC(ctx context.Context, f *fbcutil.FBCContext, originalDeclCfg *dec

// only add the new package if it does not already exist
if !packagePresent {
originalDeclCfg.Packages = append(originalDeclCfg.Packages, declarativeconfig.Package{
packageBlob := declarativeconfig.Package{
Schema: fbcutil.SchemaPackage,
Name: f.Package,
DefaultChannel: f.ChannelName,
})
}
extraDeclConfig.Packages = []declarativeconfig.Package{packageBlob}
}

return originalDeclCfg, nil
return extraDeclConfig, nil
}

// UpdateCatalog links a new registry pod in catalog source by updating the address and annotations,
Expand Down

0 comments on commit 2fcc326

Please sign in to comment.