Skip to content

Commit 7f5d552

Browse files
⚠️ 🐛 (API) fix deprecate interface to allow bundle plugin has deprecation message (#3276)
1 parent bf9812b commit 7f5d552

File tree

10 files changed

+47
-7
lines changed

10 files changed

+47
-7
lines changed

cmd/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,22 @@ import (
3939

4040
func main() {
4141

42+
const deprecateMessageGoV3Bundle = "This version is deprecated." +
43+
"The `go/v3` cannot scaffold projects using kustomize versions v4x+" +
44+
" and cannot fully support Kubernetes 1.25+." +
45+
"It is recommended to upgrade your project to the latest versions available (go/v4)." +
46+
"Please, check the migration guide to learn how to upgrade your project"
47+
4248
// Bundle plugin which built the golang projects scaffold by Kubebuilder go/v3
4349
gov3Bundle, _ := plugin.NewBundle(golang.DefaultNameQualifier, plugin.Version{Number: 3},
50+
deprecateMessageGoV3Bundle,
4451
kustomizecommonv1.Plugin{},
4552
golangv3.Plugin{},
4653
)
54+
4755
// Bundle plugin which built the golang projects scaffold by Kubebuilder go/v4 with kustomize alpha-v2
4856
gov4Bundle, _ := plugin.NewBundle(golang.DefaultNameQualifier, plugin.Version{Number: 4},
57+
"",
4958
kustomizecommonv2alpha.Plugin{},
5059
golangv4.Plugin{},
5160
)

pkg/cli/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ func (c *CLI) addExtraCommands() error {
443443
// printDeprecationWarnings prints the deprecation warnings of the resolved plugins.
444444
func (c CLI) printDeprecationWarnings() {
445445
for _, p := range c.resolvedPlugins {
446-
if d, isDeprecated := p.(plugin.Deprecated); isDeprecated {
447-
fmt.Printf(noticeColor, fmt.Sprintf(deprecationFmt, d.DeprecationWarning()))
446+
if p != nil && p.(plugin.Deprecated) != nil && len(p.(plugin.Deprecated).DeprecationWarning()) > 0 {
447+
fmt.Printf(noticeColor, fmt.Sprintf(deprecationFmt, p.(plugin.Deprecated).DeprecationWarning()))
448448
}
449449
}
450450
}

pkg/plugin/bundle.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ type bundle struct {
2828
plugins []Plugin
2929

3030
supportedProjectVersions []config.Version
31+
deprecateWarning string
3132
}
3233

3334
// NewBundle creates a new Bundle with the provided name and version, and that wraps the provided plugins.
3435
// The list of supported project versions is computed from the provided plugins.
35-
func NewBundle(name string, version Version, plugins ...Plugin) (Bundle, error) {
36+
func NewBundle(name string, version Version, deprecateWarning string, plugins ...Plugin) (Bundle, error) {
3637
supportedProjectVersions := CommonSupportedProjectVersions(plugins...)
3738
if len(supportedProjectVersions) == 0 {
3839
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)
5556
version: version,
5657
plugins: allPlugins,
5758
supportedProjectVersions: supportedProjectVersions,
59+
deprecateWarning: deprecateWarning,
5860
}, nil
5961
}
6062

@@ -77,3 +79,8 @@ func (b bundle) SupportedProjectVersions() []config.Version {
7779
func (b bundle) Plugins() []Plugin {
7880
return b.plugins
7981
}
82+
83+
// Plugins implements Bundle
84+
func (b bundle) DeprecationWarning() string {
85+
return b.deprecateWarning
86+
}

pkg/plugin/bundle_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var _ = Describe("Bundle", func() {
6767
{p1, p2, p3},
6868
{p1, p3, p4},
6969
} {
70-
b, err := NewBundle(name, version, plugins...)
70+
b, err := NewBundle(name, version, "", plugins...)
7171
Expect(err).NotTo(HaveOccurred())
7272
Expect(b.Name()).To(Equal(name))
7373
Expect(b.Version().Compare(version)).To(Equal(0))
@@ -88,9 +88,9 @@ var _ = Describe("Bundle", func() {
8888
var a, b Bundle
8989
var err error
9090
plugins := []Plugin{p1, p2, p3}
91-
a, err = NewBundle("a", version, p1, p2)
91+
a, err = NewBundle("a", version, "", p1, p2)
9292
Expect(err).NotTo(HaveOccurred())
93-
b, err = NewBundle("b", version, a, p3)
93+
b, err = NewBundle("b", version, "", a, p3)
9494
Expect(err).NotTo(HaveOccurred())
9595
versions := b.SupportedProjectVersions()
9696
sort.Slice(versions, func(i int, j int) bool {
@@ -113,7 +113,7 @@ var _ = Describe("Bundle", func() {
113113

114114
{p1, p2, p3, p4},
115115
} {
116-
_, err := NewBundle(name, version, plugins...)
116+
_, err := NewBundle(name, version, "", plugins...)
117117
Expect(err).To(HaveOccurred())
118118
}
119119
})

pkg/plugins/common/kustomize/v2/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ func (p Plugin) GetCreateAPISubcommand() plugin.CreateAPISubcommand { return &p.
6666
func (p Plugin) GetCreateWebhookSubcommand() plugin.CreateWebhookSubcommand {
6767
return &p.createWebhookSubcommand
6868
}
69+
70+
func (p Plugin) DeprecationWarning() string {
71+
return ""
72+
}

pkg/plugins/external/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,7 @@ func (p Plugin) GetEditSubcommand() plugin.EditSubcommand {
7373
Args: p.Args,
7474
}
7575
}
76+
77+
func (p Plugin) DeprecationWarning() string {
78+
return ""
79+
}

pkg/plugins/golang/declarative/v1/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@ func (p Plugin) GetCreateAPISubcommand() plugin.CreateAPISubcommand { return &p.
5959
type pluginConfig struct {
6060
Resources []resource.GVK `json:"resources,omitempty"`
6161
}
62+
63+
func (p Plugin) DeprecationWarning() string {
64+
return ""
65+
}

pkg/plugins/golang/deploy-image/v1alpha1/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ type options struct {
6969
ContainerPort string `json:"containerPort,omitempty"`
7070
RunAsUser string `json:"runAsUser,omitempty"`
7171
}
72+
73+
func (p Plugin) DeprecationWarning() string {
74+
return ""
75+
}

pkg/plugins/golang/v4/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ func (p Plugin) GetCreateWebhookSubcommand() plugin.CreateWebhookSubcommand {
6363

6464
// GetEditSubcommand will return the subcommand which is responsible for editing the scaffold of the project
6565
func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { return &p.editSubcommand }
66+
67+
func (p Plugin) DeprecationWarning() string {
68+
return ""
69+
}

pkg/plugins/optional/grafana/v1alpha/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ func (p Plugin) GetInitSubcommand() plugin.InitSubcommand { return &p.initSubcom
5858
func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { return &p.editSubcommand }
5959

6060
type pluginConfig struct{}
61+
62+
func (p Plugin) DeprecationWarning() string {
63+
return ""
64+
}

0 commit comments

Comments
 (0)