Skip to content

Commit

Permalink
Add --plural flag to kubebuilder create api and update the v3 flag fo…
Browse files Browse the repository at this point in the history
…r kubebuilder create webhook from --resource to --plural

Signed-off-by: Adrian Orive <[email protected]>
  • Loading branch information
Adirio committed Nov 17, 2020
1 parent cd3cb2a commit 60db31a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pkg/model/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type GVK struct {
Group string `json:"group,omitempty"`
Version string `json:"version,omitempty"`
Kind string `json:"kind,omitempty"`
Plural string `json:"plural,omitempty"`

// CRDVersion holds the CustomResourceDefinition API version used for the GVK.
CRDVersion string `json:"crdVersion,omitempty"`
Expand All @@ -159,7 +160,8 @@ type GVK struct {
func (r GVK) isEqualTo(other GVK) bool {
return r.Group == other.Group &&
r.Version == other.Version &&
r.Kind == other.Kind
r.Kind == other.Kind &&
r.Plural == other.Plural
}

// merge combines fields of two GVKs that have matching group, version, and kind,
Expand Down
11 changes: 10 additions & 1 deletion pkg/model/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"
"strings"

"github.com/gobuffalo/flect"

"sigs.k8s.io/kubebuilder/v2/pkg/model/config"
)

Expand Down Expand Up @@ -60,13 +62,20 @@ type Resource struct {

// GVK returns the group-version-kind information to check against tracked resources in the configuration file
func (r *Resource) GVK() config.GVK {
return config.GVK{
gvk := config.GVK{
Group: r.Group,
Version: r.Version,
Kind: r.Kind,
CRDVersion: r.CRDVersion,
WebhookVersion: r.WebhookVersion,
}

// Only store plural if it is irregular
if r.Plural != flect.Pluralize(strings.ToLower(r.Kind)) {
gvk.Plural = r.Plural
}

return gvk
}

func wrapKey(key string) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/v2/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (p *createWebhookSubcommand) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.resource.Group, "group", "", "resource Group")
fs.StringVar(&p.resource.Version, "version", "", "resource Version")
fs.StringVar(&p.resource.Kind, "kind", "", "resource Kind")
fs.StringVar(&p.resource.Plural, "resource", "", "resource Resource")
fs.StringVar(&p.resource.Plural, "resource", "", "resource kind irregular plural form")

fs.BoolVar(&p.defaulting, "defaulting", false,
"if set, scaffold the defaulting webhook")
Expand Down
1 change: 1 addition & 0 deletions pkg/plugin/v3/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.resource.Kind, "kind", "", "resource Kind")
fs.StringVar(&p.resource.Group, "group", "", "resource Group")
fs.StringVar(&p.resource.Version, "version", "", "resource Version")
fs.StringVar(&p.resource.Plural, "plural", "", "resource kind irregular plural form")
fs.BoolVar(&p.resource.Namespaced, "namespaced", true, "resource is namespaced")
fs.StringVar(&p.resource.CRDVersion, "crd-version", defaultCRDVersion,
"version of CustomResourceDefinition to scaffold. Options: [v1, v1beta1]")
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/v3/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ validating and (or) conversion webhooks.

func (p *createWebhookSubcommand) BindFlags(fs *pflag.FlagSet) {
p.resource = &resource.Options{}
fs.StringVar(&p.resource.Kind, "kind", "", "resource Kind")
fs.StringVar(&p.resource.Group, "group", "", "resource Group")
fs.StringVar(&p.resource.Version, "version", "", "resource Version")
fs.StringVar(&p.resource.Kind, "kind", "", "resource Kind")
fs.StringVar(&p.resource.Plural, "resource", "", "resource Resource")
fs.StringVar(&p.resource.Plural, "plural", "", "resource kind irregular plural form")
fs.StringVar(&p.resource.WebhookVersion, "webhook-version", defaultWebhookVersion,
"version of {Mutating,Validating}WebhookConfigurations to scaffold. Options: [v1, v1beta1]")

Expand Down

0 comments on commit 60db31a

Please sign in to comment.