Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 15 additions & 12 deletions commands/operator-sdk/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ package cmd

import "github.com/spf13/cobra"

// buildCmd represents the build command
var buildCmd = &cobra.Command{
Use: "build <image>",
Short: "Compiles code and builds artifacts",
Long: `The operator-sdk build command compiles the code, builds the executables,
and generates Kubernetes manifests.
func NewBuildCmd() *cobra.Command {
return &cobra.Command{
Use: "build <image>",
Short: "Compiles code and builds artifacts",
Long: `The operator-sdk build command compiles the code, builds the executables,
and generates Kubernetes manifests.

<image> is the container image to be built, e.g. "quay.io/example/operator:v0.0.1".
This image will be automatically set in the deployment manifests.
<image> is the container image to be built, e.g. "quay.io/example/operator:v0.0.1".
This image will be automatically set in the deployment manifests.

After build completes, the image would be built locally in docker. Then it needs to
be pushed to remote registry.
For example:
After build completes, the image would be built locally in docker. Then it needs to
be pushed to remote registry.
For example:
$ operator-sdk build quay.io/example/operator:v0.0.1
$ docker push quay.io/example/operator:v0.0.1
`,
Run: newFunc,
Run: func(cmd *cobra.Command, args []string) {
panic("UNIMPLEMENTED")
},
}
}
18 changes: 18 additions & 0 deletions commands/operator-sdk/cmd/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/coreos/operator-sdk/commands/operator-sdk/cmd/generate"

"github.com/spf13/cobra"
)

func NewGenerateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "generate <generator>",
Short: "Invokes specific generator",
Long: `The operator-sdk generate command invokes specific generator to generate code as needed.
`,
}
cmd.AddCommand(generate.NewGenerateK8SCmd())
return cmd
}
16 changes: 16 additions & 0 deletions commands/operator-sdk/cmd/generate/k8s.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package generate

import "github.com/spf13/cobra"

func NewGenerateK8SCmd() *cobra.Command {
return &cobra.Command{
Use: "k8s",
Short: "Generates Kubernetes code for custom resource",
Long: `k8s generator generates code for custom resource given the API spec
to comply with kube-API requirements.
`,
Run: func(cmd *cobra.Command, args []string) {
panic("UNIMPLEMENTED")
},
}
}
36 changes: 18 additions & 18 deletions commands/operator-sdk/cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@ import (
"github.com/spf13/cobra"
)

// newCmd represents the new command
var newCmd = &cobra.Command{
Use: "new <project-name> [required-flags]",
Short: "Creates a new operator application",
Long: `The operator-sdk new command creates a new operator application and
generates a default directory layout based on the input <project-name>.
func NewNewCmd() *cobra.Command {
newCmd := &cobra.Command{
Use: "new <project-name> [required-flags]",
Short: "Creates a new operator application",
Long: `The operator-sdk new command creates a new operator application and
generates a default directory layout based on the input <project-name>.

<project-name> is the project name of the new operator. (e.g app-operator)
<project-name> is the project name of the new operator. (e.g app-operator)

--api-version and --kind are required flags to generate the new operator application.

For example,
For example:
$ mkdir $GOPATH/src/github.com/example.com/
$ cd $GOPATH/src/github.com/example.com/
$ operator-sdk new app-operator --api-group=app.example.com --kind=AppService
generates a skeletal app-operator application in $GOPATH/src/github.com/example.com/app-operator.
generates a skeletal app-operator application in $GOPATH/src/github.com/example.com/app-operator.
`,
Run: newFunc,
Run: newFunc,
}

newCmd.Flags().StringVar(&apiVersion, "api-version", "", "Kubernetes apiVersion and has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)")
newCmd.MarkFlagRequired("api-version")
newCmd.Flags().StringVar(&kind, "kind", "", "Kubernetes CustomResourceDefintion kind. (e.g AppService)")
newCmd.MarkFlagRequired("kind")

return newCmd
}

var (
Expand All @@ -42,14 +50,6 @@ const (
src = "src"
)

func init() {
RootCmd.AddCommand(newCmd)
newCmd.Flags().StringVar(&apiVersion, "api-version", "", "Kubernetes apiVersion and has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)")
newCmd.MarkFlagRequired("api-version")
newCmd.Flags().StringVar(&kind, "kind", "", "Kubernetes CustomResourceDefintion kind. (e.g AppService)")
newCmd.MarkFlagRequired("kind")
}

func newFunc(cmd *cobra.Command, args []string) {
if len(args) != 1 {
ExitWithError(ExitBadArgs, fmt.Errorf("new command needs 1 argument."))
Expand Down
15 changes: 11 additions & 4 deletions commands/operator-sdk/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ package cmd

import "github.com/spf13/cobra"

// This represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "operator-sdk",
Short: "A sdk for building operator with ease",
func NewRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "operator-sdk",
Short: "A sdk for building operator with ease",
}

cmd.AddCommand(NewNewCmd())
cmd.AddCommand(NewBuildCmd())
cmd.AddCommand(NewGenerateCmd())

return cmd
}
2 changes: 1 addition & 1 deletion commands/operator-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func main() {
if err := cmd.RootCmd.Execute(); err != nil {
if err := cmd.NewRootCmd().Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
Expand Down