diff --git a/pkg/plugin/util/helpers.go b/pkg/plugin/util/helpers.go deleted file mode 100644 index 87d953f268..0000000000 --- a/pkg/plugin/util/helpers.go +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2022 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package util - -import ( - "sigs.k8s.io/kubebuilder/v3/pkg/config" -) - -// Deprecated: go/v4 no longer supports v1beta1 option -// HasDifferentCRDVersion returns true if any other CRD version is tracked in the project configuration. -func HasDifferentCRDVersion(config config.Config, crdVersion string) bool { - return hasDifferentAPIVersion(config.ListCRDVersions(), crdVersion) -} - -// Deprecated: go/v4 no longer supports v1beta1 option -// HasDifferentWebhookVersion returns true if any other webhook version is tracked in the project configuration. -func HasDifferentWebhookVersion(config config.Config, webhookVersion string) bool { - return hasDifferentAPIVersion(config.ListWebhookVersions(), webhookVersion) -} - -// Deprecated: go/v4 no longer supports v1beta1 option -func hasDifferentAPIVersion(versions []string, version string) bool { - return !(len(versions) == 0 || (len(versions) == 1 && versions[0] == version)) -} diff --git a/pkg/plugin/util/helpers_test.go b/pkg/plugin/util/helpers_test.go deleted file mode 100644 index 62553b9ce9..0000000000 --- a/pkg/plugin/util/helpers_test.go +++ /dev/null @@ -1,44 +0,0 @@ -/* -Copyright 2022 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package util - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestPlugin(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Plugin Util Suite") -} - -var _ = Describe("hasDifferentAPIVersion", func() { - DescribeTable("should return false", - func(versions []string) { Expect(hasDifferentAPIVersion(versions, "v1")).To(BeFalse()) }, - Entry("for an empty list of versions", []string{}), - Entry("for a list of only that version", []string{"v1"}), - ) - - DescribeTable("should return true", - func(versions []string) { Expect(hasDifferentAPIVersion(versions, "v1")).To(BeTrue()) }, - Entry("for a list of only a different version", []string{"v2"}), - Entry("for a list of several different versions", []string{"v2", "v3"}), - Entry("for a list of several versions containing that version", []string{"v1", "v2"}), - ) -}) diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/api.go b/pkg/plugins/golang/deploy-image/v1alpha1/api.go index 923a6813e5..fd96a860ee 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/api.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/api.go @@ -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 { @@ -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 { @@ -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 } diff --git a/pkg/plugins/golang/options.go b/pkg/plugins/golang/options.go index 2227f4de3e..548efdaf9c 100644 --- a/pkg/plugins/golang/options.go +++ b/pkg/plugins/golang/options.go @@ -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 @@ -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, } @@ -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 } diff --git a/pkg/plugins/golang/options_test.go b/pkg/plugins/golang/options_test.go index b1fb6701f8..09ba607668 100644 --- a/pkg/plugins/golang/options_test.go +++ b/pkg/plugins/golang/options_test.go @@ -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 { @@ -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)) @@ -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", diff --git a/pkg/plugins/golang/v4/api.go b/pkg/plugins/golang/v4/api.go index 6b54f06053..6ca63051d2 100644 --- a/pkg/plugins/golang/v4/api.go +++ b/pkg/plugins/golang/v4/api.go @@ -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" @@ -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 } diff --git a/pkg/plugins/golang/v4/webhook.go b/pkg/plugins/golang/v4/webhook.go index 6e017ab1fd..c12c6248d1 100644 --- a/pkg/plugins/golang/v4/webhook.go +++ b/pkg/plugins/golang/v4/webhook.go @@ -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 { @@ -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 }