Skip to content

Commit

Permalink
internal/pkg/scaffold/olm-catalog: do not add duplicate package manif…
Browse files Browse the repository at this point in the history
…est channels (#1693)

* internal/pkg/scaffold/olm-catalog: do not add duplicate channels, use PackageManifest.OperatorName instead of ProjectName
  • Loading branch information
Eric Stroczynski authored Aug 15, 2019
1 parent 73bda6f commit 8c0bafb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- 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))

### Changed

- 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))
- 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))

Expand All @@ -19,6 +20,7 @@

- 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))
- 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))
- 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))

## v0.10.0

Expand Down
1 change: 1 addition & 0 deletions cmd/operator-sdk/olmcatalog/gen-csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func genCSVFunc(cmd *cobra.Command, args []string) error {
CSVVersion: csvVersion,
Channel: csvChannel,
ChannelIsDefault: defaultChannel,
OperatorName: operatorName,
},
)
if err != nil {
Expand Down
43 changes: 29 additions & 14 deletions internal/pkg/scaffold/olm-catalog/package_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ type PackageManifest struct {
// If ChannelIsDefault is true, Channel will be the package manifests'
// default channel.
ChannelIsDefault bool
// OperatorName is the operator's name, ex. app-operator
OperatorName string
}

var _ input.File = &PackageManifest{}

// GetInput gets s' Input.
func (s *PackageManifest) GetInput() (input.Input, error) {
if s.Path == "" {
lowerProjName := strings.ToLower(s.ProjectName)
lowerOperatorName := strings.ToLower(s.OperatorName)
// Path is what the operator-registry expects:
// {manifests -> olm-catalog}/{operator_name}/{operator_name}.package.yaml
s.Path = filepath.Join(OLMCatalogDir, lowerProjName,
lowerProjName+PackageManifestFileExt)
s.Path = filepath.Join(OLMCatalogDir, lowerOperatorName,
lowerOperatorName+PackageManifestFileExt)
}
return s.Input, nil
}
Expand Down Expand Up @@ -117,10 +119,11 @@ func (s *PackageManifest) newPackageManifest() *olmregistry.PackageManifest {
if s.Channel != "" {
channel = s.Channel
}
lowerOperatorName := strings.ToLower(s.OperatorName)
pm := &olmregistry.PackageManifest{
PackageName: s.ProjectName,
PackageName: lowerOperatorName,
Channels: []olmregistry.PackageChannel{
{Name: channel, CurrentCSVName: getCSVName(s.ProjectName, s.CSVVersion)},
{Name: channel, CurrentCSVName: getCSVName(lowerOperatorName, s.CSVVersion)},
},
DefaultChannelName: channel,
}
Expand All @@ -131,17 +134,29 @@ func (s *PackageManifest) newPackageManifest() *olmregistry.PackageManifest {
// channel if possible.
func (s *PackageManifest) setChannels(pm *olmregistry.PackageManifest) error {
if s.Channel != "" {
pm.Channels = append(pm.Channels, olmregistry.PackageChannel{
Name: s.Channel,
CurrentCSVName: getCSVName(s.ProjectName, s.CSVVersion),
})
channelIdx := -1
for i, channel := range pm.Channels {
if channel.Name == s.Channel {
channelIdx = i
break
}
}
lowerOperatorName := strings.ToLower(s.OperatorName)
if channelIdx == -1 {
pm.Channels = append(pm.Channels, olmregistry.PackageChannel{
Name: s.Channel,
CurrentCSVName: getCSVName(lowerOperatorName, s.CSVVersion),
})
} else {
pm.Channels[channelIdx].CurrentCSVName = getCSVName(lowerOperatorName, s.CSVVersion)
}
// Use s.Channel as the default channel if caller has specified it as the
// default.
if s.ChannelIsDefault {
pm.DefaultChannelName = s.Channel
}
}

// Use s.Channel as the default channel if caller has specified it as the
// default.
if s.ChannelIsDefault && s.Channel != "" {
pm.DefaultChannelName = s.Channel
}
if pm.DefaultChannelName == "" {
log.Warn("Package manifest default channel is empty and should be set to an existing channel.")
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/scaffold/olm-catalog/package_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestPackageManifest(t *testing.T) {
CSVVersion: csvVer,
Channel: "stable",
ChannelIsDefault: true,
OperatorName: projectName,
}
err = s.Execute(cfg, pm)
if err != nil {
Expand Down

0 comments on commit 8c0bafb

Please sign in to comment.