Skip to content

Commit

Permalink
Add deprecation warnings for CLIs that use or depend on sqlite (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelanford committed Aug 25, 2021
1 parent cede7db commit 9bf77cf
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 24 deletions.
7 changes: 7 additions & 0 deletions alpha/action/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"

"github.com/h2non/filetype"
"github.com/h2non/filetype/matchers"
Expand All @@ -26,6 +27,8 @@ import (
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

var logDeprecationMessage sync.Once

type RefType uint

const (
Expand Down Expand Up @@ -197,6 +200,10 @@ func checkDBFile(ref string) error {
}

func sqliteToDeclcfg(ctx context.Context, dbFile string) (*declcfg.DeclarativeConfig, error) {
logDeprecationMessage.Do(func() {
sqlite.LogSqliteDeprecation()
})

db, err := sqlite.Open(dbFile)
if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion cmd/initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import (

var rootCmd = &cobra.Command{
Short: "initializer",
Long: `initializer takes a directory of OLM manifests and outputs a sqlite database containing them`,
Long: `initializer takes a directory of OLM manifests and outputs a sqlite database containing them
` + sqlite.DeprecationMessage,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
sqlite.LogSqliteDeprecation()
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
Expand Down
3 changes: 2 additions & 1 deletion cmd/opm/index/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/operator-framework/operator-registry/pkg/containertools"
"github.com/operator-framework/operator-registry/pkg/lib/indexer"
"github.com/operator-framework/operator-registry/pkg/registry"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

var (
Expand All @@ -25,7 +26,7 @@ var (
0.1.1 -> 0.1.2 -> 0.1.2-1
will be pruned on add to:
0.1.1 -> 0.1.2
`)
`) + "\n\n" + sqlite.DeprecationMessage

addExample = templates.Examples(`
# Create an index image from scratch with a single bundle image
Expand Down
7 changes: 6 additions & 1 deletion cmd/opm/index/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package index
import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/operator-framework/operator-registry/pkg/sqlite"
)

// AddCommand adds the index subcommand to the given parent command.
func AddCommand(parent *cobra.Command) {
cmd := &cobra.Command{
Use: "index",
Short: "generate operator index container images",
Long: `generate operator index container images from preexisting operator bundles`,
Long: `generate operator index container images from preexisting operator bundles
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
Expand All @@ -19,6 +23,7 @@ func AddCommand(parent *cobra.Command) {
return nil
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
sqlite.LogSqliteDeprecation()
if skipTLS, err := cmd.Flags().GetBool("skip-tls"); err == nil && skipTLS {
logrus.Warn("--skip-tls flag is set: this mode is insecure and meant for development purposes only.")
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/opm/index/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (

"github.com/operator-framework/operator-registry/pkg/containertools"
"github.com/operator-framework/operator-registry/pkg/lib/indexer"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

func newIndexDeleteCmd() *cobra.Command {
indexCmd := &cobra.Command{
Use: "rm",
Short: "delete an entire operator from an index",
Long: `delete an entire operator from an index`,
Long: `delete an entire operator from an index
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
Expand Down
3 changes: 2 additions & 1 deletion cmd/opm/index/deprecatetruncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/operator-framework/operator-registry/pkg/containertools"
"github.com/operator-framework/operator-registry/pkg/lib/indexer"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

var deprecateLong = templates.LongDesc(`
Expand All @@ -28,7 +29,7 @@ var deprecateLong = templates.LongDesc(`
Deprecating a bundle that removes the default channel is not allowed unless the head(s) of all channels are being deprecated (the package is subsequently removed from the index).
This behavior can be enabled via the allow-package-removal flag.
Changing the default channel prior to deprecation is possible by publishing a new bundle to the index.
`)
`) + "\n\n" + sqlite.DeprecationMessage

func newIndexDeprecateTruncateCmd() *cobra.Command {
indexCmd := &cobra.Command{
Expand Down
3 changes: 2 additions & 1 deletion cmd/opm/index/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/operator-framework/operator-registry/pkg/containertools"
"github.com/operator-framework/operator-registry/pkg/lib/indexer"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

var exportLong = templates.LongDesc(`
Expand All @@ -18,7 +19,7 @@ var exportLong = templates.LongDesc(`
the --package option) and export the operator metadata into an appregistry compliant format (a package.yaml file).
Note: the appregistry format is being deprecated in favor of the new index image and image bundle format.
`)
`) + "\n\n" + sqlite.DeprecationMessage

func newIndexExportCmd() *cobra.Command {
indexCmd := &cobra.Command{
Expand Down
5 changes: 4 additions & 1 deletion cmd/opm/index/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (

"github.com/operator-framework/operator-registry/pkg/containertools"
"github.com/operator-framework/operator-registry/pkg/lib/indexer"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

func newIndexPruneCmd() *cobra.Command {
indexCmd := &cobra.Command{
Use: "prune",
Short: "prune an index of all but specified packages",
Long: `prune an index of all but specified packages`,
Long: `prune an index of all but specified packages
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
Expand Down
5 changes: 4 additions & 1 deletion cmd/opm/index/prunestranded.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (

"github.com/operator-framework/operator-registry/pkg/containertools"
"github.com/operator-framework/operator-registry/pkg/lib/indexer"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

func newIndexPruneStrandedCmd() *cobra.Command {
indexCmd := &cobra.Command{
Use: "prune-stranded",
Short: "prune an index of stranded bundles",
Long: `prune an index of stranded bundles - bundles that are not associated with a particular package`,
Long: `prune an index of stranded bundles - bundles that are not associated with a particular package
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
Expand Down
5 changes: 4 additions & 1 deletion cmd/opm/registry/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import (
"github.com/operator-framework/operator-registry/pkg/containertools"
"github.com/operator-framework/operator-registry/pkg/lib/registry"
reg "github.com/operator-framework/operator-registry/pkg/registry"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

func newRegistryAddCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "add",
Short: "add operator bundle to operator registry DB",
Long: `add operator bundle to operator registry DB`,
Long: `add operator bundle to operator registry DB
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
Expand Down
8 changes: 7 additions & 1 deletion cmd/opm/registry/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ package registry
import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/operator-framework/operator-registry/pkg/sqlite"
)

// NewOpmRegistryCmd returns the appregistry-server command
func NewOpmRegistryCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "registry",
Short: "interact with operator-registry database",
Long: `interact with operator-registry database building, modifying and/or serving the operator-registry database`,
Long: `interact with operator-registry database building, modifying and/or serving the operator-registry database
` + sqlite.DeprecationMessage,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
sqlite.LogSqliteDeprecation()
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
Expand Down
6 changes: 5 additions & 1 deletion cmd/opm/registry/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import (
"github.com/spf13/cobra"

"github.com/operator-framework/operator-registry/pkg/mirror"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

func MirrorCmd() *cobra.Command {
// TODO(joelanford): MirrorCmd is unused. Delete it and any other code used only by it.
o := mirror.DefaultImageIndexMirrorerOptions()
cmd := &cobra.Command{
Hidden: true,
Use: "mirror [src image] [dest image]",
Short: "mirror an operator-registry catalog",
Long: `mirror an operator-registry catalog image from one registry to another`,
Long: `mirror an operator-registry catalog image from one registry to another
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
Expand Down
9 changes: 6 additions & 3 deletions cmd/opm/registry/prune.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package registry

import (
"github.com/operator-framework/operator-registry/pkg/lib/registry"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/operator-framework/operator-registry/pkg/lib/registry"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

func newRegistryPruneCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "prune",
Short: "prune an operator registry DB of all but specified packages",
Long: `prune an operator registry DB of all but specified packages`,
Long: `prune an operator registry DB of all but specified packages
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
Expand Down
9 changes: 6 additions & 3 deletions cmd/opm/registry/prunestranded.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package registry

import (
"github.com/operator-framework/operator-registry/pkg/lib/registry"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/operator-framework/operator-registry/pkg/lib/registry"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

func newRegistryPruneStrandedCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "prune-stranded",
Short: "prune an operator registry DB of stranded bundles",
Long: `prune an operator registry DB of stranded bundles - bundles that are not associated with a particular package`,
Long: `prune an operator registry DB of stranded bundles - bundles that are not associated with a particular package
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
Expand Down
9 changes: 6 additions & 3 deletions cmd/opm/registry/rm.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package registry

import (
"github.com/operator-framework/operator-registry/pkg/lib/registry"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/operator-framework/operator-registry/pkg/lib/registry"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

func newRegistryRmCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "rm",
Short: "remove operator from operator registry DB",
Long: `Remove operator from operator registry DB`,
Long: `Remove operator from operator registry DB
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
Expand Down
4 changes: 3 additions & 1 deletion cmd/opm/registry/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func newRegistryServeCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "serve",
Short: "serve an operator-registry database",
Long: `serve an operator-registry database that is queriable using grpc`,
Long: `serve an operator-registry database that is queriable using grpc
` + sqlite.DeprecationMessage,

PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
Expand Down
8 changes: 6 additions & 2 deletions cmd/opm/render/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/operator-framework/operator-registry/alpha/action"
"github.com/operator-framework/operator-registry/alpha/declcfg"
"github.com/operator-framework/operator-registry/pkg/sqlite"
)

func NewCmd() *cobra.Command {
Expand All @@ -20,8 +21,11 @@ func NewCmd() *cobra.Command {
)
cmd := &cobra.Command{
Use: "render [index-image | bundle-image | sqlite-file]...",
Short: "Generate a declarative config blob from the provided index images, bundle images, and sqlite database files",
Args: cobra.MinimumNArgs(1),
Short: "Generate a declarative config blob from catalogs and bundles",
Long: `Generate a declarative config blob from the provided index images, bundle images, and sqlite database files
` + sqlite.DeprecationMessage,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
render.Refs = args

Expand Down
6 changes: 5 additions & 1 deletion cmd/registry-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ import (

var rootCmd = &cobra.Command{
Short: "registry-server",
Long: `registry loads a sqlite database containing operator manifests and serves a grpc API to query it`,
Long: `registry loads a sqlite database containing operator manifests and serves a grpc API to query it
` + sqlite.DeprecationMessage,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
sqlite.LogSqliteDeprecation()
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if debug, _ := cmd.Flags().GetBool("debug"); debug {
logrus.SetLevel(logrus.DebugLevel)
Expand Down
19 changes: 19 additions & 0 deletions pkg/sqlite/deprecationmessage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sqlite

import (
"fmt"

"github.com/sirupsen/logrus"
)

const noticeColor = "\033[1;33m%s\033[0m"

func LogSqliteDeprecation() {
log := logrus.New()
log.Warnf(DeprecationMessage)
}

var DeprecationMessage = fmt.Sprintf(noticeColor, `DEPRECATION NOTICE:
Sqlite-based catalogs and their related subcommands are deprecated. Support for
them will be removed in a future release. Please migrate your catalog workflows
to the new file-based catalog format.`)

0 comments on commit 9bf77cf

Please sign in to comment.