Skip to content

Commit

Permalink
Check the error from CodeGenerator Execute
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Jun 23, 2018
1 parent 06c1e62 commit 84d9376
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
10 changes: 8 additions & 2 deletions cmd/kubebuilder/create/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"log"
"path/filepath"

"github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/util"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -57,8 +58,13 @@ kubebuilder create config --crds --output myextensionname.yaml
fmt.Printf("Must either specify the name of the extension with --name or set --crds.\n")
return
}
CodeGenerator{SkipMapValidation: skipMapValidation}.Execute()
log.Printf("Config written to %s", output)
generated, err := CodeGenerator{SkipMapValidation: skipMapValidation}.Execute()
if err != nil {
fmt.Printf("%v\n", err)
} else {
util.WriteString(output, generated)
log.Printf("Config written to %s", output)
}
},
}

Expand Down
17 changes: 7 additions & 10 deletions cmd/kubebuilder/create/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/ghodss/yaml"
"github.com/golang/glog"
"github.com/kubernetes-sigs/kubebuilder/cmd/internal/codegen/parse"
"github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/util"
"github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/version"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -36,7 +35,7 @@ import (
)

// CodeGenerator generates code for Kubernetes resources and controllers
type CodeGenerator struct{
type CodeGenerator struct {
SkipMapValidation bool
}

Expand All @@ -53,28 +52,27 @@ func addLabels(m map[string]string) map[string]string {
}

// Execute parses packages and executes the code generators against the resource and controller packages
func (g CodeGenerator) Execute() error {
func (g CodeGenerator) Execute() (string, error) {
arguments := args.Default()
b, err := arguments.NewBuilder()
if err != nil {
return fmt.Errorf("Failed making a parser: %v", err)
return "", fmt.Errorf("Failed making a parser: %v", err)
}
for _, d := range []string{"./pkg/apis", "./pkg/controller", "./pkg/inject"} {
if err := b.AddDirRecursive(d); err != nil {
return fmt.Errorf("Failed making a parser: %v", err)
return "", fmt.Errorf("Failed making a parser: %v", err)
}
}
c, err := parse.NewContext(b)
if err != nil {
return fmt.Errorf("Failed making a context: %v", err)
return "", fmt.Errorf("Failed making a context: %v", err)
}

arguments.CustomArgs = &parse.ParseOptions{SkipMapValidation: g.SkipMapValidation}

p := parse.NewAPIs(c, arguments)
if crds {
util.WriteString(output, strings.Join(getCrds(p), "---\n"))
return nil
return strings.Join(getCrds(p), "---\n"), nil
}

result := append([]string{},
Expand All @@ -90,8 +88,7 @@ func (g CodeGenerator) Execute() error {
result = append(result, getStatefuleSet(p))
}

util.WriteString(output, strings.Join(result, "---\n"))
return nil
return strings.Join(result, "---\n"), nil
}

func getClusterRole(p *parse.APIs) string {
Expand Down

0 comments on commit 84d9376

Please sign in to comment.