Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if converting this to use the options pattern would be better than adding another function parameter? I think that would prevent this function signature getting really long with future changes.

I think this would look something like:

func NewBundle(opts ...BundleOptions) (Bundle, error)

and new bundles could be created like:

bundle, err := NewBundle(
  WithName("name"),
  WithVersion(plugin.Version{Number: 4}),
  WithPlugins(plugins ...Plugin),
  WithDeprecationMessage("Deprecated!"),
)

Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@everettraven here we just fixing the method (which breaks the API)
I totally agree with the approach suggested by you and for we are able to do that I tracked the need in: #3307

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 ""
}