Skip to content

Commit 6a27bf7

Browse files
⚠️ enforce deprecate interface to allow bundle plugin has deprecation message
1 parent 3cb60ab commit 6a27bf7

File tree

11 files changed

+57
-14
lines changed

11 files changed

+57
-14
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: 12 additions & 3 deletions
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")
@@ -50,12 +51,15 @@ func NewBundle(name string, version Version, plugins ...Plugin) (Bundle, error)
5051
}
5152
}
5253

53-
return bundle{
54+
b := bundle{
5455
name: name,
5556
version: version,
5657
plugins: allPlugins,
5758
supportedProjectVersions: supportedProjectVersions,
58-
}, nil
59+
deprecateWarning: deprecateWarning,
60+
}
61+
62+
return b, nil
5963
}
6064

6165
// Name implements Plugin
@@ -77,3 +81,8 @@ func (b bundle) SupportedProjectVersions() []config.Version {
7781
func (b bundle) Plugins() []Plugin {
7882
return b.plugins
7983
}
84+
85+
// Plugins implements Bundle
86+
func (b bundle) DeprecationWarning() string {
87+
return b.deprecateWarning
88+
}

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/v3/plugin.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@ func (p Plugin) GetCreateWebhookSubcommand() plugin.CreateWebhookSubcommand {
6262

6363
// GetEditSubcommand will return the subcommand which is responsible for editing the scaffold of the project
6464
func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { return &p.editSubcommand }
65+
66+
// DeprecationWarning will return the warning for the deprecation of this plugin
67+
func (p Plugin) DeprecationWarning() string {
68+
return "This version is deprecated." +
69+
"The `go/v3` cannot scaffold projects using kustomize versions v4x+" +
70+
" and cannot fully support Kubernetes 1.25+." +
71+
"It is recommended to upgrade your project to the latest versions available (go/v4)." +
72+
"Please, check the migration guide to learn how to upgrade your project"
73+
}

pkg/plugins/golang/v4/plugin.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,5 @@ func (p Plugin) GetCreateWebhookSubcommand() plugin.CreateWebhookSubcommand {
6565
func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { return &p.editSubcommand }
6666

6767
func (p Plugin) DeprecationWarning() string {
68-
return "This version is deprecated." +
69-
"The `go/v3` cannot scaffold projects using kustomize versions v4x+" +
70-
" and cannot fully support Kubernetes 1.25+." +
71-
"It is recommended to upgrade your project to the latest versions available (go/v4)." +
72-
"Please, check the migration guide to learn how to upgrade your project"
68+
return ""
7369
}

0 commit comments

Comments
 (0)