-
Notifications
You must be signed in to change notification settings - Fork 252
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
Adding opm CLI #96
Merged
openshift-merge-robot
merged 1 commit into
operator-framework:master
from
gallettilance:opm-cli
Oct 17, 2019
+150
−1
Merged
Adding opm CLI #96
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/operator-framework/operator-registry/cmd/opm/registry" | ||
) | ||
|
||
func main() { | ||
rootCmd := &cobra.Command{ | ||
Use: "opm", | ||
Short: "operator package manager", | ||
Long: "CLI to interact with operator-registry and build indexes of operator content", | ||
} | ||
|
||
rootCmd.AddCommand(registry.NewOpmRegistryCmd()) | ||
|
||
if err := rootCmd.Execute(); err != nil { | ||
logrus.Panic(err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package registry | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// 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`, | ||
|
||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
if debug, _ := cmd.Flags().GetBool("debug"); debug { | ||
logrus.SetLevel(logrus.DebugLevel) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
rootCmd.AddCommand(newRegistryServeCmd()) | ||
|
||
return rootCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package registry | ||
|
||
import ( | ||
"context" | ||
"net" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/reflection" | ||
|
||
"github.com/operator-framework/operator-registry/pkg/api" | ||
health "github.com/operator-framework/operator-registry/pkg/api/grpc_health_v1" | ||
"github.com/operator-framework/operator-registry/pkg/lib/log" | ||
"github.com/operator-framework/operator-registry/pkg/registry" | ||
"github.com/operator-framework/operator-registry/pkg/server" | ||
"github.com/operator-framework/operator-registry/pkg/sqlite" | ||
) | ||
|
||
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`, | ||
|
||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
if debug, _ := cmd.Flags().GetBool("debug"); debug { | ||
logrus.SetLevel(logrus.DebugLevel) | ||
} | ||
return nil | ||
}, | ||
|
||
RunE: runRegistryServeCmdFunc, | ||
} | ||
|
||
rootCmd.Flags().Bool("debug", false, "enable debug logging") | ||
rootCmd.Flags().StringP("database", "d", "bundles.db", "relative path to sqlite db") | ||
rootCmd.Flags().StringP("port", "p", "50051", "port number to serve on") | ||
rootCmd.Flags().StringP("termination-log", "t", "/dev/termination-log", "path to a container termination log file") | ||
|
||
return rootCmd | ||
|
||
} | ||
|
||
func runRegistryServeCmdFunc(cmd *cobra.Command, args []string) error { | ||
// Immediately set up termination log | ||
terminationLogPath, err := cmd.Flags().GetString("termination-log") | ||
if err != nil { | ||
return err | ||
} | ||
err = log.AddDefaultWriterHooks(terminationLogPath) | ||
if err != nil { | ||
logrus.WithError(err).Warn("unable to set termination log path") | ||
} | ||
dbName, err := cmd.Flags().GetString("database") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
port, err := cmd.Flags().GetString("port") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logger := logrus.WithFields(logrus.Fields{"database": dbName, "port": port}) | ||
|
||
var store registry.Query | ||
store, err = sqlite.NewSQLLiteQuerier(dbName) | ||
if err != nil { | ||
logger.WithError(err).Warnf("failed to load db") | ||
} | ||
if store == nil { | ||
store = registry.NewEmptyQuerier() | ||
} | ||
|
||
// sanity check that the db is available | ||
tables, err := store.ListTables(context.TODO()) | ||
if err != nil { | ||
logger.WithError(err).Warnf("couldn't list tables in db") | ||
} | ||
if len(tables) == 0 { | ||
logger.Warn("no tables found in db") | ||
} | ||
|
||
lis, err := net.Listen("tcp", ":"+port) | ||
if err != nil { | ||
logger.Fatalf("failed to listen: %s", err) | ||
} | ||
s := grpc.NewServer() | ||
|
||
api.RegisterRegistryServer(s, server.NewRegistryServer(store)) | ||
health.RegisterHealthServer(s, server.NewHealthServer()) | ||
reflection.Register(s) | ||
logger.Info("serving registry") | ||
if err := s.Serve(lis); err != nil { | ||
logger.Fatalf("failed to serve: %s", err) | ||
} | ||
|
||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄