Skip to content

Commit 9eba542

Browse files
modify default channels for previous versions of manifests
Previously, the versions of manifests other than the latest version, used to have the channel 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 35313e8 commit 9eba542

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

Diff for: changelog/fragments/modify-default-channel.yaml

+17
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 pkgman-to-bundle command, modified the `channels` for manifests (other than latest version)
6+
to be the `defaultChannel` from `package.yaml` instead of `candidate`.
7+
8+
# kind is one of:
9+
# - addition
10+
# - change
11+
# - deprecation
12+
# - removal
13+
# - bugfix
14+
kind: "change"
15+
16+
# Is this a breaking change?
17+
breaking: false

Diff for: internal/cmd/operator-sdk/pkgmantobundle/cmd.go

+10-8
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,8 +308,9 @@ 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
314315
var channelNames []string
315316
for csv, ch := range channelsByCSV {
@@ -323,8 +324,8 @@ func getChannelsByCSV(bundle *apimanifests.Bundle, channelsByCSV map[string][]st
323324
// TODO: verify if we have to add this validation since while building bundles if channel is not specified
324325
// we add the default channel.
325326
if channels == "" {
326-
channels = "candidate"
327-
log.Infof("Supported channels cannot be identified from CSV %s, using default channel 'preview'", bundle.CSV.GetName())
327+
channels = defaultChannel
328+
log.Infof("Supported channels cannot be identified from CSV %s, using default channel %s", bundle.CSV.GetName(), defaultChannel)
328329
}
329330

330331
return channels
@@ -339,7 +340,8 @@ func getPackageMetadata(pkg *apimanifests.PackageManifest) (packagename, default
339340

340341
defaultChannel = pkg.DefaultChannelName
341342
if defaultChannel == "" {
342-
defaultChannel = "candidate"
343+
err = fmt.Errorf("cannot find the default channel for package %q", packagename)
344+
return
343345
}
344346

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

Diff for: 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 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)