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 <adrian.orive.oneca@gmail.com>
  • Loading branch information
Adirio committed Nov 9, 2020
1 parent 7868757 commit 9bf8e93
Show file tree
Hide file tree
Showing 6 changed files with 18 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 @@ -118,13 +118,15 @@ type GVK struct {
Group string `json:"group,omitempty"`
Version string `json:"version,omitempty"`
Kind string `json:"kind,omitempty"`
Plural string `json:"plural,omitempty"`
}

// isEqualTo compares it with another resource
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
}

// Marshal returns the bytes of c.
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 @@ -55,11 +57,18 @@ 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,
}

// 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
1 change: 1 addition & 0 deletions pkg/plugin/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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")
}

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 @@ -123,6 +123,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")
}

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 @@ -64,10 +64,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.BoolVar(&p.defaulting, "defaulting", false,
"if set, scaffold the defaulting webhook")
Expand Down

0 comments on commit 9bf8e93

Please sign in to comment.