Skip to content

Commit 030fc1a

Browse files
modify default channels for previous versions of manifests (operator-framework#5071)
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 23f7697 commit 030fc1a

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
# kind is one of:
8+
# - addition
9+
# - change
10+
# - deprecation
11+
# - removal
12+
# - bugfix
13+
kind: "bugfix"
14+
# Is this a breaking change?
15+
breaking: false

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

+9-14
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
}
@@ -309,22 +309,16 @@ func getSDKStamps(bundle *apimanifests.Bundle) (map[string]string, error) {
309309
}
310310

311311
// getChannelsByCSV creates a list for channels for the currentCSV,
312-
func getChannelsByCSV(bundle *apimanifests.Bundle, channelsByCSV map[string][]string) (channels string) {
312+
func getChannelsByCSV(bundle *apimanifests.Bundle, channelsByCSV map[string][]string, defaultChannel string) (channels string) {
313313
// 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-
}
314+
channelNames := channelsByCSV[bundle.CSV.GetName()]
321315
channels = strings.Join(channelNames, ",")
322316

323317
// TODO: verify if we have to add this validation since while building bundles if channel is not specified
324318
// we add the default channel.
325319
if channels == "" {
326-
channels = "preview"
327-
log.Infof("Supported channels cannot be identified from CSV %s, using default channel 'preview'", bundle.CSV.GetName())
320+
channels = defaultChannel
321+
log.Infof("Supported channels cannot be identified from CSV %s, using default channel %s", bundle.CSV.GetName(), defaultChannel)
328322
}
329323

330324
return channels
@@ -339,7 +333,8 @@ func getPackageMetadata(pkg *apimanifests.PackageManifest) (packagename, default
339333

340334
defaultChannel = pkg.DefaultChannelName
341335
if defaultChannel == "" {
342-
defaultChannel = "preview"
336+
err = fmt.Errorf("cannot find the default channel for package %q", packagename)
337+
return
343338
}
344339

345340
channelsByCSV = make(map[string][]string)

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

+9-7
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 preview", func() {
177179
channels := map[string][]string{}
178-
ch := getChannelsByCSV(&bundle, channels)
179-
Expect(ch).To(BeEquivalentTo("preview"))
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("preview"))
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)