From 5df08d2d17e440a8bd6533489400c30f2ec9d900 Mon Sep 17 00:00:00 2001 From: Mengqi Yu Date: Mon, 1 Jul 2019 14:03:58 -0700 Subject: [PATCH] address comments --- cmd/create.go | 5 ++++- cmd/docs.go | 33 --------------------------------- cmd/main.go | 3 +-- cmd/webhook_v1.go | 2 +- cmd/webhook_v2.go | 17 ++++++++++++----- 5 files changed, 18 insertions(+), 42 deletions(-) delete mode 100644 cmd/docs.go diff --git a/cmd/create.go b/cmd/create.go index 0e1c5ba05b7..360a3b2eb5d 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -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(), ) diff --git a/cmd/docs.go b/cmd/docs.go deleted file mode 100644 index ba9f456fc08..00000000000 --- a/cmd/docs.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2018 The Kubernetes 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 ( - "fmt" - "github.com/spf13/cobra" -) - -func newDocsCmd() *cobra.Command { - return &cobra.Command{ - Use: "docs", - Short: "Generate API reference docs. Coming soon", - Long: `Generate API reference docs. Coming soon`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Coming soon.") - }, - } -} diff --git a/cmd/main.go b/cmd/main.go index 534d02dc371..0abb25b4efb 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -117,14 +117,13 @@ func main() { newInitProjectCmd(), newCreateCmd(), version.NewVersionCmd(), - newDocsCmd(), - newVendorUpdateCmd(), ) foundProject, version := getProjectVersion() if foundProject && version == "1" { rootCmd.AddCommand( newAlphaCommand(), + newVendorUpdateCmd(), ) } diff --git a/cmd/webhook_v1.go b/cmd/webhook_v1.go index a89a48b896a..7fd415a5c40 100644 --- a/cmd/webhook_v1.go +++ b/cmd/webhook_v1.go @@ -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...") diff --git a/cmd/webhook_v2.go b/cmd/webhook_v2.go index b1831a2a6f7..58e21232cfc 100644 --- a/cmd/webhook_v2.go +++ b/cmd/webhook_v2.go @@ -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 `, @@ -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 { @@ -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, @@ -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 } @@ -112,4 +118,5 @@ type webhookV2Options struct { res *resource.Resource defaulting bool validation bool + conversion bool }