Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add --plural flag #1802

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
Copy link
Member

@camilamacedo86 camilamacedo86 Nov 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a test to ensure these changes. WDYT about add/update the testdata samples with this scenario? See that it means that 1 resource for v3-projects should use it at least. Also, will it work fine for the addon scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea about the addon scenario, but I guess it shouldn't affect as it was being passed a Resource which already ahs this field (it was always set with flect.Pluralize(strings.ToLower(resource.Kind)) instead of providing the user the ability to define it).

Will add the test later.


// 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
}
Adirio marked this conversation as resolved.
Show resolved Hide resolved

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