Skip to content

Commit 98c187e

Browse files
⚠️ Remove api deprecations: The methods NewBundle, GetShortName, IsLegacyLayout are no longer available (#3929)
* ⚠️ remove deprecated api NewBundle in favor of NewBundleWithOptions * ⚠️ remove deprecated apis no longer used GetShortName and IsLegacyLayout * cleanup: remove unused usage of IsLegacyLayout
1 parent afa5b3c commit 98c187e

File tree

7 files changed

+25
-115
lines changed

7 files changed

+25
-115
lines changed

pkg/plugin/bundle.go

+1-37
Original file line numberDiff line numberDiff line change
@@ -58,42 +58,6 @@ func WithDeprecationMessage(msg string) BundleOption {
5858

5959
}
6060

61-
// NewBundle creates a new Bundle with the provided name and version, and that wraps the provided plugins.
62-
// The list of supported project versions is computed from the provided plugins.
63-
//
64-
// Deprecated: Use the NewBundle informing the options from now one. Replace its use for as the
65-
// following example. Example:
66-
//
67-
// mylanguagev1Bundle, _ := plugin.NewBundle(plugin.WithName(language.DefaultNameQualifier),
68-
// plugin.WithVersion(plugin.Version{Number: 1}),
69-
// plugin.WithPlugins(kustomizecommonv1.Plugin{}, mylanguagev1.Plugin{}),
70-
func NewBundle(name string, version Version, deprecateWarning string, plugins ...Plugin) (Bundle, error) {
71-
supportedProjectVersions := CommonSupportedProjectVersions(plugins...)
72-
if len(supportedProjectVersions) == 0 {
73-
return nil, fmt.Errorf("in order to bundle plugins, they must all support at least one common project version")
74-
}
75-
76-
// Plugins may be bundles themselves, so unbundle here
77-
// NOTE(Adirio): unbundling here ensures that Bundle.Plugin always returns a flat list of Plugins instead of also
78-
// including Bundles, and therefore we don't have to use a recursive algorithm when resolving.
79-
allPlugins := make([]Plugin, 0, len(plugins))
80-
for _, plugin := range plugins {
81-
if pluginBundle, isBundle := plugin.(Bundle); isBundle {
82-
allPlugins = append(allPlugins, pluginBundle.Plugins()...)
83-
} else {
84-
allPlugins = append(allPlugins, plugin)
85-
}
86-
}
87-
88-
return bundle{
89-
name: name,
90-
version: version,
91-
plugins: allPlugins,
92-
supportedProjectVersions: supportedProjectVersions,
93-
deprecateWarning: deprecateWarning,
94-
}, nil
95-
}
96-
9761
// NewBundleWithOptions creates a new Bundle with the provided BundleOptions.
9862
// The list of supported project versions is computed from the provided plugins in options.
9963
func NewBundleWithOptions(opts ...BundleOption) (Bundle, error) {
@@ -149,7 +113,7 @@ func (b bundle) Plugins() []Plugin {
149113
return b.plugins
150114
}
151115

152-
// Plugins implements Bundle
116+
// DeprecationWarning return the warning message
153117
func (b bundle) DeprecationWarning() string {
154118
return b.deprecateWarning
155119
}

pkg/plugin/bundle_test.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ var _ = Describe("Bundle", func() {
6767
{p1, p2, p3},
6868
{p1, p3, p4},
6969
} {
70-
b, err := NewBundle(name, version, "", plugins...)
70+
71+
b, err := NewBundleWithOptions(WithName(name),
72+
WithVersion(version),
73+
WithPlugins(plugins...))
7174
Expect(err).NotTo(HaveOccurred())
7275
Expect(b.Name()).To(Equal(name))
7376
Expect(b.Version().Compare(version)).To(Equal(0))
@@ -88,9 +91,13 @@ var _ = Describe("Bundle", func() {
8891
var a, b Bundle
8992
var err error
9093
plugins := []Plugin{p1, p2, p3}
91-
a, err = NewBundle("a", version, "", p1, p2)
94+
a, err = NewBundleWithOptions(WithName("a"),
95+
WithVersion(version),
96+
WithPlugins(p1, p2))
9297
Expect(err).NotTo(HaveOccurred())
93-
b, err = NewBundle("b", version, "", a, p3)
98+
b, err = NewBundleWithOptions(WithName("b"),
99+
WithVersion(version),
100+
WithPlugins(a, p3))
94101
Expect(err).NotTo(HaveOccurred())
95102
versions := b.SupportedProjectVersions()
96103
sort.Slice(versions, func(i int, j int) bool {
@@ -113,7 +120,10 @@ var _ = Describe("Bundle", func() {
113120

114121
{p1, p2, p3, p4},
115122
} {
116-
_, err := NewBundle(name, version, "", plugins...)
123+
_, err := NewBundleWithOptions(WithName(name),
124+
WithVersion(version),
125+
WithPlugins(plugins...))
126+
117127
Expect(err).To(HaveOccurred())
118128
}
119129
})

pkg/plugin/helpers.go

-20
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,6 @@ func SplitKey(key string) (string, string) {
4040
return keyParts[0], keyParts[1]
4141
}
4242

43-
// GetShortName returns plugin's short name (name before domain) if name
44-
// is fully qualified (has a domain suffix), otherwise GetShortName returns name.
45-
// Deprecated
46-
func GetShortName(name string) string {
47-
return strings.SplitN(name, ".", 2)[0]
48-
}
49-
50-
// Deprecated: it was added to ensure backwards compatibility and should
51-
// be removed when we remove the go/v3 plugin
52-
// IsLegacyLayout returns true when is possible to identify that the project
53-
// was scaffolded with the previous layout
54-
func IsLegacyLayout(config config.Config) bool {
55-
for _, pluginKey := range config.GetPluginChain() {
56-
if strings.Contains(pluginKey, "go.kubebuilder.io/v3") || strings.Contains(pluginKey, "go.kubebuilder.io/v2") {
57-
return true
58-
}
59-
}
60-
return false
61-
}
62-
6343
// Validate ensures a Plugin is valid.
6444
func Validate(p Plugin) error {
6545
if err := validateName(p.Name()); err != nil {

pkg/plugin/helpers_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ var _ = Describe("SplitKey", func() {
6464
})
6565
})
6666

67-
var _ = Describe("GetShortName", func() {
68-
It("should extract base names from domains", func() {
69-
Expect(GetShortName(name)).To(Equal(short))
70-
})
71-
})
72-
7367
var _ = Describe("Validate", func() {
7468
It("should succeed for valid plugins", func() {
7569
plugin := mockPlugin{

pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go

+3-18
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,15 @@ type Types struct {
3636

3737
// Port if informed we will create the scaffold with this spec
3838
Port string
39-
40-
IsLegacyLayout bool
4139
}
4240

4341
// SetTemplateDefaults implements file.Template
4442
func (f *Types) SetTemplateDefaults() error {
4543
if f.Path == "" {
46-
47-
if f.IsLegacyLayout {
48-
if f.MultiGroup {
49-
if f.Resource.Group != "" {
50-
f.Path = filepath.Join("apis", "%[group]", "%[version]", "%[kind]_types.go")
51-
} else {
52-
f.Path = filepath.Join("apis", "%[version]", "%[kind]_types.go")
53-
}
54-
} else {
55-
f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go")
56-
}
44+
if f.MultiGroup && f.Resource.Group != "" {
45+
f.Path = filepath.Join("api", "%[group]", "%[version]", "%[kind]_types.go")
5746
} else {
58-
if f.MultiGroup && f.Resource.Group != "" {
59-
f.Path = filepath.Join("api", "%[group]", "%[version]", "%[kind]_types.go")
60-
} else {
61-
f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go")
62-
}
47+
f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go")
6348
}
6449
}
6550

pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go

+4-17
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,23 @@ type ControllerTest struct {
3434
machinery.BoilerplateMixin
3535
machinery.ResourceMixin
3636

37-
Port string
38-
IsLegacyLayout bool
39-
PackageName string
37+
Port string
38+
PackageName string
4039
}
4140

4241
// SetTemplateDefaults implements file.Template
4342
func (f *ControllerTest) SetTemplateDefaults() error {
4443
if f.Path == "" {
4544
if f.MultiGroup && f.Resource.Group != "" {
46-
if f.IsLegacyLayout {
47-
f.Path = filepath.Join("controllers", "%[group]", "%[kind]_controller_test.go")
48-
} else {
49-
f.Path = filepath.Join("internal", "controller", "%[group]", "%[kind]_controller_test.go")
50-
}
45+
f.Path = filepath.Join("internal", "controller", "%[group]", "%[kind]_controller_test.go")
5146
} else {
52-
if f.IsLegacyLayout {
53-
f.Path = filepath.Join("controllers", "%[kind]_controller_test.go")
54-
} else {
55-
f.Path = filepath.Join("internal", "controller", "%[kind]_controller_test.go")
56-
}
47+
f.Path = filepath.Join("internal", "controller", "%[kind]_controller_test.go")
5748
}
5849
}
5950
f.Path = f.Resource.Replacer().Replace(f.Path)
6051
log.Println(f.Path)
6152

6253
f.PackageName = "controller"
63-
if f.IsLegacyLayout {
64-
f.PackageName = "controllers"
65-
}
66-
6754
f.IfExistsAction = machinery.OverwriteFile
6855

6956
log.Println("creating import for %", f.Resource.Path)

pkg/plugins/golang/options.go

+3-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"sigs.k8s.io/kubebuilder/v3/pkg/config"
2323
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
24-
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
2524
)
2625

2726
var (
@@ -76,11 +75,7 @@ func (opts Options) UpdateResource(res *resource.Resource, c config.Config) {
7675

7776
if opts.DoAPI {
7877
//nolint:staticcheck
79-
if plugin.IsLegacyLayout(c) {
80-
res.Path = resource.APIPackagePathLegacy(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
81-
} else {
82-
res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
83-
}
78+
res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
8479

8580
res.API = &resource.API{
8681
CRDVersion: "v1",
@@ -94,14 +89,9 @@ func (opts Options) UpdateResource(res *resource.Resource, c config.Config) {
9489
}
9590

9691
if opts.DoDefaulting || opts.DoValidation || opts.DoConversion {
97-
// IsLegacyLayout is added to ensure backwards compatibility and should
98-
// be removed when we remove the go/v3 plugin
9992
//nolint:staticcheck
100-
if plugin.IsLegacyLayout(c) {
101-
res.Path = resource.APIPackagePathLegacy(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
102-
} else {
103-
res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
104-
}
93+
res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
94+
10595
res.Webhooks.WebhookVersion = "v1"
10696
if opts.DoDefaulting {
10797
res.Webhooks.Defaulting = true

0 commit comments

Comments
 (0)