Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
### Deprecated

- **Breaking Change:** The `--namespace` flag from `operator-sdk run --local`, `operator-sdk test --local` and `operator-sdk cleanup` command was deprecated and will be removed in the future versions. Use `--watch-namespace` and `--operator-namespace` instead of. ([#2617](https://github.com/operator-framework/operator-sdk/pull/2617))
- **Breaking Change:** The method `ctx.GetNamespace()` from the `pkg/test` is deprecated and will be removed in the future versions. Use `ctx.GetOperatorNamespace()` and `ctx.GetWatchNamespace()` instead of. ([#2617](https://github.com/operator-framework/operator-sdk/pull/2617))
- **Breaking Change:** The method `ctx.GetNamespace()` from the `pkg/test` is deprecated and will be removed in future versions. Use `ctx.GetOperatorNamespace()` and `ctx.GetWatchNamespace()` instead of. ([#2617](https://github.com/operator-framework/operator-sdk/pull/2617))
- package manifests are deprecated and new manifests are no longer generated; existing manifests are still updated by `operator-sdk generate csv`, but updates will not occur in future versions. Use [`operator-sdk bundle create`](./doc/cli/operator-sdk_bundle_create.md) to manage operator bundle metadata. ([#2755](https://github.com/operator-framework/operator-sdk/pull/2755))
Comment thread
estroz marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to remember to upgrade the Getting Started as well.

### Removed

- **Breaking Change:** remove `pkg/restmapper` which was deprecated in `v0.14.0`. Projects that use this package must switch to the `DynamicRESTMapper` implementation in [controller-runtime](https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/client/apiutil#NewDynamicRESTMapper). ([#2544](https://github.com/operator-framework/operator-sdk/pull/2544))
- **Breaking Change:** remove deprecated `operator-sdk generate openapi` subcommand. ([#2740](https://github.com/operator-framework/operator-sdk/pull/2740))
- **Breaking Change:** remove deprecated `operator-sdk generate openapi` subcommand. ([#2740](https://github.com/operator-framework/operator-sdk/pull/2740))

### Bug Fixes

Expand Down
32 changes: 25 additions & 7 deletions internal/generate/olm-catalog/package_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ import (
"github.com/operator-framework/operator-registry/pkg/registry"
"github.com/operator-framework/operator-sdk/internal/generate/gen"
"github.com/operator-framework/operator-sdk/internal/util/fileutil"
"github.com/operator-framework/operator-sdk/internal/util/projutil"

"github.com/ghodss/yaml"
log "github.com/sirupsen/logrus"
)

// Deprecated: The package manifest generator will no longer create new package
// manifests, only update existing ones. This generator will be removed in v0.19.0.

const (
PackageManifestFileExt = ".package.yaml"

Expand Down Expand Up @@ -83,7 +87,7 @@ func (g pkgGenerator) Generate() error {
return err
}
if len(fileMap) == 0 {
return errors.New("error generating package manifest: no generated file found")
return nil
}
if err = os.MkdirAll(g.OutputDir, fileutil.DefaultDirFileMode); err != nil {
return fmt.Errorf("error mkdir %s: %v", g.OutputDir, err)
Expand All @@ -100,17 +104,29 @@ func (g pkgGenerator) Generate() error {
// generate either reads an existing package manifest or creates a new
// manifest and modifies it based on values set in s.
func (g pkgGenerator) generate() (map[string][]byte, error) {
pkg, err := g.buildPackageManifest()
if err != nil {
return nil, err
path := filepath.Join(g.Inputs[ManifestsDirKey], g.fileName)
pkg := registry.PackageManifest{}
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil, nil
} else if err == nil || os.IsExist(err) {
projutil.PrintDeprecationWarning("Package manifests are no longer updated. " +
"Run `operator-sdk bundle create --generate-only` to create operator metadata")
b, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to read package manifest %s: %v", path, err)
}
if err = yaml.Unmarshal(b, &pkg); err != nil {
return nil, fmt.Errorf("failed to unmarshal package manifest %s: %v", path, err)
}
} else {
return nil, fmt.Errorf("error reading package manifest %s: %v", path, err)
}

g.setChannels(&pkg)
sortChannelsByName(&pkg)

if err := validatePackageManifest(&pkg); err != nil {
log.Error(err)
os.Exit(1)
return nil, err
}

b, err := yaml.Marshal(pkg)
Expand All @@ -126,6 +142,7 @@ func (g pkgGenerator) generate() (map[string][]byte, error) {

// buildPackageManifest will create a registry.PackageManifest from scratch, or modify
// an existing one if found at the expected path.
// Deprecated: only used for testing other methods on g.
func (g pkgGenerator) buildPackageManifest() (registry.PackageManifest, error) {
pkg := registry.PackageManifest{}
path := filepath.Join(g.Inputs[ManifestsDirKey], g.fileName)
Expand Down Expand Up @@ -175,7 +192,8 @@ func validatePackageManifest(pkg *registry.PackageManifest) error {
return nil
}

// newPackageManifest will return the registry.PackageManifest populated
// newPackageManifest will return the registry.PackageManifest populated.
// Deprecated: only used for testing other methods on g.
func newPackageManifest(operatorName, channelName, version string) registry.PackageManifest {
// Take the current CSV version to be the "alpha" channel, as an operator
// should only be designated anything more stable than "alpha" by a human.
Expand Down
58 changes: 0 additions & 58 deletions internal/generate/olm-catalog/package_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package olmcatalog

import (
"path/filepath"
"reflect"
"testing"

"github.com/operator-framework/operator-registry/pkg/registry"
Expand Down Expand Up @@ -112,63 +111,6 @@ func TestValidatePackageManifest(t *testing.T) {
}
}

func TestNewPackageManifest(t *testing.T) {
Comment thread
estroz marked this conversation as resolved.
type args struct {
operatorName string
channelName string
version string
}
tests := []struct {
name string
args args
want registry.PackageManifest
}{
{
name: "Should return a valid registry.PackageManifest",
want: registry.PackageManifest{
PackageName: "memcached-operator",
Channels: []registry.PackageChannel{
registry.PackageChannel{
Name: "stable",
CurrentCSVName: "memcached-operator.v0.0.3",
},
},
DefaultChannelName: "stable",
},
args: args{
operatorName: testProjectName,
channelName: "stable",
version: csvVersion,
},
},
{
name: "Should return a valid registry.PackageManifest with channel == alpha when it is not informed",
want: registry.PackageManifest{
PackageName: "memcached-operator",
Channels: []registry.PackageChannel{
registry.PackageChannel{
Name: "alpha",
CurrentCSVName: "memcached-operator.v0.0.3",
},
},
DefaultChannelName: "alpha",
},
args: args{
operatorName: testProjectName,
version: csvVersion,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := newPackageManifest(tt.args.operatorName, tt.args.channelName, tt.args.version)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewPackageManifest() = %v, want %v", got, tt.want)
}
})
}
}

const packageManifestExp = `channels:
- currentCSV: memcached-operator.v0.0.2
name: alpha
Expand Down
8 changes: 8 additions & 0 deletions internal/util/projutil/project_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
rolesDir = "roles"
helmChartsDir = "helm-charts"
goModFile = "go.mod"

noticeColor = "\033[1;36m%s\033[0m"
)

// OperatorType - the type of operator
Expand Down Expand Up @@ -271,3 +273,9 @@ func CheckGoModules() error {
}
return nil
}

// PrintDeprecationWarning prints a colored warning wrapping msg to the terminal.
func PrintDeprecationWarning(msg string) {
fmt.Printf(noticeColor, "[Deprecation Notice] "+msg+". Refer to the version upgrade guide "+
"for more information: https://operator-sdk.netlify.com/docs/migration/version-upgrade-guide\n\n")
}