diff --git a/Makefile b/Makefile index 88b16f63872..d26959878bb 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ endif VERSION = $(shell git describe --dirty --tags --always) REPO = github.com/operator-framework/operator-sdk -BUILD_PATH = $(REPO)/commands/operator-sdk +BUILD_PATH = $(REPO)/cmd/operator-sdk PKGS = $(shell go list ./... | grep -v /vendor/) SOURCES = $(shell find . -name '*.go' -not -path "*/vendor/*") @@ -85,7 +85,7 @@ test/sanity: ./hack/tests/sanity-check.sh test/unit: - $(Q)go test -count=1 -short ./commands/... + $(Q)go test -count=1 -short ./cmd/... $(Q)go test -count=1 -short ./pkg/... test/subcommand: test/subcommand/test-local test/subcommand/scorecard diff --git a/commands/operator-sdk/cmd/add/api.go b/cmd/operator-sdk/add/api.go similarity index 94% rename from commands/operator-sdk/cmd/add/api.go rename to cmd/operator-sdk/add/api.go index 0dc406493d8..d4a4327d426 100644 --- a/commands/operator-sdk/cmd/add/api.go +++ b/cmd/operator-sdk/add/api.go @@ -17,7 +17,7 @@ package add import ( "fmt" - "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/generate" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil" "github.com/operator-framework/operator-sdk/internal/util/projutil" "github.com/operator-framework/operator-sdk/pkg/scaffold" "github.com/operator-framework/operator-sdk/pkg/scaffold/input" @@ -32,7 +32,7 @@ var ( headerFile string ) -func NewApiCmd() *cobra.Command { +func newAddApiCmd() *cobra.Command { apiCmd := &cobra.Command{ Use: "api", Short: "Adds a new api definition under pkg/apis", @@ -124,12 +124,12 @@ func apiRun(cmd *cobra.Command, args []string) error { } // Run k8s codegen for deepcopy - if err := generate.K8sCodegen(headerFile); err != nil { + if err := genutil.K8sCodegen(headerFile); err != nil { return err } // Generate a validation spec for the new CRD. - if err := generate.OpenAPIGen(headerFile); err != nil { + if err := genutil.OpenAPIGen(headerFile); err != nil { return err } diff --git a/commands/operator-sdk/cmd/add.go b/cmd/operator-sdk/add/cmd.go similarity index 72% rename from commands/operator-sdk/cmd/add.go rename to cmd/operator-sdk/add/cmd.go index 69d6f8ca3af..fe6f7b6796b 100644 --- a/commands/operator-sdk/cmd/add.go +++ b/cmd/operator-sdk/add/cmd.go @@ -12,23 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package add import ( - "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/add" - "github.com/spf13/cobra" ) -func NewAddCmd() *cobra.Command { - upCmd := &cobra.Command{ +func NewCmd() *cobra.Command { + cmd := &cobra.Command{ Use: "add", Short: "Adds a controller or resource to the project", Long: "", } - upCmd.AddCommand(add.NewApiCmd()) - upCmd.AddCommand(add.NewControllerCmd()) - upCmd.AddCommand(add.NewAddCRDCmd()) - return upCmd + cmd.AddCommand(newAddApiCmd()) + cmd.AddCommand(newAddControllerCmd()) + cmd.AddCommand(newAddCRDCmd()) + return cmd } diff --git a/commands/operator-sdk/cmd/add/controller.go b/cmd/operator-sdk/add/controller.go similarity index 98% rename from commands/operator-sdk/cmd/add/controller.go rename to cmd/operator-sdk/add/controller.go index 88537dae052..d3ee17273a7 100644 --- a/commands/operator-sdk/cmd/add/controller.go +++ b/cmd/operator-sdk/add/controller.go @@ -25,7 +25,7 @@ import ( "github.com/spf13/cobra" ) -func NewControllerCmd() *cobra.Command { +func newAddControllerCmd() *cobra.Command { controllerCmd := &cobra.Command{ Use: "controller", Short: "Adds a new controller pkg", diff --git a/commands/operator-sdk/cmd/add/crd.go b/cmd/operator-sdk/add/crd.go similarity index 98% rename from commands/operator-sdk/cmd/add/crd.go rename to cmd/operator-sdk/add/crd.go index 2adb3cb8f0c..4c7c080924e 100644 --- a/commands/operator-sdk/cmd/add/crd.go +++ b/cmd/operator-sdk/add/crd.go @@ -28,8 +28,8 @@ import ( "github.com/spf13/cobra" ) -// NewAddCRDCmd - add crd command -func NewAddCRDCmd() *cobra.Command { +// newAddCRDCmd - add crd command +func newAddCRDCmd() *cobra.Command { crdCmd := &cobra.Command{ Use: "crd", Short: "Adds a Custom Resource Definition (CRD) and the Custom Resource (CR) files", diff --git a/commands/operator-sdk/cmd/build_test.go b/cmd/operator-sdk/build/build_test.go similarity index 99% rename from commands/operator-sdk/cmd/build_test.go rename to cmd/operator-sdk/build/build_test.go index 2fa1b2b2896..3f094acc163 100644 --- a/commands/operator-sdk/cmd/build_test.go +++ b/cmd/operator-sdk/build/build_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package build import "testing" diff --git a/commands/operator-sdk/cmd/build.go b/cmd/operator-sdk/build/cmd.go similarity index 99% rename from commands/operator-sdk/cmd/build.go rename to cmd/operator-sdk/build/cmd.go index 1dc1871c813..ebebb2fdff3 100644 --- a/commands/operator-sdk/cmd/build.go +++ b/cmd/operator-sdk/build/cmd.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package build import ( "errors" @@ -41,7 +41,7 @@ var ( dockerBuildArgs string ) -func NewBuildCmd() *cobra.Command { +func NewCmd() *cobra.Command { buildCmd := &cobra.Command{ Use: "build ", Short: "Compiles code and builds artifacts", diff --git a/commands/operator-sdk/cmd/completion/bash.go b/cmd/operator-sdk/completion/bash.go similarity index 96% rename from commands/operator-sdk/cmd/completion/bash.go rename to cmd/operator-sdk/completion/bash.go index 7e50bcfd930..a70921bf419 100644 --- a/commands/operator-sdk/cmd/completion/bash.go +++ b/cmd/operator-sdk/completion/bash.go @@ -20,7 +20,7 @@ import ( "github.com/spf13/cobra" ) -func NewBashCmd() *cobra.Command { +func newBashCmd() *cobra.Command { return &cobra.Command{ Use: "bash", Short: "Generate bash completions", diff --git a/commands/operator-sdk/cmd/completion.go b/cmd/operator-sdk/completion/cmd.go similarity index 76% rename from commands/operator-sdk/cmd/completion.go rename to cmd/operator-sdk/completion/cmd.go index ec3e43986df..259a16560a9 100644 --- a/commands/operator-sdk/cmd/completion.go +++ b/cmd/operator-sdk/completion/cmd.go @@ -12,20 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package completion import ( "github.com/spf13/cobra" - - "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/completion" ) -func NewCompletionCmd() *cobra.Command { +func NewCmd() *cobra.Command { completionCmd := &cobra.Command{ Use: "completion", Short: "Generators for shell completions", } - completionCmd.AddCommand(completion.NewZshCmd()) - completionCmd.AddCommand(completion.NewBashCmd()) + completionCmd.AddCommand(newZshCmd()) + completionCmd.AddCommand(newBashCmd()) return completionCmd } diff --git a/commands/operator-sdk/cmd/completion/zsh.go b/cmd/operator-sdk/completion/zsh.go similarity index 96% rename from commands/operator-sdk/cmd/completion/zsh.go rename to cmd/operator-sdk/completion/zsh.go index 89d9235b174..27597fcfb52 100644 --- a/commands/operator-sdk/cmd/completion/zsh.go +++ b/cmd/operator-sdk/completion/zsh.go @@ -20,7 +20,7 @@ import ( "github.com/spf13/cobra" ) -func NewZshCmd() *cobra.Command { +func newZshCmd() *cobra.Command { return &cobra.Command{ Use: "zsh", Short: "Generate zsh completions", diff --git a/commands/operator-sdk/cmd/generate.go b/cmd/operator-sdk/generate/cmd.go similarity index 78% rename from commands/operator-sdk/cmd/generate.go rename to cmd/operator-sdk/generate/cmd.go index 53dbbdcf8c3..d574ecc7c99 100644 --- a/commands/operator-sdk/cmd/generate.go +++ b/cmd/operator-sdk/generate/cmd.go @@ -12,21 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package generate import ( - "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/generate" - "github.com/spf13/cobra" ) -func NewGenerateCmd() *cobra.Command { +func NewCmd() *cobra.Command { cmd := &cobra.Command{ Use: "generate ", Short: "Invokes specific generator", Long: `The operator-sdk generate command invokes specific generator to generate code as needed.`, } - cmd.AddCommand(generate.NewGenerateK8SCmd()) - cmd.AddCommand(generate.NewGenerateOpenAPICmd()) + cmd.AddCommand(newGenerateK8SCmd()) + cmd.AddCommand(newGenerateOpenAPICmd()) return cmd } diff --git a/cmd/operator-sdk/generate/k8s.go b/cmd/operator-sdk/generate/k8s.go new file mode 100644 index 00000000000..21621ebde98 --- /dev/null +++ b/cmd/operator-sdk/generate/k8s.go @@ -0,0 +1,61 @@ +// Copyright 2019 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package generate + +import ( + "fmt" + + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil" + "github.com/operator-framework/operator-sdk/internal/util/projutil" + + "github.com/spf13/cobra" +) + +func newGenerateK8SCmd() *cobra.Command { + k8sCmd := &cobra.Command{ + Use: "k8s", + Short: "Generates Kubernetes code for custom resource", + Long: `k8s generator generates code for custom resources given the API +specs in pkg/apis// directories to comply with kube-API +requirements. Go code is generated under +pkg/apis///zz_generated.deepcopy.go. +Example: + $ operator-sdk generate k8s + $ tree pkg/apis + pkg/apis/ + └── app + └── v1alpha1 + ├── zz_generated.deepcopy.go +`, + RunE: k8sFunc, + } + + k8sCmd.Flags().StringVar(&headerFile, "header-file", "", "Path to file containing headers for generated files.") + + return k8sCmd +} + +func k8sFunc(cmd *cobra.Command, args []string) error { + if len(args) != 0 { + return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath()) + } + + // Only Go projects can generate k8s deepcopy code. + if err := projutil.CheckGoProjectCmd(cmd); err != nil { + return err + } + + return genutil.K8sCodegen(headerFile) +} diff --git a/cmd/operator-sdk/generate/openapi.go b/cmd/operator-sdk/generate/openapi.go new file mode 100644 index 00000000000..a777a21efd9 --- /dev/null +++ b/cmd/operator-sdk/generate/openapi.go @@ -0,0 +1,62 @@ +// Copyright 2019 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package generate + +import ( + "fmt" + + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil" + "github.com/spf13/cobra" +) + +var headerFile string + +func newGenerateOpenAPICmd() *cobra.Command { + openAPICmd := &cobra.Command{ + Use: "openapi", + Short: "Generates OpenAPI specs for API's", + Long: `generate openapi generates OpenAPI validation specs in Go from tagged types +in all pkg/apis// directories. Go code is generated under +pkg/apis///zz_generated.openapi.go. CRD's are generated, or +updated if they exist for a particular group + version + kind, under +deploy/crds/___crd.yaml; OpenAPI V3 validation YAML +is generated as a 'validation' object. + +Example: + $ operator-sdk generate openapi + $ tree pkg/apis + pkg/apis/ + └── app + └── v1alpha1 + ├── zz_generated.openapi.go + $ tree deploy/crds + ├── deploy/crds/app_v1alpha1_appservice_cr.yaml + ├── deploy/crds/app_v1alpha1_appservice_crd.yaml +`, + RunE: openAPIFunc, + } + + openAPICmd.Flags().StringVar(&headerFile, "header-file", "", "Path to file containing headers for generated files.") + + return openAPICmd +} + +func openAPIFunc(cmd *cobra.Command, args []string) error { + if len(args) != 0 { + return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath()) + } + + return genutil.OpenAPIGen(headerFile) +} diff --git a/commands/operator-sdk/cmd/generate/internal/genutil.go b/cmd/operator-sdk/internal/genutil/genutil.go similarity index 92% rename from commands/operator-sdk/cmd/generate/internal/genutil.go rename to cmd/operator-sdk/internal/genutil/genutil.go index 657155135fb..c0f119e2848 100644 --- a/commands/operator-sdk/cmd/generate/internal/genutil.go +++ b/cmd/operator-sdk/internal/genutil/genutil.go @@ -28,7 +28,7 @@ import ( log "github.com/sirupsen/logrus" ) -func BuildCodegenBinaries(genDirs []string, binDir, codegenSrcDir string) error { +func buildCodegenBinaries(genDirs []string, binDir, codegenSrcDir string) error { for _, gd := range genDirs { err := runGoBuildCodegen(binDir, codegenSrcDir, gd) if err != nil { @@ -56,7 +56,7 @@ func runGoBuildCodegen(binDir, repoDir, genDir string) error { // ParseGroupVersions parses the layout of pkg/apis to return a map of // API groups to versions. -func ParseGroupVersions() (map[string][]string, error) { +func parseGroupVersions() (map[string][]string, error) { gvs := make(map[string][]string) groups, err := ioutil.ReadDir(scaffold.ApisDir) if err != nil { @@ -89,7 +89,7 @@ func ParseGroupVersions() (map[string][]string, error) { // CreateFQApis return a string of all fully qualified pkg + groups + versions // of pkg and gvs in the format: // "pkg/groupA/v1,pkg/groupA/v2,pkg/groupB/v1" -func CreateFQApis(pkg string, gvs map[string][]string) string { +func createFQApis(pkg string, gvs map[string][]string) string { gn := 0 fqb := &strings.Builder{} for g, vs := range gvs { @@ -107,7 +107,7 @@ func CreateFQApis(pkg string, gvs map[string][]string) string { return fqb.String() } -func WithHeaderFile(hf string, f func(string) error) (err error) { +func withHeaderFile(hf string, f func(string) error) (err error) { if hf == "" { hf, err = createEmptyTmpFile() if err != nil { diff --git a/commands/operator-sdk/cmd/generate/k8s.go b/cmd/operator-sdk/internal/genutil/k8s.go similarity index 67% rename from commands/operator-sdk/cmd/generate/k8s.go rename to cmd/operator-sdk/internal/genutil/k8s.go index 01b6be0d84a..3bfa014ec91 100644 --- a/commands/operator-sdk/cmd/generate/k8s.go +++ b/cmd/operator-sdk/internal/genutil/k8s.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package generate +package genutil import ( "fmt" @@ -21,52 +21,12 @@ import ( "path/filepath" "strings" - genutil "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/generate/internal" "github.com/operator-framework/operator-sdk/internal/util/projutil" "github.com/operator-framework/operator-sdk/pkg/scaffold" log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" ) -func NewGenerateK8SCmd() *cobra.Command { - k8sCmd := &cobra.Command{ - Use: "k8s", - Short: "Generates Kubernetes code for custom resource", - Long: `k8s generator generates code for custom resources given the API -specs in pkg/apis// directories to comply with kube-API -requirements. Go code is generated under -pkg/apis///zz_generated.deepcopy.go. - -Example: - $ operator-sdk generate k8s - $ tree pkg/apis - pkg/apis/ - └── app - └── v1alpha1 - ├── zz_generated.deepcopy.go -`, - RunE: k8sFunc, - } - - k8sCmd.Flags().StringVar(&headerFile, "header-file", "", "Path to file containing headers for generated files.") - - return k8sCmd -} - -func k8sFunc(cmd *cobra.Command, args []string) error { - if len(args) != 0 { - return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath()) - } - - // Only Go projects can generate k8s deepcopy code. - if err := projutil.CheckGoProjectCmd(cmd); err != nil { - return err - } - - return K8sCodegen(headerFile) -} - // K8sCodegen performs deepcopy code-generation for all custom resources under // pkg/apis. hf is a path to a header file containing text to add to generated // files. @@ -78,11 +38,18 @@ func K8sCodegen(hf string) error { srcDir := filepath.Join(wd, "vendor", "k8s.io", "code-generator") binDir := filepath.Join(wd, scaffold.BuildBinDir) - if err := buildCodegenBinaries(binDir, srcDir); err != nil { + genDirs := []string{ + "./cmd/defaulter-gen", + "./cmd/client-gen", + "./cmd/lister-gen", + "./cmd/informer-gen", + "./cmd/deepcopy-gen", + } + if err := buildCodegenBinaries(genDirs, binDir, srcDir); err != nil { return err } - gvMap, err := genutil.ParseGroupVersions() + gvMap, err := parseGroupVersions() if err != nil { return fmt.Errorf("failed to parse group versions: (%v)", err) } @@ -94,11 +61,11 @@ func K8sCodegen(hf string) error { log.Infof("Running deepcopy code-generation for Custom Resource group versions: [%v]\n", gvb.String()) fdc := func(a string) error { return deepcopyGen(binDir, repoPkg, a, gvMap) } - if err = genutil.WithHeaderFile(hf, fdc); err != nil { + if err = withHeaderFile(hf, fdc); err != nil { return err } fd := func(a string) error { return defaulterGen(binDir, repoPkg, a, gvMap) } - if err = genutil.WithHeaderFile(hf, fd); err != nil { + if err = withHeaderFile(hf, fd); err != nil { return err } @@ -106,21 +73,10 @@ func K8sCodegen(hf string) error { return nil } -func buildCodegenBinaries(binDir, codegenSrcDir string) error { - genDirs := []string{ - "./cmd/defaulter-gen", - "./cmd/client-gen", - "./cmd/lister-gen", - "./cmd/informer-gen", - "./cmd/deepcopy-gen", - } - return genutil.BuildCodegenBinaries(genDirs, binDir, codegenSrcDir) -} - func deepcopyGen(binDir, repoPkg, hf string, gvMap map[string][]string) (err error) { apisPkg := filepath.Join(repoPkg, scaffold.ApisDir) args := []string{ - "--input-dirs", genutil.CreateFQApis(apisPkg, gvMap), + "--input-dirs", createFQApis(apisPkg, gvMap), "--output-file-base", "zz_generated.deepcopy", "--bounding-dirs", apisPkg, // deepcopy-gen requires a boilerplate file. Either use header or an @@ -144,7 +100,7 @@ func deepcopyGen(binDir, repoPkg, hf string, gvMap map[string][]string) (err err func defaulterGen(binDir, repoPkg, hf string, gvMap map[string][]string) (err error) { apisPkg := filepath.Join(repoPkg, scaffold.ApisDir) args := []string{ - "--input-dirs", genutil.CreateFQApis(apisPkg, gvMap), + "--input-dirs", createFQApis(apisPkg, gvMap), "--output-file-base", "zz_generated.defaults", // defaulter-gen requires a boilerplate file. Either use header or an // empty file if header is empty. diff --git a/commands/operator-sdk/cmd/generate/openapi.go b/cmd/operator-sdk/internal/genutil/openapi.go similarity index 69% rename from commands/operator-sdk/cmd/generate/openapi.go rename to cmd/operator-sdk/internal/genutil/openapi.go index f2a16acd50d..887846e13f8 100644 --- a/commands/operator-sdk/cmd/generate/openapi.go +++ b/cmd/operator-sdk/internal/genutil/openapi.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package generate +package genutil import ( "fmt" @@ -21,56 +21,14 @@ import ( "path/filepath" "strings" - genutil "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/generate/internal" "github.com/operator-framework/operator-sdk/internal/util/k8sutil" "github.com/operator-framework/operator-sdk/internal/util/projutil" "github.com/operator-framework/operator-sdk/pkg/scaffold" "github.com/operator-framework/operator-sdk/pkg/scaffold/input" log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" ) -var headerFile string - -func NewGenerateOpenAPICmd() *cobra.Command { - openAPICmd := &cobra.Command{ - Use: "openapi", - Short: "Generates OpenAPI specs for API's", - Long: `generate openapi generates OpenAPI validation specs in Go from tagged types -in all pkg/apis// directories. Go code is generated under -pkg/apis///zz_generated.openapi.go. CRD's are generated, or -updated if they exist for a particular group + version + kind, under -deploy/crds/___crd.yaml; OpenAPI V3 validation YAML -is generated as a 'validation' object. - -Example: - $ operator-sdk generate openapi - $ tree pkg/apis - pkg/apis/ - └── app - └── v1alpha1 - ├── zz_generated.openapi.go - $ tree deploy/crds - ├── deploy/crds/app_v1alpha1_appservice_cr.yaml - ├── deploy/crds/app_v1alpha1_appservice_crd.yaml -`, - RunE: openAPIFunc, - } - - openAPICmd.Flags().StringVar(&headerFile, "header-file", "", "Path to file containing headers for generated files.") - - return openAPICmd -} - -func openAPIFunc(cmd *cobra.Command, args []string) error { - if len(args) != 0 { - return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath()) - } - - return OpenAPIGen(headerFile) -} - // OpenAPIGen generates OpenAPI validation specs for all CRD's in dirs. hf is // a path to a header file containing text to add to generated files. func OpenAPIGen(hf string) error { @@ -85,7 +43,7 @@ func OpenAPIGen(hf string) error { return err } - gvMap, err := genutil.ParseGroupVersions() + gvMap, err := parseGroupVersions() if err != nil { return fmt.Errorf("failed to parse group versions: (%v)", err) } @@ -97,10 +55,10 @@ func OpenAPIGen(hf string) error { log.Infof("Running OpenAPI code-generation for Custom Resource group versions: [%v]\n", gvb.String()) apisPkg := filepath.Join(repoPkg, scaffold.ApisDir) - fqApiStr := genutil.CreateFQApis(apisPkg, gvMap) + fqApiStr := createFQApis(apisPkg, gvMap) fqApis := strings.Split(fqApiStr, ",") f := func(a string) error { return openAPIGen(binDir, a, fqApis) } - if err = genutil.WithHeaderFile(hf, f); err != nil { + if err = withHeaderFile(hf, f); err != nil { return err } @@ -141,7 +99,7 @@ func OpenAPIGen(hf string) error { func buildOpenAPIGenBinary(binDir, codegenSrcDir string) error { genDirs := []string{"./cmd/openapi-gen"} - return genutil.BuildCodegenBinaries(genDirs, binDir, codegenSrcDir) + return buildCodegenBinaries(genDirs, binDir, codegenSrcDir) } func openAPIGen(binDir, hf string, fqApis []string) (err error) { diff --git a/cmd/operator-sdk/main.go b/cmd/operator-sdk/main.go new file mode 100644 index 00000000000..8826dcaa10a --- /dev/null +++ b/cmd/operator-sdk/main.go @@ -0,0 +1,64 @@ +// Copyright 2019 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "os" + + // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) + // to ensure that `run` and `up local` can make use of them. + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/add" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/build" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/migrate" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/new" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/olmcatalog" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/printdeps" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/run" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/scorecard" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/test" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/up" + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/version" + osdkversion "github.com/operator-framework/operator-sdk/version" + "github.com/spf13/cobra" + _ "k8s.io/client-go/plugin/pkg/client/auth" +) + +func main() { + root := &cobra.Command{ + Use: "operator-sdk", + Short: "An SDK for building operators with ease", + Version: osdkversion.Version, + } + + root.AddCommand(new.NewCmd()) + root.AddCommand(add.NewCmd()) + root.AddCommand(build.NewCmd()) + root.AddCommand(generate.NewCmd()) + root.AddCommand(up.NewCmd()) + root.AddCommand(completion.NewCmd()) + root.AddCommand(test.NewCmd()) + root.AddCommand(scorecard.NewCmd()) + root.AddCommand(printdeps.NewCmd()) + root.AddCommand(migrate.NewCmd()) + root.AddCommand(run.NewCmd()) + root.AddCommand(olmcatalog.NewCmd()) + root.AddCommand(version.NewCmd()) + + if err := root.Execute(); err != nil { + os.Exit(1) + } +} diff --git a/commands/operator-sdk/cmd/migrate.go b/cmd/operator-sdk/migrate/cmd.go similarity index 96% rename from commands/operator-sdk/cmd/migrate.go rename to cmd/operator-sdk/migrate/cmd.go index 28f50ad2126..c044da04bfe 100644 --- a/commands/operator-sdk/cmd/migrate.go +++ b/cmd/operator-sdk/migrate/cmd.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package migrate import ( "fmt" @@ -29,8 +29,8 @@ import ( "github.com/spf13/cobra" ) -// NewMigrateCmd returns a command that will add source code to an existing non-go operator -func NewMigrateCmd() *cobra.Command { +// NewCmd returns a command that will add source code to an existing non-go operator +func NewCmd() *cobra.Command { return &cobra.Command{ Use: "migrate", Short: "Adds source code to an operator", diff --git a/commands/operator-sdk/cmd/new.go b/cmd/operator-sdk/new/cmd.go similarity index 99% rename from commands/operator-sdk/cmd/new.go rename to cmd/operator-sdk/new/cmd.go index 05988ea412c..de93c751579 100644 --- a/commands/operator-sdk/cmd/new.go +++ b/cmd/operator-sdk/new/cmd.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package new import ( "fmt" @@ -31,7 +31,7 @@ import ( "github.com/spf13/cobra" ) -func NewNewCmd() *cobra.Command { +func NewCmd() *cobra.Command { newCmd := &cobra.Command{ Use: "new ", Short: "Creates a new operator application", diff --git a/commands/operator-sdk/cmd/olm-catalog.go b/cmd/operator-sdk/olmcatalog/cmd.go similarity index 82% rename from commands/operator-sdk/cmd/olm-catalog.go rename to cmd/operator-sdk/olmcatalog/cmd.go index f068dfcf33e..af63ca322e1 100644 --- a/commands/operator-sdk/cmd/olm-catalog.go +++ b/cmd/operator-sdk/olmcatalog/cmd.go @@ -12,21 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package olmcatalog import ( - catalog "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/olm-catalog" - "github.com/spf13/cobra" ) -func NewOLMCatalogCmd() *cobra.Command { +func NewCmd() *cobra.Command { cmd := &cobra.Command{ Use: "olm-catalog ", Short: "Invokes a olm-catalog command", Long: `The operator-sdk olm-catalog command invokes a command to perform Catalog related actions.`, } - cmd.AddCommand(catalog.NewGenCSVCmd()) + cmd.AddCommand(newGenCSVCmd()) return cmd } diff --git a/commands/operator-sdk/cmd/olm-catalog/gen-csv.go b/cmd/operator-sdk/olmcatalog/gen-csv.go similarity index 98% rename from commands/operator-sdk/cmd/olm-catalog/gen-csv.go rename to cmd/operator-sdk/olmcatalog/gen-csv.go index 3a972344b7b..076e74140ff 100644 --- a/commands/operator-sdk/cmd/olm-catalog/gen-csv.go +++ b/cmd/operator-sdk/olmcatalog/gen-csv.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package catalog +package olmcatalog import ( "fmt" @@ -38,7 +38,7 @@ var ( updateCRDs bool ) -func NewGenCSVCmd() *cobra.Command { +func newGenCSVCmd() *cobra.Command { genCSVCmd := &cobra.Command{ Use: "gen-csv", Short: "Generates a Cluster Service Version yaml file for the operator", diff --git a/commands/operator-sdk/cmd/print_deps.go b/cmd/operator-sdk/printdeps/cmd.go similarity index 96% rename from commands/operator-sdk/cmd/print_deps.go rename to cmd/operator-sdk/printdeps/cmd.go index 090acb5e4a1..4b8cfd6ad21 100644 --- a/commands/operator-sdk/cmd/print_deps.go +++ b/cmd/operator-sdk/printdeps/cmd.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package printdeps import ( "fmt" @@ -24,7 +24,7 @@ import ( var asFile bool -func NewPrintDepsCmd() *cobra.Command { +func NewCmd() *cobra.Command { printDepsCmd := &cobra.Command{ Use: "print-deps", Short: "Print Golang packages and versions required to run the operator", diff --git a/commands/operator-sdk/cmd/run/ansible.go b/cmd/operator-sdk/run/ansible.go similarity index 92% rename from commands/operator-sdk/cmd/run/ansible.go rename to cmd/operator-sdk/run/ansible.go index 190323db6e3..cdbdbb25b9a 100644 --- a/commands/operator-sdk/cmd/run/ansible.go +++ b/cmd/operator-sdk/run/ansible.go @@ -23,8 +23,8 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" ) -// RunAnsibleCmd returns a command that will run an ansible operator. -func RunAnsibleCmd() *cobra.Command { +// newRunAnsibleCmd returns a command that will run an ansible operator. +func newRunAnsibleCmd() *cobra.Command { var flags *aoflags.AnsibleOperatorFlags runAnsibleCmd := &cobra.Command{ Use: "ansible", diff --git a/commands/operator-sdk/cmd/run.go b/cmd/operator-sdk/run/cmd.go similarity index 77% rename from commands/operator-sdk/cmd/run.go rename to cmd/operator-sdk/run/cmd.go index 1c2b35044d5..1513148ecaf 100644 --- a/commands/operator-sdk/cmd/run.go +++ b/cmd/operator-sdk/run/cmd.go @@ -12,17 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package run import ( - "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/run" - "github.com/spf13/cobra" ) -// NewRunCmd returns a command that contains subcommands to run specific +// NewCmd returns a command that contains subcommands to run specific // operator types. -func NewRunCmd() *cobra.Command { +func NewCmd() *cobra.Command { runCmd := &cobra.Command{ Use: "run", Short: "Runs a generic operator", @@ -31,7 +29,7 @@ in a Pod inside a cluster. Developers wanting to run their operator locally should use "up local" instead.`, } - runCmd.AddCommand(run.RunAnsibleCmd()) - runCmd.AddCommand(run.RunHelmCmd()) + runCmd.AddCommand(newRunAnsibleCmd()) + runCmd.AddCommand(newRunHelmCmd()) return runCmd } diff --git a/commands/operator-sdk/cmd/run/helm.go b/cmd/operator-sdk/run/helm.go similarity index 93% rename from commands/operator-sdk/cmd/run/helm.go rename to cmd/operator-sdk/run/helm.go index 122c96561dd..72834c1e9c9 100644 --- a/commands/operator-sdk/cmd/run/helm.go +++ b/cmd/operator-sdk/run/helm.go @@ -23,8 +23,8 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" ) -// RunHelmCmd returns a command that will run a helm operator. -func RunHelmCmd() *cobra.Command { +// newRunHelmCmd returns a command that will run a helm operator. +func newRunHelmCmd() *cobra.Command { var flags *hoflags.HelmOperatorFlags runHelmCmd := &cobra.Command{ Use: "helm", diff --git a/commands/operator-sdk/cmd/scorecard/basic_tests.go b/cmd/operator-sdk/scorecard/basic_tests.go similarity index 100% rename from commands/operator-sdk/cmd/scorecard/basic_tests.go rename to cmd/operator-sdk/scorecard/basic_tests.go diff --git a/cmd/operator-sdk/scorecard/cmd.go b/cmd/operator-sdk/scorecard/cmd.go new file mode 100644 index 00000000000..bff50795e24 --- /dev/null +++ b/cmd/operator-sdk/scorecard/cmd.go @@ -0,0 +1,81 @@ +// Copyright 2019 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scorecard + +import ( + "fmt" + "strings" + + "github.com/operator-framework/operator-sdk/pkg/scaffold" + "github.com/operator-framework/operator-sdk/version" + + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// scorecardConfig stores all scorecard config passed as flags +type scorecardConfig struct { + namespace string + kubeconfigPath string + initTimeout int + olmDeployed bool + csvPath string + basicTests bool + olmTests bool + tenantTests bool + namespacedManifest string + globalManifest string + crManifest string + proxyImage string + proxyPullPolicy string + crdsDir string + verbose bool +} + +var scConf scorecardConfig + +func NewCmd() *cobra.Command { + scorecardCmd := &cobra.Command{ + Use: "scorecard", + Short: "Run scorecard tests", + Long: `Runs blackbox scorecard tests on an operator +`, + RunE: ScorecardTests, + } + + scorecardCmd.Flags().StringVar(&ScorecardConf, ConfigOpt, "", "config file (default is /.osdk-yaml)") + scorecardCmd.Flags().StringVar(&scConf.namespace, NamespaceOpt, "", "Namespace of custom resource created in cluster") + scorecardCmd.Flags().StringVar(&scConf.kubeconfigPath, KubeconfigOpt, "", "Path to kubeconfig of custom resource created in cluster") + scorecardCmd.Flags().IntVar(&scConf.initTimeout, InitTimeoutOpt, 10, "Timeout for status block on CR to be created in seconds") + scorecardCmd.Flags().BoolVar(&scConf.olmDeployed, OlmDeployedOpt, false, "The OLM has deployed the operator. Use only the CSV for test data") + scorecardCmd.Flags().StringVar(&scConf.csvPath, CSVPathOpt, "", "Path to CSV being tested") + scorecardCmd.Flags().BoolVar(&scConf.basicTests, BasicTestsOpt, true, "Enable basic operator checks") + scorecardCmd.Flags().BoolVar(&scConf.olmTests, OLMTestsOpt, true, "Enable OLM integration checks") + scorecardCmd.Flags().BoolVar(&scConf.tenantTests, TenantTestsOpt, false, "Enable good tenant checks") + scorecardCmd.Flags().StringVar(&scConf.namespacedManifest, NamespacedManifestOpt, "", "Path to manifest for namespaced resources (e.g. RBAC and Operator manifest)") + scorecardCmd.Flags().StringVar(&scConf.globalManifest, GlobalManifestOpt, "", "Path to manifest for Global resources (e.g. CRD manifests)") + scorecardCmd.Flags().StringVar(&scConf.crManifest, CRManifestOpt, "", "Path to manifest for Custom Resource (required)") + scorecardCmd.Flags().StringVar(&scConf.proxyImage, ProxyImageOpt, fmt.Sprintf("quay.io/operator-framework/scorecard-proxy:%s", strings.TrimSuffix(version.Version, "+git")), "Image name for scorecard proxy") + scorecardCmd.Flags().StringVar(&scConf.proxyPullPolicy, ProxyPullPolicyOpt, "Always", "Pull policy for scorecard proxy image") + scorecardCmd.Flags().StringVar(&scConf.crdsDir, "crds-dir", scaffold.CRDsDir, "Directory containing CRDs (all CRD manifest filenames must have the suffix 'crd.yaml')") + scorecardCmd.Flags().BoolVar(&scConf.verbose, VerboseOpt, false, "Enable verbose logging") + + if err := viper.BindPFlags(scorecardCmd.Flags()); err != nil { + log.Fatalf("Failed to bind scorecard flags to viper: %v", err) + } + + return scorecardCmd +} diff --git a/commands/operator-sdk/cmd/scorecard/olm_tests.go b/cmd/operator-sdk/scorecard/olm_tests.go similarity index 100% rename from commands/operator-sdk/cmd/scorecard/olm_tests.go rename to cmd/operator-sdk/scorecard/olm_tests.go diff --git a/commands/operator-sdk/cmd/scorecard/resource_handler.go b/cmd/operator-sdk/scorecard/resource_handler.go similarity index 100% rename from commands/operator-sdk/cmd/scorecard/resource_handler.go rename to cmd/operator-sdk/scorecard/resource_handler.go diff --git a/commands/operator-sdk/cmd/scorecard/scorecard.go b/cmd/operator-sdk/scorecard/scorecard.go similarity index 100% rename from commands/operator-sdk/cmd/scorecard/scorecard.go rename to cmd/operator-sdk/scorecard/scorecard.go diff --git a/commands/operator-sdk/cmd/scorecard/test_definitions.go b/cmd/operator-sdk/scorecard/test_definitions.go similarity index 100% rename from commands/operator-sdk/cmd/scorecard/test_definitions.go rename to cmd/operator-sdk/scorecard/test_definitions.go diff --git a/commands/operator-sdk/cmd/test/cluster.go b/cmd/operator-sdk/test/cluster.go similarity index 99% rename from commands/operator-sdk/cmd/test/cluster.go rename to cmd/operator-sdk/test/cluster.go index ac7fba9c268..ecefbb7cd8a 100755 --- a/commands/operator-sdk/cmd/test/cluster.go +++ b/cmd/operator-sdk/test/cluster.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmdtest +package test import ( "bytes" @@ -46,7 +46,7 @@ type testClusterConfig struct { var tcConfig testClusterConfig -func NewTestClusterCmd() *cobra.Command { +func newTestClusterCmd() *cobra.Command { testCmd := &cobra.Command{ Use: "cluster [flags]", Short: "Run End-To-End tests using image with embedded test binary", diff --git a/commands/operator-sdk/cmd/test.go b/cmd/operator-sdk/test/cmd.go similarity index 79% rename from commands/operator-sdk/cmd/test.go rename to cmd/operator-sdk/test/cmd.go index 9f7cea7e80f..a955bd744f3 100644 --- a/commands/operator-sdk/cmd/test.go +++ b/cmd/operator-sdk/test/cmd.go @@ -12,15 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package test import ( - "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/test" - "github.com/spf13/cobra" ) -func NewTestCmd() *cobra.Command { +func NewCmd() *cobra.Command { testCmd := &cobra.Command{ Use: "test", Short: "Tests the operator", @@ -28,7 +26,7 @@ func NewTestCmd() *cobra.Command { `, } - testCmd.AddCommand(cmdtest.NewTestLocalCmd()) - testCmd.AddCommand(cmdtest.NewTestClusterCmd()) + testCmd.AddCommand(newTestLocalCmd()) + testCmd.AddCommand(newTestClusterCmd()) return testCmd } diff --git a/commands/operator-sdk/cmd/test/local.go b/cmd/operator-sdk/test/local.go similarity index 99% rename from commands/operator-sdk/cmd/test/local.go rename to cmd/operator-sdk/test/local.go index 5577e124502..06ef59d86a8 100644 --- a/commands/operator-sdk/cmd/test/local.go +++ b/cmd/operator-sdk/test/local.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmdtest +package test import ( "fmt" @@ -54,7 +54,7 @@ type testLocalConfig struct { var tlConfig testLocalConfig -func NewTestLocalCmd() *cobra.Command { +func newTestLocalCmd() *cobra.Command { testCmd := &cobra.Command{ Use: "local [flags]", Short: "Run End-To-End tests locally", diff --git a/commands/operator-sdk/cmd/up.go b/cmd/operator-sdk/up/cmd.go similarity index 84% rename from commands/operator-sdk/cmd/up.go rename to cmd/operator-sdk/up/cmd.go index 4ae072159e5..98f636faf0b 100644 --- a/commands/operator-sdk/cmd/up.go +++ b/cmd/operator-sdk/up/cmd.go @@ -12,15 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package up import ( - "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/up" - "github.com/spf13/cobra" ) -func NewUpCmd() *cobra.Command { +func NewCmd() *cobra.Command { upCmd := &cobra.Command{ Use: "up", Short: "Launches the operator", @@ -28,6 +26,6 @@ func NewUpCmd() *cobra.Command { `, } - upCmd.AddCommand(up.NewLocalCmd()) + upCmd.AddCommand(newLocalCmd()) return upCmd } diff --git a/commands/operator-sdk/cmd/up/local.go b/cmd/operator-sdk/up/local.go similarity index 98% rename from commands/operator-sdk/cmd/up/local.go rename to cmd/operator-sdk/up/local.go index db0b7093735..9c115277291 100644 --- a/commands/operator-sdk/cmd/up/local.go +++ b/cmd/operator-sdk/up/local.go @@ -40,8 +40,8 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" ) -// NewLocalCmd - up local command to run an operator loccally -func NewLocalCmd() *cobra.Command { +// newLocalCmd - up local command to run an operator loccally +func newLocalCmd() *cobra.Command { upLocalCmd := &cobra.Command{ Use: "local", Short: "Launches the operator locally", diff --git a/commands/operator-sdk/cmd/version.go b/cmd/operator-sdk/version/cmd.go similarity index 94% rename from commands/operator-sdk/cmd/version.go rename to cmd/operator-sdk/version/cmd.go index 0cf756df705..dbc369f59ba 100644 --- a/commands/operator-sdk/cmd/version.go +++ b/cmd/operator-sdk/version/cmd.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cmd +package version import ( "fmt" @@ -22,7 +22,7 @@ import ( "github.com/spf13/cobra" ) -func NewVersionCmd() *cobra.Command { +func NewCmd() *cobra.Command { versionCmd := &cobra.Command{ Use: "version", Short: "Prints the version of operator-sdk", diff --git a/commands/operator-sdk/cmd/root.go b/commands/operator-sdk/cmd/root.go deleted file mode 100644 index bbfdd6ebf39..00000000000 --- a/commands/operator-sdk/cmd/root.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cmd - -import ( - "github.com/spf13/cobra" - - "github.com/operator-framework/operator-sdk/version" -) - -func NewRootCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "operator-sdk", - Short: "An SDK for building operators with ease", - Version: version.Version, - } - - cmd.AddCommand(NewNewCmd()) - cmd.AddCommand(NewAddCmd()) - cmd.AddCommand(NewBuildCmd()) - cmd.AddCommand(NewGenerateCmd()) - cmd.AddCommand(NewUpCmd()) - cmd.AddCommand(NewCompletionCmd()) - cmd.AddCommand(NewTestCmd()) - cmd.AddCommand(NewScorecardCmd()) - cmd.AddCommand(NewPrintDepsCmd()) - cmd.AddCommand(NewMigrateCmd()) - cmd.AddCommand(NewRunCmd()) - cmd.AddCommand(NewOLMCatalogCmd()) - cmd.AddCommand(NewVersionCmd()) - - return cmd -} diff --git a/commands/operator-sdk/cmd/scorecard.go b/commands/operator-sdk/cmd/scorecard.go deleted file mode 100644 index e514eb34e91..00000000000 --- a/commands/operator-sdk/cmd/scorecard.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2019 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cmd - -import ( - "fmt" - "strings" - - "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/scorecard" - "github.com/operator-framework/operator-sdk/pkg/scaffold" - "github.com/operator-framework/operator-sdk/version" - - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" - "github.com/spf13/viper" -) - -// scorecardConfig stores all scorecard config passed as flags -type scorecardConfig struct { - namespace string - kubeconfigPath string - initTimeout int - olmDeployed bool - csvPath string - basicTests bool - olmTests bool - tenantTests bool - namespacedManifest string - globalManifest string - crManifest string - proxyImage string - proxyPullPolicy string - crdsDir string - verbose bool -} - -var scConf scorecardConfig - -func NewScorecardCmd() *cobra.Command { - scorecardCmd := &cobra.Command{ - Use: "scorecard", - Short: "Run scorecard tests", - Long: `Runs blackbox scorecard tests on an operator -`, - RunE: scorecard.ScorecardTests, - } - - scorecardCmd.Flags().StringVar(&scorecard.ScorecardConf, scorecard.ConfigOpt, "", "config file (default is /.osdk-scorecard.yaml)") - scorecardCmd.Flags().StringVar(&scConf.namespace, scorecard.NamespaceOpt, "", "Namespace of custom resource created in cluster") - scorecardCmd.Flags().StringVar(&scConf.kubeconfigPath, scorecard.KubeconfigOpt, "", "Path to kubeconfig of custom resource created in cluster") - scorecardCmd.Flags().IntVar(&scConf.initTimeout, scorecard.InitTimeoutOpt, 10, "Timeout for status block on CR to be created in seconds") - scorecardCmd.Flags().BoolVar(&scConf.olmDeployed, scorecard.OlmDeployedOpt, false, "The OLM has deployed the operator. Use only the CSV for test data") - scorecardCmd.Flags().StringVar(&scConf.csvPath, scorecard.CSVPathOpt, "", "Path to CSV being tested") - scorecardCmd.Flags().BoolVar(&scConf.basicTests, scorecard.BasicTestsOpt, true, "Enable basic operator checks") - scorecardCmd.Flags().BoolVar(&scConf.olmTests, scorecard.OLMTestsOpt, true, "Enable OLM integration checks") - scorecardCmd.Flags().BoolVar(&scConf.tenantTests, scorecard.TenantTestsOpt, false, "Enable good tenant checks") - scorecardCmd.Flags().StringVar(&scConf.namespacedManifest, scorecard.NamespacedManifestOpt, "", "Path to manifest for namespaced resources (e.g. RBAC and Operator manifest)") - scorecardCmd.Flags().StringVar(&scConf.globalManifest, scorecard.GlobalManifestOpt, "", "Path to manifest for Global resources (e.g. CRD manifests)") - scorecardCmd.Flags().StringVar(&scConf.crManifest, scorecard.CRManifestOpt, "", "Path to manifest for Custom Resource (required)") - scorecardCmd.Flags().StringVar(&scConf.proxyImage, scorecard.ProxyImageOpt, fmt.Sprintf("quay.io/operator-framework/scorecard-proxy:%s", strings.TrimSuffix(version.Version, "+git")), "Image name for scorecard proxy") - scorecardCmd.Flags().StringVar(&scConf.proxyPullPolicy, scorecard.ProxyPullPolicyOpt, "Always", "Pull policy for scorecard proxy image") - scorecardCmd.Flags().StringVar(&scConf.crdsDir, "crds-dir", scaffold.CRDsDir, "Directory containing CRDs (all CRD manifest filenames must have the suffix 'crd.yaml')") - scorecardCmd.Flags().BoolVar(&scConf.verbose, scorecard.VerboseOpt, false, "Enable verbose logging") - - if err := viper.BindPFlags(scorecardCmd.Flags()); err != nil { - log.Fatalf("Failed to bind scorecard flags to viper: %v", err) - } - - return scorecardCmd -} diff --git a/commands/operator-sdk/main.go b/commands/operator-sdk/main.go deleted file mode 100644 index 4c162d0fcd5..00000000000 --- a/commands/operator-sdk/main.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "os" - - // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) - // to ensure that `run` and `up local` can make use of them. - _ "k8s.io/client-go/plugin/pkg/client/auth" - - "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd" -) - -func main() { - if err := cmd.NewRootCmd().Execute(); err != nil { - os.Exit(1) - } -} diff --git a/hack/lib/test_lib.sh b/hack/lib/test_lib.sh index 51d80f4ba46..ee68081be8d 100644 --- a/hack/lib/test_lib.sh +++ b/hack/lib/test_lib.sh @@ -3,7 +3,7 @@ source hack/lib/common.sh function listPkgs() { - go list ./commands/... ./pkg/... ./test/... | grep -v generated + go list ./cmd/... ./pkg/... ./test/... | grep -v generated } function listFiles() {