Skip to content

Commit

Permalink
⚠️ 🐛 (API) fix deprecate interface to allow bundle plugin has depreca…
Browse files Browse the repository at this point in the history
…tion message (#3276)
  • Loading branch information
camilamacedo86 committed Mar 20, 2023
1 parent bf9812b commit 7f5d552
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 7 deletions.
9 changes: 9 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/plugin/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -55,6 +56,7 @@ func NewBundle(name string, version Version, plugins ...Plugin) (Bundle, error)
version: version,
plugins: allPlugins,
supportedProjectVersions: supportedProjectVersions,
deprecateWarning: deprecateWarning,
}, nil
}

Expand All @@ -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
}
8 changes: 4 additions & 4 deletions pkg/plugin/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 {
Expand All @@ -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())
}
})
Expand Down
4 changes: 4 additions & 0 deletions pkg/plugins/common/kustomize/v2/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
4 changes: 4 additions & 0 deletions pkg/plugins/external/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ func (p Plugin) GetEditSubcommand() plugin.EditSubcommand {
Args: p.Args,
}
}

func (p Plugin) DeprecationWarning() string {
return ""
}
4 changes: 4 additions & 0 deletions pkg/plugins/golang/declarative/v1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
4 changes: 4 additions & 0 deletions pkg/plugins/golang/deploy-image/v1alpha1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ type options struct {
ContainerPort string `json:"containerPort,omitempty"`
RunAsUser string `json:"runAsUser,omitempty"`
}

func (p Plugin) DeprecationWarning() string {
return ""
}
4 changes: 4 additions & 0 deletions pkg/plugins/golang/v4/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
4 changes: 4 additions & 0 deletions pkg/plugins/optional/grafana/v1alpha/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}

0 comments on commit 7f5d552

Please sign in to comment.