Skip to content

Commit 8c0bafb

Browse files
author
Eric Stroczynski
authored
internal/pkg/scaffold/olm-catalog: do not add duplicate package manifest channels (#1693)
* internal/pkg/scaffold/olm-catalog: do not add duplicate channels, use PackageManifest.OperatorName instead of ProjectName
1 parent 73bda6f commit 8c0bafb

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Added flag `--dep-manager` to command [`operator-sdk print-deps`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#print-deps) to specify the type of dependency manager file to print. The choice of dependency manager is inferred from top-level dependency manager files present if `--dep-manager` is not set. ([#1819](https://github.com/operator-framework/operator-sdk/pull/1819))
77

88
### Changed
9+
910
- The Helm operator now uses the CR name for the release name for newly created CRs. Existing CRs will continue to use their existing UID-based release name. When a release name collision occurs (when CRs of different types share the same name), the second CR will fail to install with an error about a duplicate name. ([#1818](https://github.com/operator-framework/operator-sdk/pull/1818))
1011
- Commands [`olm uninstall`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#uninstall) and [`olm status`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#status) no longer use a `--version` flag to specify OLM version. This information is now retrieved from the running cluster. ([#1634](https://github.com/operator-framework/operator-sdk/pull/1634))
1112

@@ -19,6 +20,7 @@
1920

2021
- Configure the repo path correctly in `operator-sdk add crd` and prevent the command from running outside of an operator project. ([#1660](https://github.com/operator-framework/operator-sdk/pull/1660))
2122
- In the Helm operator, skip owner reference injection for cluster-scoped resources in release manifests. The Helm operator only supports namespace-scoped CRs, and namespaced resources cannot own cluster-scoped resources. ([#1817](https://github.com/operator-framework/operator-sdk/pull/1817))
23+
- Package manifests generated with [`gen-csv`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#gen-csv) respect the `--operator-name` flag, channel names are checked for duplicates before (re-)generation. ([#1693](https://github.com/operator-framework/operator-sdk/pull/1693))
2224

2325
## v0.10.0
2426

cmd/operator-sdk/olmcatalog/gen-csv.go

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func genCSVFunc(cmd *cobra.Command, args []string) error {
107107
CSVVersion: csvVersion,
108108
Channel: csvChannel,
109109
ChannelIsDefault: defaultChannel,
110+
OperatorName: operatorName,
110111
},
111112
)
112113
if err != nil {

internal/pkg/scaffold/olm-catalog/package_manifest.go

+29-14
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@ type PackageManifest struct {
4545
// If ChannelIsDefault is true, Channel will be the package manifests'
4646
// default channel.
4747
ChannelIsDefault bool
48+
// OperatorName is the operator's name, ex. app-operator
49+
OperatorName string
4850
}
4951

5052
var _ input.File = &PackageManifest{}
5153

5254
// GetInput gets s' Input.
5355
func (s *PackageManifest) GetInput() (input.Input, error) {
5456
if s.Path == "" {
55-
lowerProjName := strings.ToLower(s.ProjectName)
57+
lowerOperatorName := strings.ToLower(s.OperatorName)
5658
// Path is what the operator-registry expects:
5759
// {manifests -> olm-catalog}/{operator_name}/{operator_name}.package.yaml
58-
s.Path = filepath.Join(OLMCatalogDir, lowerProjName,
59-
lowerProjName+PackageManifestFileExt)
60+
s.Path = filepath.Join(OLMCatalogDir, lowerOperatorName,
61+
lowerOperatorName+PackageManifestFileExt)
6062
}
6163
return s.Input, nil
6264
}
@@ -117,10 +119,11 @@ func (s *PackageManifest) newPackageManifest() *olmregistry.PackageManifest {
117119
if s.Channel != "" {
118120
channel = s.Channel
119121
}
122+
lowerOperatorName := strings.ToLower(s.OperatorName)
120123
pm := &olmregistry.PackageManifest{
121-
PackageName: s.ProjectName,
124+
PackageName: lowerOperatorName,
122125
Channels: []olmregistry.PackageChannel{
123-
{Name: channel, CurrentCSVName: getCSVName(s.ProjectName, s.CSVVersion)},
126+
{Name: channel, CurrentCSVName: getCSVName(lowerOperatorName, s.CSVVersion)},
124127
},
125128
DefaultChannelName: channel,
126129
}
@@ -131,17 +134,29 @@ func (s *PackageManifest) newPackageManifest() *olmregistry.PackageManifest {
131134
// channel if possible.
132135
func (s *PackageManifest) setChannels(pm *olmregistry.PackageManifest) error {
133136
if s.Channel != "" {
134-
pm.Channels = append(pm.Channels, olmregistry.PackageChannel{
135-
Name: s.Channel,
136-
CurrentCSVName: getCSVName(s.ProjectName, s.CSVVersion),
137-
})
137+
channelIdx := -1
138+
for i, channel := range pm.Channels {
139+
if channel.Name == s.Channel {
140+
channelIdx = i
141+
break
142+
}
143+
}
144+
lowerOperatorName := strings.ToLower(s.OperatorName)
145+
if channelIdx == -1 {
146+
pm.Channels = append(pm.Channels, olmregistry.PackageChannel{
147+
Name: s.Channel,
148+
CurrentCSVName: getCSVName(lowerOperatorName, s.CSVVersion),
149+
})
150+
} else {
151+
pm.Channels[channelIdx].CurrentCSVName = getCSVName(lowerOperatorName, s.CSVVersion)
152+
}
153+
// Use s.Channel as the default channel if caller has specified it as the
154+
// default.
155+
if s.ChannelIsDefault {
156+
pm.DefaultChannelName = s.Channel
157+
}
138158
}
139159

140-
// Use s.Channel as the default channel if caller has specified it as the
141-
// default.
142-
if s.ChannelIsDefault && s.Channel != "" {
143-
pm.DefaultChannelName = s.Channel
144-
}
145160
if pm.DefaultChannelName == "" {
146161
log.Warn("Package manifest default channel is empty and should be set to an existing channel.")
147162
}

internal/pkg/scaffold/olm-catalog/package_manifest_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func TestPackageManifest(t *testing.T) {
4848
CSVVersion: csvVer,
4949
Channel: "stable",
5050
ChannelIsDefault: true,
51+
OperatorName: projectName,
5152
}
5253
err = s.Execute(cfg, pm)
5354
if err != nil {

0 commit comments

Comments
 (0)