From e242df55dc85a87effac6463cd0aad2e9e1ef0c4 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Fri, 17 May 2024 00:07:55 +0100 Subject: [PATCH] Remove CRD and Webwhook versions options since they are no longer useful --- pkg/plugin/util/helpers.go | 38 ---------------- pkg/plugin/util/helpers_test.go | 44 ------------------- .../golang/deploy-image/v1alpha1/api.go | 26 ----------- pkg/plugins/golang/options.go | 9 +--- pkg/plugins/golang/v4/api.go | 2 - pkg/plugins/golang/v4/webhook.go | 2 - 6 files changed, 2 insertions(+), 119 deletions(-) delete mode 100644 pkg/plugin/util/helpers.go delete mode 100644 pkg/plugin/util/helpers_test.go diff --git a/pkg/plugin/util/helpers.go b/pkg/plugin/util/helpers.go deleted file mode 100644 index 87d953f268b..00000000000 --- 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 62553b9ce9e..00000000000 --- 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 923a6813e53..5ff3b9e0273 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/api.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/api.go @@ -39,11 +39,6 @@ const ( 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 +124,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 +151,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 2227f4de3ee..548efdaf9c6 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/v4/api.go b/pkg/plugins/golang/v4/api.go index 6b54f060532..d2b12046bea 100644 --- a/pkg/plugins/golang/v4/api.go +++ b/pkg/plugins/golang/v4/api.go @@ -117,8 +117,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 6e017ab1fdb..233b9cc5eec 100644 --- a/pkg/plugins/golang/v4/webhook.go +++ b/pkg/plugins/golang/v4/webhook.go @@ -82,8 +82,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 }