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

🌱 Remove CRD and Webwhook versions options since they are no longer useful #3920

Merged
Merged
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
38 changes: 0 additions & 38 deletions pkg/plugin/util/helpers.go

This file was deleted.

44 changes: 0 additions & 44 deletions pkg/plugin/util/helpers_test.go

This file was deleted.

31 changes: 0 additions & 31 deletions pkg/plugins/golang/deploy-image/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds"
)

const (
// defaultCRDVersion is the default CRD API version to scaffold.
defaultCRDVersion = "v1"
)

const deprecateMsg = "The v1beta1 API version for CRDs and Webhooks are deprecated and are no longer supported since " +
"the Kubernetes release 1.22. This flag no longer required to exist in future releases. Also, we would like to " +
"recommend you no longer use these API versions." +
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22"

var _ plugin.CreateAPISubcommand = &createAPISubcommand{}

type createAPISubcommand struct {
Expand Down Expand Up @@ -129,14 +119,7 @@ func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) {

p.options = &goPlugin.Options{}

fs.StringVar(&p.options.CRDVersion, "crd-version", defaultCRDVersion,
"version of CustomResourceDefinition to scaffold. Options: [v1, v1beta1]")

fs.StringVar(&p.options.Plural, "plural", "", "resource irregular plural form")

// (not required raise an error in this case)
// nolint:errcheck,gosec
fs.MarkDeprecated("crd-version", deprecateMsg)
}

func (p *createAPISubcommand) InjectConfig(c config.Config) error {
Expand All @@ -163,20 +146,6 @@ func (p *createAPISubcommand) InjectResource(res *resource.Resource) error {
"to enable multi-group visit https://kubebuilder.io/migration/multi-group.html")
}

// Check CRDVersion against all other CRDVersions in p.config for compatibility.
// nolint:staticcheck
if util.HasDifferentCRDVersion(p.config, p.resource.API.CRDVersion) {
return fmt.Errorf("only one CRD version can be used for all resources, cannot add %q",
p.resource.API.CRDVersion)
}

// Check CRDVersion against all other CRDVersions in p.config for compatibility.
// nolint:staticcheck
if util.HasDifferentCRDVersion(p.config, p.resource.API.CRDVersion) {
return fmt.Errorf("only one CRD version can be used for all resources, cannot add %q",
p.resource.API.CRDVersion)
}

return nil
}

Expand Down
9 changes: 2 additions & 7 deletions pkg/plugins/golang/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ type Options struct {
// Plural is the resource's kind plural form.
Plural string

// CRDVersion is the CustomResourceDefinition API version that will be used for the resource.
CRDVersion string
// WebhookVersion is the {Validating,Mutating}WebhookConfiguration API version that will be used for the resource.
WebhookVersion string

// Namespaced is true if the resource should be namespaced.
Namespaced bool

Expand All @@ -88,7 +83,7 @@ func (opts Options) UpdateResource(res *resource.Resource, c config.Config) {
}

res.API = &resource.API{
CRDVersion: opts.CRDVersion,
CRDVersion: "v1",
Namespaced: opts.Namespaced,
}

Expand All @@ -107,7 +102,7 @@ func (opts Options) UpdateResource(res *resource.Resource, c config.Config) {
} else {
res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
}
res.Webhooks.WebhookVersion = opts.WebhookVersion
res.Webhooks.WebhookVersion = "v1"
if opts.DoDefaulting {
res.Webhooks.Defaulting = true
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/plugins/golang/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ var _ = Describe("Options", func() {
}
Expect(res.API).NotTo(BeNil())
if options.DoAPI {
Expect(res.API.CRDVersion).To(Equal(options.CRDVersion))
Expect(res.API.Namespaced).To(Equal(options.Namespaced))
Expect(res.API.IsEmpty()).To(BeFalse())
} else {
Expand All @@ -95,7 +94,6 @@ var _ = Describe("Options", func() {
Expect(res.Controller).To(Equal(options.DoController))
Expect(res.Webhooks).NotTo(BeNil())
if options.DoDefaulting || options.DoValidation || options.DoConversion {
Expect(res.Webhooks.WebhookVersion).To(Equal(options.WebhookVersion))
Expect(res.Webhooks.Defaulting).To(Equal(options.DoDefaulting))
Expect(res.Webhooks.Validation).To(Equal(options.DoValidation))
Expect(res.Webhooks.Conversion).To(Equal(options.DoConversion))
Expand All @@ -110,10 +108,7 @@ var _ = Describe("Options", func() {
},
Entry("when updating nothing", Options{}),
Entry("when updating the plural", Options{Plural: "mates"}),
Entry("when updating the API", Options{DoAPI: true, CRDVersion: "v1", Namespaced: true}),
Entry("when updating the Controller", Options{DoController: true}),
Entry("when updating Webhooks",
Options{WebhookVersion: "v1", DoDefaulting: true, DoValidation: true, DoConversion: true}),
)

DescribeTable("should use core apis",
Expand Down
7 changes: 0 additions & 7 deletions pkg/plugins/golang/v4/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v4/scaffolds"
)

const (
// defaultCRDVersion is the default CRD API version to scaffold.
defaultCRDVersion = "v1"
)

// DefaultMainPath is default file path of main.go
const DefaultMainPath = "cmd/main.go"

Expand Down Expand Up @@ -117,8 +112,6 @@ func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) {

func (p *createAPISubcommand) InjectConfig(c config.Config) error {
p.config = c
// go/v4 no longer supports v1beta1 option
p.options.CRDVersion = defaultCRDVersion
return nil
}

Expand Down
5 changes: 0 additions & 5 deletions pkg/plugins/golang/v4/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v4/scaffolds"
)

// defaultWebhookVersion is the default mutating/validating webhook config API version to scaffold.
const defaultWebhookVersion = "v1"

var _ plugin.CreateWebhookSubcommand = &createWebhookSubcommand{}

type createWebhookSubcommand struct {
Expand Down Expand Up @@ -82,8 +79,6 @@ func (p *createWebhookSubcommand) BindFlags(fs *pflag.FlagSet) {

func (p *createWebhookSubcommand) InjectConfig(c config.Config) error {
p.config = c
// go/v4 no longer supports v1beta1 option
p.options.WebhookVersion = defaultWebhookVersion
return nil
}

Expand Down
Loading