@@ -182,7 +182,7 @@ func (p *pkgManToBundleCmd) run() (err error) {
182182 for _ , dir := range directories {
183183 if dir .IsDir () {
184184 // this is required to extract project layout and SDK version information.
185- otherLabels , channels , err := getSDKStampsAndChannels (filepath .Join (p .pkgmanifestDir , dir .Name ()), channelsByCSV )
185+ otherLabels , channels , err := getSDKStampsAndChannels (filepath .Join (p .pkgmanifestDir , dir .Name ()), defaultChannel , channelsByCSV )
186186 if err != nil {
187187 return fmt .Errorf ("error getting CSV from provided packagemanifest %v" , err )
188188 }
@@ -268,7 +268,7 @@ func getScorecardConfigPath(inputDir string) (string, error) {
268268 return scorecardConfigPath , nil
269269}
270270
271- func getSDKStampsAndChannels (path string , channelsByCSV map [string ][]string ) (map [string ]string , string , error ) {
271+ func getSDKStampsAndChannels (path , defaultChannel string , channelsByCSV map [string ][]string ) (map [string ]string , string , error ) {
272272 bundle , err := apimanifests .GetBundleFromDir (path )
273273 if err != nil {
274274 return nil , "" , err
@@ -280,7 +280,7 @@ func getSDKStampsAndChannels(path string, channelsByCSV map[string][]string) (ma
280280 }
281281
282282 // Find channels matching the CSV names
283- channels := getChannelsByCSV (bundle , channelsByCSV )
283+ channels := getChannelsByCSV (bundle , channelsByCSV , defaultChannel )
284284
285285 return sdkLabels , channels , nil
286286}
@@ -308,23 +308,18 @@ func getSDKStamps(bundle *apimanifests.Bundle) (map[string]string, error) {
308308 return sdkLabels , nil
309309}
310310
311- // getChannelsByCSV creates a list for channels for the currentCSV,
312- func getChannelsByCSV (bundle * apimanifests.Bundle , channelsByCSV map [string ][]string ) (channels string ) {
311+ // getChannelsByCSV creates a list for channels for the currentCSV. For other versions of manifests which
312+ // are not present in the manifest, the defaultChannel is added.
313+ func getChannelsByCSV (bundle * apimanifests.Bundle , channelsByCSV map [string ][]string , defaultChannel string ) (channels string ) {
313314 // Find channels matching the CSV names
314- var channelNames []string
315- for csv , ch := range channelsByCSV {
316- if csv == bundle .CSV .GetName () {
317- channelNames = ch
318- break
319- }
320- }
315+ channelNames := channelsByCSV [bundle .CSV .GetName ()]
321316 channels = strings .Join (channelNames , "," )
322317
323318 // TODO: verify if we have to add this validation since while building bundles if channel is not specified
324319 // we add the default channel.
325320 if channels == "" {
326- channels = "candidate"
327- log .Infof ("Supported channels cannot be identified from CSV %s, using default channel 'preview' " , bundle .CSV .GetName ())
321+ channels = defaultChannel
322+ log .Infof ("Supported channels cannot be identified from CSV %s, using default channel %s " , bundle .CSV .GetName (), defaultChannel )
328323 }
329324
330325 return channels
@@ -339,7 +334,8 @@ func getPackageMetadata(pkg *apimanifests.PackageManifest) (packagename, default
339334
340335 defaultChannel = pkg .DefaultChannelName
341336 if defaultChannel == "" {
342- defaultChannel = "candidate"
337+ err = fmt .Errorf ("cannot find the default channel for package %q" , packagename )
338+ return
343339 }
344340
345341 channelsByCSV = make (map [string ][]string )
0 commit comments