diff --git a/pkg/plugin/bundle.go b/pkg/plugin/bundle.go index 47e4f879ea..493458a9fc 100644 --- a/pkg/plugin/bundle.go +++ b/pkg/plugin/bundle.go @@ -58,42 +58,6 @@ func WithDeprecationMessage(msg string) BundleOption { } -// NewBundle creates a new Bundle with the provided name and version, and that wraps the provided plugins. -// The list of supported project versions is computed from the provided plugins. -// -// Deprecated: Use the NewBundle informing the options from now one. Replace its use for as the -// following example. Example: -// -// mylanguagev1Bundle, _ := plugin.NewBundle(plugin.WithName(language.DefaultNameQualifier), -// plugin.WithVersion(plugin.Version{Number: 1}), -// plugin.WithPlugins(kustomizecommonv1.Plugin{}, mylanguagev1.Plugin{}), -func NewBundle(name string, version Version, deprecateWarning string, plugins ...Plugin) (Bundle, error) { - supportedProjectVersions := CommonSupportedProjectVersions(plugins...) - if len(supportedProjectVersions) == 0 { - return nil, fmt.Errorf("in order to bundle plugins, they must all support at least one common project version") - } - - // Plugins may be bundles themselves, so unbundle here - // NOTE(Adirio): unbundling here ensures that Bundle.Plugin always returns a flat list of Plugins instead of also - // including Bundles, and therefore we don't have to use a recursive algorithm when resolving. - allPlugins := make([]Plugin, 0, len(plugins)) - for _, plugin := range plugins { - if pluginBundle, isBundle := plugin.(Bundle); isBundle { - allPlugins = append(allPlugins, pluginBundle.Plugins()...) - } else { - allPlugins = append(allPlugins, plugin) - } - } - - return bundle{ - name: name, - version: version, - plugins: allPlugins, - supportedProjectVersions: supportedProjectVersions, - deprecateWarning: deprecateWarning, - }, nil -} - // NewBundleWithOptions creates a new Bundle with the provided BundleOptions. // The list of supported project versions is computed from the provided plugins in options. func NewBundleWithOptions(opts ...BundleOption) (Bundle, error) { @@ -149,7 +113,7 @@ func (b bundle) Plugins() []Plugin { return b.plugins } -// Plugins implements Bundle +// DeprecationWarning return the warning message func (b bundle) DeprecationWarning() string { return b.deprecateWarning } diff --git a/pkg/plugin/bundle_test.go b/pkg/plugin/bundle_test.go index ccb1a41d57..1c3306b450 100644 --- a/pkg/plugin/bundle_test.go +++ b/pkg/plugin/bundle_test.go @@ -67,7 +67,10 @@ var _ = Describe("Bundle", func() { {p1, p2, p3}, {p1, p3, p4}, } { - b, err := NewBundle(name, version, "", plugins...) + + b, err := NewBundleWithOptions(WithName(name), + WithVersion(version), + WithPlugins(plugins...)) Expect(err).NotTo(HaveOccurred()) Expect(b.Name()).To(Equal(name)) Expect(b.Version().Compare(version)).To(Equal(0)) @@ -88,9 +91,13 @@ var _ = Describe("Bundle", func() { var a, b Bundle var err error plugins := []Plugin{p1, p2, p3} - a, err = NewBundle("a", version, "", p1, p2) + a, err = NewBundleWithOptions(WithName("a"), + WithVersion(version), + WithPlugins(p1, p2)) Expect(err).NotTo(HaveOccurred()) - b, err = NewBundle("b", version, "", a, p3) + b, err = NewBundleWithOptions(WithName("b"), + WithVersion(version), + WithPlugins(a, p3)) Expect(err).NotTo(HaveOccurred()) versions := b.SupportedProjectVersions() sort.Slice(versions, func(i int, j int) bool { @@ -113,7 +120,10 @@ var _ = Describe("Bundle", func() { {p1, p2, p3, p4}, } { - _, err := NewBundle(name, version, "", plugins...) + _, err := NewBundleWithOptions(WithName(name), + WithVersion(version), + WithPlugins(plugins...)) + Expect(err).To(HaveOccurred()) } }) diff --git a/pkg/plugin/helpers.go b/pkg/plugin/helpers.go index a957d4cb07..11e2fe4519 100644 --- a/pkg/plugin/helpers.go +++ b/pkg/plugin/helpers.go @@ -40,26 +40,6 @@ func SplitKey(key string) (string, string) { return keyParts[0], keyParts[1] } -// GetShortName returns plugin's short name (name before domain) if name -// is fully qualified (has a domain suffix), otherwise GetShortName returns name. -// Deprecated -func GetShortName(name string) string { - return strings.SplitN(name, ".", 2)[0] -} - -// Deprecated: it was added to ensure backwards compatibility and should -// be removed when we remove the go/v3 plugin -// IsLegacyLayout returns true when is possible to identify that the project -// was scaffolded with the previous layout -func IsLegacyLayout(config config.Config) bool { - for _, pluginKey := range config.GetPluginChain() { - if strings.Contains(pluginKey, "go.kubebuilder.io/v3") || strings.Contains(pluginKey, "go.kubebuilder.io/v2") { - return true - } - } - return false -} - // Validate ensures a Plugin is valid. func Validate(p Plugin) error { if err := validateName(p.Name()); err != nil { diff --git a/pkg/plugin/helpers_test.go b/pkg/plugin/helpers_test.go index f01caa2505..981265231a 100644 --- a/pkg/plugin/helpers_test.go +++ b/pkg/plugin/helpers_test.go @@ -64,12 +64,6 @@ var _ = Describe("SplitKey", func() { }) }) -var _ = Describe("GetShortName", func() { - It("should extract base names from domains", func() { - Expect(GetShortName(name)).To(Equal(short)) - }) -}) - var _ = Describe("Validate", func() { It("should succeed for valid plugins", func() { plugin := mockPlugin{ diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go index e7b73cf7d9..cb966bc037 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go @@ -36,30 +36,15 @@ type Types struct { // Port if informed we will create the scaffold with this spec Port string - - IsLegacyLayout bool } // SetTemplateDefaults implements file.Template func (f *Types) SetTemplateDefaults() error { if f.Path == "" { - - if f.IsLegacyLayout { - if f.MultiGroup { - if f.Resource.Group != "" { - f.Path = filepath.Join("apis", "%[group]", "%[version]", "%[kind]_types.go") - } else { - f.Path = filepath.Join("apis", "%[version]", "%[kind]_types.go") - } - } else { - f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go") - } + if f.MultiGroup && f.Resource.Group != "" { + f.Path = filepath.Join("api", "%[group]", "%[version]", "%[kind]_types.go") } else { - if f.MultiGroup && f.Resource.Group != "" { - f.Path = filepath.Join("api", "%[group]", "%[version]", "%[kind]_types.go") - } else { - f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go") - } + f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go") } } diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go index 47c8e8cc1b..f5d45c4e28 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go @@ -34,36 +34,23 @@ type ControllerTest struct { machinery.BoilerplateMixin machinery.ResourceMixin - Port string - IsLegacyLayout bool - PackageName string + Port string + PackageName string } // SetTemplateDefaults implements file.Template func (f *ControllerTest) SetTemplateDefaults() error { if f.Path == "" { if f.MultiGroup && f.Resource.Group != "" { - if f.IsLegacyLayout { - f.Path = filepath.Join("controllers", "%[group]", "%[kind]_controller_test.go") - } else { - f.Path = filepath.Join("internal", "controller", "%[group]", "%[kind]_controller_test.go") - } + f.Path = filepath.Join("internal", "controller", "%[group]", "%[kind]_controller_test.go") } else { - if f.IsLegacyLayout { - f.Path = filepath.Join("controllers", "%[kind]_controller_test.go") - } else { - f.Path = filepath.Join("internal", "controller", "%[kind]_controller_test.go") - } + f.Path = filepath.Join("internal", "controller", "%[kind]_controller_test.go") } } f.Path = f.Resource.Replacer().Replace(f.Path) log.Println(f.Path) f.PackageName = "controller" - if f.IsLegacyLayout { - f.PackageName = "controllers" - } - f.IfExistsAction = machinery.OverwriteFile log.Println("creating import for %", f.Resource.Path) diff --git a/pkg/plugins/golang/options.go b/pkg/plugins/golang/options.go index 548efdaf9c..f3cc87cce4 100644 --- a/pkg/plugins/golang/options.go +++ b/pkg/plugins/golang/options.go @@ -21,7 +21,6 @@ import ( "sigs.k8s.io/kubebuilder/v3/pkg/config" "sigs.k8s.io/kubebuilder/v3/pkg/model/resource" - "sigs.k8s.io/kubebuilder/v3/pkg/plugin" ) var ( @@ -76,11 +75,7 @@ func (opts Options) UpdateResource(res *resource.Resource, c config.Config) { if opts.DoAPI { //nolint:staticcheck - if plugin.IsLegacyLayout(c) { - res.Path = resource.APIPackagePathLegacy(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup()) - } else { - res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup()) - } + res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup()) res.API = &resource.API{ CRDVersion: "v1", @@ -94,14 +89,9 @@ func (opts Options) UpdateResource(res *resource.Resource, c config.Config) { } if opts.DoDefaulting || opts.DoValidation || opts.DoConversion { - // IsLegacyLayout is added to ensure backwards compatibility and should - // be removed when we remove the go/v3 plugin //nolint:staticcheck - if plugin.IsLegacyLayout(c) { - res.Path = resource.APIPackagePathLegacy(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup()) - } else { - res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup()) - } + res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup()) + res.Webhooks.WebhookVersion = "v1" if opts.DoDefaulting { res.Webhooks.Defaulting = true