Skip to content

Commit d7b4ad1

Browse files
modify default channels for previous versions of manifests (#5062)
Previously, the versions of manifests other than the latest version, used to have channel specified as `candidate`. This caused errors while running the bundle. With this commit, the channels for those manifests would be the `defaultchannel` specified in package.yaml. Signed-off-by: varshaprasad96 <[email protected]>
1 parent 570cae3 commit d7b4ad1

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# entries is a list of entries to include in
2+
# release notes and/or the migration guide
3+
entries:
4+
- description: >
5+
In the `pkgman-to-bundle` command, changed the default channel name used for CSV's
6+
not specified in `package.yaml` to `defaultChannel` instead of "candidate".
7+
8+
# kind is one of:
9+
# - addition
10+
# - change
11+
# - deprecation
12+
# - removal
13+
# - bugfix
14+
kind: "bugfix"
15+
16+
# Is this a breaking change?
17+
breaking: false

internal/cmd/operator-sdk/pkgmantobundle/cmd.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

internal/cmd/operator-sdk/pkgmantobundle/pkgmantobundle_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,21 @@ var _ = Describe("Running pkgmanToBundle command", func() {
164164
},
165165
}
166166

167+
defaultChannel := "gamma"
168+
167169
It("should get the list of channels for corresponding CSV", func() {
168170
channels := map[string][]string{
169171
"memcached-operator:0.0.1": {"alpha", "beta"},
170172
}
171173

172-
ch := getChannelsByCSV(&bundle, channels)
174+
ch := getChannelsByCSV(&bundle, channels, defaultChannel)
173175
Expect(ch).To(BeEquivalentTo("alpha,beta"))
174176
})
175177

176178
It("if no channel is provided, default to candidate", func() {
177179
channels := map[string][]string{}
178-
ch := getChannelsByCSV(&bundle, channels)
179-
Expect(ch).To(BeEquivalentTo("candidate"))
180+
ch := getChannelsByCSV(&bundle, channels, defaultChannel)
181+
Expect(ch).To(BeEquivalentTo(defaultChannel))
180182
})
181183
})
182184
})
@@ -224,11 +226,11 @@ var _ = Describe("Running pkgmanToBundle command", func() {
224226
Expect(err.Error()).To(ContainSubstring("cannot find packagename from the manifest directory"))
225227
})
226228

227-
It("should assign default channel name of not provided", func() {
229+
It("should error when defaultChannel name is empty", func() {
228230
pkg.DefaultChannelName = ""
229-
_, defaultChannel, _, err := getPackageMetadata(&pkg)
230-
Expect(err).NotTo(HaveOccurred())
231-
Expect(defaultChannel).To(BeEquivalentTo("candidate"))
231+
_, _, _, err := getPackageMetadata(&pkg)
232+
Expect(err).To(HaveOccurred())
233+
Expect(err.Error()).To(ContainSubstring("cannot find the default channel for package"))
232234
})
233235
})
234236
})

0 commit comments

Comments
 (0)