Skip to content

Commit 66294ed

Browse files
committed
Merge branch 'master' into v1-scaffold
2 parents fac856e + 147862c commit 66294ed

File tree

43 files changed

+401
-383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+401
-383
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ endif
1111

1212
VERSION = $(shell git describe --dirty --tags --always)
1313
REPO = github.com/operator-framework/operator-sdk
14-
BUILD_PATH = $(REPO)/commands/operator-sdk
14+
BUILD_PATH = $(REPO)/cmd/operator-sdk
1515
PKGS = $(shell go list ./... | grep -v /vendor/)
1616
SOURCES = $(shell find . -name '*.go' -not -path "*/vendor/*")
1717

@@ -85,7 +85,7 @@ test/sanity:
8585
./hack/tests/sanity-check.sh
8686

8787
test/unit:
88-
$(Q)go test -count=1 -short ./commands/...
88+
$(Q)go test -count=1 -short ./cmd/...
8989
$(Q)go test -count=1 -short ./pkg/...
9090

9191
test/subcommand: test/subcommand/test-local test/subcommand/scorecard

commands/operator-sdk/cmd/add/api.go renamed to cmd/operator-sdk/add/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package add
1717
import (
1818
"fmt"
1919

20-
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/generate"
20+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil"
2121
"github.com/operator-framework/operator-sdk/internal/util/projutil"
2222
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold"
2323
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input"
@@ -32,7 +32,7 @@ var (
3232
headerFile string
3333
)
3434

35-
func NewApiCmd() *cobra.Command {
35+
func newAddApiCmd() *cobra.Command {
3636
apiCmd := &cobra.Command{
3737
Use: "api",
3838
Short: "Adds a new api definition under pkg/apis",
@@ -124,12 +124,12 @@ func apiRun(cmd *cobra.Command, args []string) error {
124124
}
125125

126126
// Run k8s codegen for deepcopy
127-
if err := generate.K8sCodegen(headerFile); err != nil {
127+
if err := genutil.K8sCodegen(headerFile); err != nil {
128128
return err
129129
}
130130

131131
// Generate a validation spec for the new CRD.
132-
if err := generate.OpenAPIGen(headerFile); err != nil {
132+
if err := genutil.OpenAPIGen(headerFile); err != nil {
133133
return err
134134
}
135135

commands/operator-sdk/cmd/add.go renamed to cmd/operator-sdk/add/cmd.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,21 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package cmd
15+
package add
1616

1717
import (
18-
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/add"
19-
2018
"github.com/spf13/cobra"
2119
)
2220

23-
func NewAddCmd() *cobra.Command {
24-
upCmd := &cobra.Command{
21+
func NewCmd() *cobra.Command {
22+
cmd := &cobra.Command{
2523
Use: "add",
2624
Short: "Adds a controller or resource to the project",
2725
Long: "",
2826
}
2927

30-
upCmd.AddCommand(add.NewApiCmd())
31-
upCmd.AddCommand(add.NewControllerCmd())
32-
upCmd.AddCommand(add.NewAddCRDCmd())
33-
return upCmd
28+
cmd.AddCommand(newAddApiCmd())
29+
cmd.AddCommand(newAddControllerCmd())
30+
cmd.AddCommand(newAddCRDCmd())
31+
return cmd
3432
}

commands/operator-sdk/cmd/add/controller.go renamed to cmd/operator-sdk/add/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/spf13/cobra"
2626
)
2727

28-
func NewControllerCmd() *cobra.Command {
28+
func newAddControllerCmd() *cobra.Command {
2929
controllerCmd := &cobra.Command{
3030
Use: "controller",
3131
Short: "Adds a new controller pkg",

commands/operator-sdk/cmd/add/crd.go renamed to cmd/operator-sdk/add/crd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
"github.com/spf13/cobra"
2929
)
3030

31-
// NewAddCRDCmd - add crd command
32-
func NewAddCRDCmd() *cobra.Command {
31+
// newAddCRDCmd - add crd command
32+
func newAddCRDCmd() *cobra.Command {
3333
crdCmd := &cobra.Command{
3434
Use: "crd",
3535
Short: "Adds a Custom Resource Definition (CRD) and the Custom Resource (CR) files",

commands/operator-sdk/cmd/build_test.go renamed to cmd/operator-sdk/build/build_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package cmd
15+
package build
1616

1717
import "testing"
1818

commands/operator-sdk/cmd/build.go renamed to cmd/operator-sdk/build/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package cmd
15+
package build
1616

1717
import (
1818
"errors"
@@ -41,7 +41,7 @@ var (
4141
dockerBuildArgs string
4242
)
4343

44-
func NewBuildCmd() *cobra.Command {
44+
func NewCmd() *cobra.Command {
4545
buildCmd := &cobra.Command{
4646
Use: "build <image>",
4747
Short: "Compiles code and builds artifacts",

commands/operator-sdk/cmd/completion/bash.go renamed to cmd/operator-sdk/completion/bash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/spf13/cobra"
2121
)
2222

23-
func NewBashCmd() *cobra.Command {
23+
func newBashCmd() *cobra.Command {
2424
return &cobra.Command{
2525
Use: "bash",
2626
Short: "Generate bash completions",

commands/operator-sdk/cmd/completion.go renamed to cmd/operator-sdk/completion/cmd.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package cmd
15+
package completion
1616

1717
import (
1818
"github.com/spf13/cobra"
19-
20-
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/completion"
2119
)
2220

23-
func NewCompletionCmd() *cobra.Command {
21+
func NewCmd() *cobra.Command {
2422
completionCmd := &cobra.Command{
2523
Use: "completion",
2624
Short: "Generators for shell completions",
2725
}
28-
completionCmd.AddCommand(completion.NewZshCmd())
29-
completionCmd.AddCommand(completion.NewBashCmd())
26+
completionCmd.AddCommand(newZshCmd())
27+
completionCmd.AddCommand(newBashCmd())
3028
return completionCmd
3129
}

commands/operator-sdk/cmd/completion/zsh.go renamed to cmd/operator-sdk/completion/zsh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/spf13/cobra"
2121
)
2222

23-
func NewZshCmd() *cobra.Command {
23+
func newZshCmd() *cobra.Command {
2424
return &cobra.Command{
2525
Use: "zsh",
2626
Short: "Generate zsh completions",

commands/operator-sdk/cmd/generate.go renamed to cmd/operator-sdk/generate/cmd.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package cmd
15+
package generate
1616

1717
import (
18-
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/generate"
19-
2018
"github.com/spf13/cobra"
2119
)
2220

23-
func NewGenerateCmd() *cobra.Command {
21+
func NewCmd() *cobra.Command {
2422
cmd := &cobra.Command{
2523
Use: "generate <generator>",
2624
Short: "Invokes specific generator",
2725
Long: `The operator-sdk generate command invokes specific generator to generate code as needed.`,
2826
}
29-
cmd.AddCommand(generate.NewGenerateK8SCmd())
30-
cmd.AddCommand(generate.NewGenerateOpenAPICmd())
27+
cmd.AddCommand(newGenerateK8SCmd())
28+
cmd.AddCommand(newGenerateOpenAPICmd())
3129
return cmd
3230
}

cmd/operator-sdk/generate/k8s.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2019 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package generate
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil"
21+
"github.com/operator-framework/operator-sdk/internal/util/projutil"
22+
23+
"github.com/spf13/cobra"
24+
)
25+
26+
func newGenerateK8SCmd() *cobra.Command {
27+
k8sCmd := &cobra.Command{
28+
Use: "k8s",
29+
Short: "Generates Kubernetes code for custom resource",
30+
Long: `k8s generator generates code for custom resources given the API
31+
specs in pkg/apis/<group>/<version> directories to comply with kube-API
32+
requirements. Go code is generated under
33+
pkg/apis/<group>/<version>/zz_generated.deepcopy.go.
34+
Example:
35+
$ operator-sdk generate k8s
36+
$ tree pkg/apis
37+
pkg/apis/
38+
└── app
39+
└── v1alpha1
40+
├── zz_generated.deepcopy.go
41+
`,
42+
RunE: k8sFunc,
43+
}
44+
45+
k8sCmd.Flags().StringVar(&headerFile, "header-file", "", "Path to file containing headers for generated files.")
46+
47+
return k8sCmd
48+
}
49+
50+
func k8sFunc(cmd *cobra.Command, args []string) error {
51+
if len(args) != 0 {
52+
return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath())
53+
}
54+
55+
// Only Go projects can generate k8s deepcopy code.
56+
if err := projutil.CheckGoProjectCmd(cmd); err != nil {
57+
return err
58+
}
59+
60+
return genutil.K8sCodegen(headerFile)
61+
}

cmd/operator-sdk/generate/openapi.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2019 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package generate
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil"
21+
"github.com/spf13/cobra"
22+
)
23+
24+
var headerFile string
25+
26+
func newGenerateOpenAPICmd() *cobra.Command {
27+
openAPICmd := &cobra.Command{
28+
Use: "openapi",
29+
Short: "Generates OpenAPI specs for API's",
30+
Long: `generate openapi generates OpenAPI validation specs in Go from tagged types
31+
in all pkg/apis/<group>/<version> directories. Go code is generated under
32+
pkg/apis/<group>/<version>/zz_generated.openapi.go. CRD's are generated, or
33+
updated if they exist for a particular group + version + kind, under
34+
deploy/crds/<group>_<version>_<kind>_crd.yaml; OpenAPI V3 validation YAML
35+
is generated as a 'validation' object.
36+
37+
Example:
38+
$ operator-sdk generate openapi
39+
$ tree pkg/apis
40+
pkg/apis/
41+
└── app
42+
└── v1alpha1
43+
├── zz_generated.openapi.go
44+
$ tree deploy/crds
45+
├── deploy/crds/app_v1alpha1_appservice_cr.yaml
46+
├── deploy/crds/app_v1alpha1_appservice_crd.yaml
47+
`,
48+
RunE: openAPIFunc,
49+
}
50+
51+
openAPICmd.Flags().StringVar(&headerFile, "header-file", "", "Path to file containing headers for generated files.")
52+
53+
return openAPICmd
54+
}
55+
56+
func openAPIFunc(cmd *cobra.Command, args []string) error {
57+
if len(args) != 0 {
58+
return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath())
59+
}
60+
61+
return genutil.OpenAPIGen(headerFile)
62+
}

commands/operator-sdk/cmd/generate/internal/genutil.go renamed to cmd/operator-sdk/internal/genutil/genutil.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
log "github.com/sirupsen/logrus"
2929
)
3030

31-
func BuildCodegenBinaries(genDirs []string, binDir, codegenSrcDir string) error {
31+
func buildCodegenBinaries(genDirs []string, binDir, codegenSrcDir string) error {
3232
for _, gd := range genDirs {
3333
err := runGoBuildCodegen(binDir, codegenSrcDir, gd)
3434
if err != nil {
@@ -56,7 +56,7 @@ func runGoBuildCodegen(binDir, repoDir, genDir string) error {
5656

5757
// ParseGroupVersions parses the layout of pkg/apis to return a map of
5858
// API groups to versions.
59-
func ParseGroupVersions() (map[string][]string, error) {
59+
func parseGroupVersions() (map[string][]string, error) {
6060
gvs := make(map[string][]string)
6161
groups, err := ioutil.ReadDir(scaffold.ApisDir)
6262
if err != nil {
@@ -89,7 +89,7 @@ func ParseGroupVersions() (map[string][]string, error) {
8989
// CreateFQApis return a string of all fully qualified pkg + groups + versions
9090
// of pkg and gvs in the format:
9191
// "pkg/groupA/v1,pkg/groupA/v2,pkg/groupB/v1"
92-
func CreateFQApis(pkg string, gvs map[string][]string) string {
92+
func createFQApis(pkg string, gvs map[string][]string) string {
9393
gn := 0
9494
fqb := &strings.Builder{}
9595
for g, vs := range gvs {
@@ -107,7 +107,7 @@ func CreateFQApis(pkg string, gvs map[string][]string) string {
107107
return fqb.String()
108108
}
109109

110-
func WithHeaderFile(hf string, f func(string) error) (err error) {
110+
func withHeaderFile(hf string, f func(string) error) (err error) {
111111
if hf == "" {
112112
hf, err = createEmptyTmpFile()
113113
if err != nil {

0 commit comments

Comments
 (0)