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 Dec 16, 2020
1 parent bba9577 commit fd0df23
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/model/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ type ResourceData struct {
Group string `json:"group,omitempty"`
Version string `json:"version,omitempty"`
Kind string `json:"kind,omitempty"`
Plural string `json:"plural,omitempty"`

// API holds the API data
API *API `json:"api,omitempty"`
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 @@ -61,13 +63,20 @@ type Resource struct {

// Data returns the ResourceData information to check against tracked resources in the configuration file
func (r *Resource) Data() config.ResourceData {
return config.ResourceData{
data := config.ResourceData{
Group: r.Group,
Version: r.Version,
Kind: r.Kind,
API: &r.API,
Webhooks: &r.Webhooks,
}

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

return data
}

func wrapKey(key string) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/golang/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) {
fs.BoolVar(&p.force, "force", false,
"attempt to create resource even if it already exists")
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.BoolVar(&p.resource.Namespaced, "namespaced", true, "resource is namespaced")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/golang/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
3 changes: 2 additions & 1 deletion pkg/plugins/golang/v3/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) {
fs.BoolVar(&p.force, "force", false,
"attempt to create resource even if it already exists")
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, "plural", "", "resource kind irregular plural form")
fs.BoolVar(&p.resource.Namespaced, "namespaced", true, "resource is namespaced")
fs.StringVar(&p.resource.API.CRDVersion, "crd-version", defaultCRDVersion,
"version of CustomResourceDefinition to scaffold. Options: [v1, v1beta1]")
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/golang/v3/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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, "plural", "", "resource kind irregular plural form")
fs.StringVar(&p.resource.Webhooks.WebhookVersion, "webhook-version", defaultWebhookVersion,
"version of {Mutating,Validating}WebhookConfigurations to scaffold. Options: [v1, v1beta1]")

Expand Down

0 comments on commit fd0df23

Please sign in to comment.