Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengqi Yu committed Jul 1, 2019
1 parent d0ec35f commit 5df08d2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 42 deletions.
5 changes: 4 additions & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ func newCreateCmd() *cobra.Command {
)

foundProject, version := getProjectVersion()
if !(foundProject && version == "1") {
// It add webhook v2 command in the following 2 cases:
// - There are no PROJECT file found.
// - version == 2 is found in the PROJECT file.
if !foundProject || version == "2" {
cmd.AddCommand(
newWebhookV2Cmd(),
)
Expand Down
33 changes: 0 additions & 33 deletions cmd/docs.go

This file was deleted.

3 changes: 1 addition & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,13 @@ func main() {
newInitProjectCmd(),
newCreateCmd(),
version.NewVersionCmd(),
newDocsCmd(),
newVendorUpdateCmd(),
)

foundProject, version := getProjectVersion()
if foundProject && version == "1" {
rootCmd.AddCommand(
newAlphaCommand(),
newVendorUpdateCmd(),
)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/webhook_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ This command is only available for v1 scaffolding project.

if projectInfo.Version != project.Version1 {
fmt.Printf("webhook scaffolding is not supported for this project version: %s \n", projectInfo.Version)
os.Exit(0)
os.Exit(1)
}

fmt.Println("Writing scaffold for you to edit...")
Expand Down
17 changes: 12 additions & 5 deletions cmd/webhook_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func newWebhookV2Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "webhook",
Short: "Scaffold a webhook for an API resource.",
Long: `Scaffold a webhook for an API resource. You can choose to scaffold defaulting and (or) validating webhooks.`,
Long: `Scaffold a webhook for an API resource. You can choose to scaffold defaulting, validating and (or) conversion webhooks.`,
Example: ` # Create defaulting and validating webhooks for CRD of group crew, version v1 and kind FirstMate.
kubebuilder webhook --group crew --version v1 --kind FirstMate --defaulting --programmatic-validation
`,
Expand All @@ -54,12 +54,12 @@ func newWebhookV2Cmd() *cobra.Command {

if projectInfo.Version != project.Version2 {
fmt.Printf("kubebuilder webhook is for project version: 2, the version of this project is: %s \n", projectInfo.Version)
os.Exit(0)
os.Exit(1)
}

if !o.defaulting && !o.validation {
fmt.Printf("kubebuilder webhook requires at least one of --defaulting and --programmatic-validation")
os.Exit(0)
if !o.defaulting && !o.validation && !o.conversion {
fmt.Printf("kubebuilder webhook requires at least one of --defaulting, --programmatic-validation and --conversion to be true")
os.Exit(1)
}

if len(o.res.Resource) == 0 {
Expand All @@ -69,6 +69,10 @@ func newWebhookV2Cmd() *cobra.Command {
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 {
fmt.Println(`Webhook server has been set up for you.
You need to implement the conversion.Hub and conversion.Convertible interfaces for your CRD types.`)
}
webhookScaffolder := &webhook.Webhook{
Resource: o.res,
Defaulting: o.defaulting,
Expand Down Expand Up @@ -103,6 +107,8 @@ func newWebhookV2Cmd() *cobra.Command {
"if set, scaffold the defaulting webhook")
cmd.Flags().BoolVar(&o.validation, "programmatic-validation", false,
"if set, scaffold the validating webhook")
cmd.Flags().BoolVar(&o.validation, "conversion", false,
"if set, scaffold the conversion webhook")

return cmd
}
Expand All @@ -112,4 +118,5 @@ type webhookV2Options struct {
res *resource.Resource
defaulting bool
validation bool
conversion bool
}

0 comments on commit 5df08d2

Please sign in to comment.