From 7f5d552d315413cbc4d18cf812e173c4f8311d2c Mon Sep 17 00:00:00 2001 From: Camila Macedo <7708031+camilamacedo86@users.noreply.github.com> Date: Mon, 20 Mar 2023 08:11:26 +0000 Subject: [PATCH] =?UTF-8?q?:warning:=20=F0=9F=90=9B=20(API)=20fix=20deprec?= =?UTF-8?q?ate=20interface=20to=20allow=20bundle=20plugin=20has=20deprecat?= =?UTF-8?q?ion=20message=20(#3276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 9 +++++++++ pkg/cli/cli.go | 4 ++-- pkg/plugin/bundle.go | 9 ++++++++- pkg/plugin/bundle_test.go | 8 ++++---- pkg/plugins/common/kustomize/v2/plugin.go | 4 ++++ pkg/plugins/external/plugin.go | 4 ++++ pkg/plugins/golang/declarative/v1/plugin.go | 4 ++++ pkg/plugins/golang/deploy-image/v1alpha1/plugin.go | 4 ++++ pkg/plugins/golang/v4/plugin.go | 4 ++++ pkg/plugins/optional/grafana/v1alpha/plugin.go | 4 ++++ 10 files changed, 47 insertions(+), 7 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index da6af08b51d..fa60babab37 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -39,13 +39,22 @@ import ( func main() { + const deprecateMessageGoV3Bundle = "This version is deprecated." + + "The `go/v3` cannot scaffold projects using kustomize versions v4x+" + + " and cannot fully support Kubernetes 1.25+." + + "It is recommended to upgrade your project to the latest versions available (go/v4)." + + "Please, check the migration guide to learn how to upgrade your project" + // Bundle plugin which built the golang projects scaffold by Kubebuilder go/v3 gov3Bundle, _ := plugin.NewBundle(golang.DefaultNameQualifier, plugin.Version{Number: 3}, + deprecateMessageGoV3Bundle, kustomizecommonv1.Plugin{}, golangv3.Plugin{}, ) + // Bundle plugin which built the golang projects scaffold by Kubebuilder go/v4 with kustomize alpha-v2 gov4Bundle, _ := plugin.NewBundle(golang.DefaultNameQualifier, plugin.Version{Number: 4}, + "", kustomizecommonv2alpha.Plugin{}, golangv4.Plugin{}, ) diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 9e0f83c7e9d..7b74436db7d 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -443,8 +443,8 @@ func (c *CLI) addExtraCommands() error { // printDeprecationWarnings prints the deprecation warnings of the resolved plugins. func (c CLI) printDeprecationWarnings() { for _, p := range c.resolvedPlugins { - if d, isDeprecated := p.(plugin.Deprecated); isDeprecated { - fmt.Printf(noticeColor, fmt.Sprintf(deprecationFmt, d.DeprecationWarning())) + if p != nil && p.(plugin.Deprecated) != nil && len(p.(plugin.Deprecated).DeprecationWarning()) > 0 { + fmt.Printf(noticeColor, fmt.Sprintf(deprecationFmt, p.(plugin.Deprecated).DeprecationWarning())) } } } diff --git a/pkg/plugin/bundle.go b/pkg/plugin/bundle.go index 853ecff9e96..8a4a9e657ff 100644 --- a/pkg/plugin/bundle.go +++ b/pkg/plugin/bundle.go @@ -28,11 +28,12 @@ type bundle struct { plugins []Plugin supportedProjectVersions []config.Version + deprecateWarning string } // 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. -func NewBundle(name string, version Version, plugins ...Plugin) (Bundle, error) { +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") @@ -55,6 +56,7 @@ func NewBundle(name string, version Version, plugins ...Plugin) (Bundle, error) version: version, plugins: allPlugins, supportedProjectVersions: supportedProjectVersions, + deprecateWarning: deprecateWarning, }, nil } @@ -77,3 +79,8 @@ func (b bundle) SupportedProjectVersions() []config.Version { func (b bundle) Plugins() []Plugin { return b.plugins } + +// Plugins implements Bundle +func (b bundle) DeprecationWarning() string { + return b.deprecateWarning +} diff --git a/pkg/plugin/bundle_test.go b/pkg/plugin/bundle_test.go index 25c0d9d9e39..c437bfd7b8f 100644 --- a/pkg/plugin/bundle_test.go +++ b/pkg/plugin/bundle_test.go @@ -67,7 +67,7 @@ var _ = Describe("Bundle", func() { {p1, p2, p3}, {p1, p3, p4}, } { - b, err := NewBundle(name, version, plugins...) + b, err := NewBundle(name, version, "", plugins...) Expect(err).NotTo(HaveOccurred()) Expect(b.Name()).To(Equal(name)) Expect(b.Version().Compare(version)).To(Equal(0)) @@ -88,9 +88,9 @@ 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 = NewBundle("a", version, "", p1, p2) Expect(err).NotTo(HaveOccurred()) - b, err = NewBundle("b", version, a, p3) + b, err = NewBundle("b", version, "", a, p3) Expect(err).NotTo(HaveOccurred()) versions := b.SupportedProjectVersions() sort.Slice(versions, func(i int, j int) bool { @@ -113,7 +113,7 @@ var _ = Describe("Bundle", func() { {p1, p2, p3, p4}, } { - _, err := NewBundle(name, version, plugins...) + _, err := NewBundle(name, version, "", plugins...) Expect(err).To(HaveOccurred()) } }) diff --git a/pkg/plugins/common/kustomize/v2/plugin.go b/pkg/plugins/common/kustomize/v2/plugin.go index 5e8eb4ad5c5..5974e984d9c 100644 --- a/pkg/plugins/common/kustomize/v2/plugin.go +++ b/pkg/plugins/common/kustomize/v2/plugin.go @@ -66,3 +66,7 @@ func (p Plugin) GetCreateAPISubcommand() plugin.CreateAPISubcommand { return &p. func (p Plugin) GetCreateWebhookSubcommand() plugin.CreateWebhookSubcommand { return &p.createWebhookSubcommand } + +func (p Plugin) DeprecationWarning() string { + return "" +} diff --git a/pkg/plugins/external/plugin.go b/pkg/plugins/external/plugin.go index 2ca4c9e4e42..8b94b70d56f 100644 --- a/pkg/plugins/external/plugin.go +++ b/pkg/plugins/external/plugin.go @@ -73,3 +73,7 @@ func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { Args: p.Args, } } + +func (p Plugin) DeprecationWarning() string { + return "" +} diff --git a/pkg/plugins/golang/declarative/v1/plugin.go b/pkg/plugins/golang/declarative/v1/plugin.go index 9c8111b179f..76cf07c7c31 100644 --- a/pkg/plugins/golang/declarative/v1/plugin.go +++ b/pkg/plugins/golang/declarative/v1/plugin.go @@ -59,3 +59,7 @@ func (p Plugin) GetCreateAPISubcommand() plugin.CreateAPISubcommand { return &p. type pluginConfig struct { Resources []resource.GVK `json:"resources,omitempty"` } + +func (p Plugin) DeprecationWarning() string { + return "" +} diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/plugin.go b/pkg/plugins/golang/deploy-image/v1alpha1/plugin.go index c212e769ebe..aadf4398712 100644 --- a/pkg/plugins/golang/deploy-image/v1alpha1/plugin.go +++ b/pkg/plugins/golang/deploy-image/v1alpha1/plugin.go @@ -69,3 +69,7 @@ type options struct { ContainerPort string `json:"containerPort,omitempty"` RunAsUser string `json:"runAsUser,omitempty"` } + +func (p Plugin) DeprecationWarning() string { + return "" +} diff --git a/pkg/plugins/golang/v4/plugin.go b/pkg/plugins/golang/v4/plugin.go index 385e79f7cfa..704912cf333 100644 --- a/pkg/plugins/golang/v4/plugin.go +++ b/pkg/plugins/golang/v4/plugin.go @@ -63,3 +63,7 @@ func (p Plugin) GetCreateWebhookSubcommand() plugin.CreateWebhookSubcommand { // GetEditSubcommand will return the subcommand which is responsible for editing the scaffold of the project func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { return &p.editSubcommand } + +func (p Plugin) DeprecationWarning() string { + return "" +} diff --git a/pkg/plugins/optional/grafana/v1alpha/plugin.go b/pkg/plugins/optional/grafana/v1alpha/plugin.go index d4f9ee4f7dd..3f386dba4be 100644 --- a/pkg/plugins/optional/grafana/v1alpha/plugin.go +++ b/pkg/plugins/optional/grafana/v1alpha/plugin.go @@ -58,3 +58,7 @@ func (p Plugin) GetInitSubcommand() plugin.InitSubcommand { return &p.initSubcom func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { return &p.editSubcommand } type pluginConfig struct{} + +func (p Plugin) DeprecationWarning() string { + return "" +}