Skip to content

Commit

Permalink
Validate resources for webhooks and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Orive <adrian.orive.oneca@gmail.com>
  • Loading branch information
Adirio committed Dec 16, 2019
1 parent 19458ba commit b94203f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
10 changes: 4 additions & 6 deletions cmd/webhook_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import (
"log"
"os"
"os/exec"
"strings"

"github.com/gobuffalo/flect"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

Expand Down Expand Up @@ -63,12 +61,12 @@ This command is only available for v1 scaffolding project.
os.Exit(1)
}

fmt.Println("Writing scaffold for you to edit...")

if len(o.res.Resource) == 0 {
o.res.Resource = flect.Pluralize(strings.ToLower(o.res.Kind))
if err := o.res.Validate(); err != nil {
log.Fatal(err)
}

fmt.Println("Writing scaffold for you to edit...")

err = (&scaffold.Scaffold{}).Execute(
&model.Universe{},
input.Options{},
Expand Down
6 changes: 3 additions & 3 deletions cmd/webhook_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"path/filepath"
"strings"

"github.com/gobuffalo/flect"
"github.com/spf13/cobra"

"sigs.k8s.io/kubebuilder/pkg/model"
Expand Down Expand Up @@ -66,11 +65,12 @@ func newWebhookV2Cmd() *cobra.Command {
os.Exit(1)
}

if len(o.res.Resource) == 0 {
o.res.Resource = flect.Pluralize(strings.ToLower(o.res.Kind))
if err := o.res.Validate(); err != nil {
log.Fatal(err)
}

fmt.Println("Writing scaffold for you to edit...")

fmt.Println(filepath.Join("api", o.res.Version,
fmt.Sprintf("%s_webhook.go", strings.ToLower(o.res.Kind))))
if o.conversion {
Expand Down
2 changes: 2 additions & 0 deletions pkg/scaffold/v1/crd/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var _ = Describe("Resource", func() {

for i := range resources {
r := resources[i]
_ = r.Validate()

Describe(fmt.Sprintf("scaffolding API %s", r.Kind), func() {
files := []struct {
instance input.File
Expand Down
2 changes: 2 additions & 0 deletions pkg/scaffold/v1/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ var _ = Describe("Webhook", func() {

for i := range inputs {
in := inputs[i]
_ = in.Validate()

Describe(fmt.Sprintf("scaffolding webhook %s", in.Kind), func() {
files := []struct {
instance input.File
Expand Down

0 comments on commit b94203f

Please sign in to comment.