diff --git a/commands/operator-sdk/cmd/new.go b/commands/operator-sdk/cmd/new.go index 34e2fed530..9227d38b35 100644 --- a/commands/operator-sdk/cmd/new.go +++ b/commands/operator-sdk/cmd/new.go @@ -17,7 +17,7 @@ var newCmd = &cobra.Command{ is the project name of the new operator. (e.g app-operator) - --api-group and --kind are required flags to generate the new operator application. + --api-version and --kind are required flags to generate the new operator application. For example, $ mkdir $GOPATH/src/github.com/example.com/ @@ -29,15 +29,15 @@ var newCmd = &cobra.Command{ } var ( - apiGroup string + apiVersion string kind string projectName string ) func init() { RootCmd.AddCommand(newCmd) - newCmd.Flags().StringVar(&apiGroup, "api-group", "", "Kubernetes API Group and has a format of $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)") - newCmd.MarkFlagRequired("api-group") + 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") } @@ -48,7 +48,7 @@ func newFunc(cmd *cobra.Command, args []string) { } parse(args) verifyFlags() - g := generator.NewGenerator(apiGroup, kind, projectName) + g := generator.NewGenerator(apiVersion, kind, projectName) err := g.Render() if err != nil { ExitWithError(ExitError, fmt.Errorf("failed to create project %v: %v", projectName, err)) diff --git a/pkg/generator/generator.go b/pkg/generator/generator.go index 60022f8ef9..21bdf0b665 100644 --- a/pkg/generator/generator.go +++ b/pkg/generator/generator.go @@ -20,16 +20,17 @@ const ( ) type Generator struct { - apiGroup string - kind string + // apiVersion is the kubernetes apiVersion that has the format of $GROUP_NAME/$VERSION. + apiVersion string + kind string // projectName is name of the new operator application // and is also the name of the base directory. projectName string } // NewGenerator creates a new scaffold Generator. -func NewGenerator(apiGroup, kind, projectName string) *Generator { - return &Generator{apiGroup: apiGroup, kind: kind, projectName: projectName} +func NewGenerator(apiVersion, kind, projectName string) *Generator { + return &Generator{apiVersion: apiVersion, kind: kind, projectName: projectName} } // Render generates the default project structure: @@ -41,8 +42,8 @@ func NewGenerator(apiGroup, kind, projectName string) *Generator { // │ ├── deploy // │ ├── pkg // │ │ ├── apis -// │ │ │ └── // computed from apiDirName(apiGroup). -// │ │ │ └── // computed from apiVersion(apiGroup). +// │ │ │ └── // computed from apiDirName(apiVersion). +// │ │ │ └── // computed from version(apiVersion). // │ │ └── stub // │ └── tmp // │ ├── build @@ -99,7 +100,7 @@ func (g *Generator) renderTmp() error { } func (g *Generator) renderPkg() error { - if err := os.MkdirAll(filepath.Join(g.projectName, apisDir, apiDirName(g.apiGroup), apiVersion(g.apiGroup)), defaultFileMode); err != nil { + if err := os.MkdirAll(filepath.Join(g.projectName, apisDir, apiDirName(g.apiVersion), version(g.apiVersion)), defaultFileMode); err != nil { return err } if err := os.MkdirAll(filepath.Join(g.projectName, stubDir), defaultFileMode); err != nil { @@ -109,18 +110,19 @@ func (g *Generator) renderPkg() error { return nil } -// apiVersion extracts api version from the given apiGroup. -func apiVersion(apiGroup string) string { - return strings.Split(apiGroup, "/")[1] +// version extracts the VERSION from the given apiVersion ($GROUP_NAME/$VERSION). +func version(apiVersion string) string { + return strings.Split(apiVersion, "/")[1] } -// groupName extracts the group name from the givem apiGroup. -func groupName(apiGroup string) string { - return strings.Split(apiGroup, "/")[0] +// groupName extracts the GROUP_NAME from the given apiVersion ($GROUP_NAME/$VERSION). +func groupName(apiVersion string) string { + return strings.Split(apiVersion, "/")[0] } -// apiDirName extracts the name of api directory under ../apis/ from the apiGroup. -// it uses the first word separated with "." of the groupName as the api directory name. +// apiDirName extracts the name of api directory under ../apis/ folder +// from the given apiVersion ($GROUP_NAME/$VERSION). +// the first word separated with "." of the GROUP_NAME is the api directory name. // for example, // apiDirName("app.example.com/v1alpha1") => "app". func apiDirName(apiGroup string) string {