Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/pkg/scaffold/olm-catalog: do not add duplicate channels, use operator-name #1693

Merged
merged 5 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
## Unreleased

### Added

- The `operator-sdk olm-catalog gen-csv` command now produces indented JSON for the `alm-examples` annotation. ([#1793](https://github.com/operator-framework/operator-sdk/pull/1793))

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

### Deprecated

### Removed

### Bug Fixes

- 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
37 changes: 24 additions & 13 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,25 @@ 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 := sort.Search(len(pm.Channels), func(i int) bool {
return pm.Channels[i].Name == s.Channel
})
lowerOperatorName := strings.ToLower(s.OperatorName)
if channelIdx == len(pm.Channels) {
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