-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨use bundle options struct for creating new bundles #3379
✨use bundle options struct for creating new bundles #3379
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: NikhilSharmaWe The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -37,26 +37,21 @@ import ( | |||
grafanav1alpha1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/v1alpha" | |||
) | |||
|
|||
// nolint:lll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason for adding this?
pkg/plugin/bundle.go
Outdated
type BundlePlugin struct { | ||
Options struct { | ||
name string | ||
version Version | ||
plugins []Plugin | ||
supportedProjectVersions []config.Version | ||
deprecateWarning string | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we need the nested struct. Wdyt of making it this?
type BundlePlugin struct { | |
Options struct { | |
name string | |
version Version | |
plugins []Plugin | |
supportedProjectVersions []config.Version | |
deprecateWarning string | |
} | |
} | |
type BundlePluginOptions struct { | |
name string | |
version Version | |
plugins []Plugin | |
supportedProjectVersions []config.Version | |
deprecateWarning string | |
} |
pkg/plugin/bundle.go
Outdated
func NewBundlePlugin() BundlePlugin { | ||
return BundlePlugin{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if BundlePlugin
is exported, then there is no need of calling NewBundlePlugin
func. We can make the BundlePlugin not to be exported (bundlePlugin) and have this func.
pkg/plugin/bundle.go
Outdated
allPlugins := make([]Plugin, 0, len(bundleOpts.plugins)) | ||
for _, plugin := range bundleOpts.plugins { | ||
allPlugins := make([]Plugin, 0, len(bp.Options.plugins)) | ||
for _, plugin := range bp.Options.plugins { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a specific reason to make a nested struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@varshaprasad96 Sorry about that. Changed it.
Actually, according to me the changes I made in this #3312 for #3307 were reasonable, since it implemented the functional arguments for the NewBundleWithOptions
func for creating Bundles to prevent the long function signature for the NewBundle func, which achieves the goal for which the issue was made.
But @camilamacedo86 has suggested that using struct for bundle options is more reasonable.
But with the calling the function for bundle creation becomes very long like
Line 50 in 0ceec77
gov3Bundle, _ := bpgov3.WithName(golang.DefaultNameQualifier).WithVersion(plugin.Version{Number: 3}).WithDeprecationMessage(deprecateMessageGoV3Bundle).WithPlugins(kustomizecommonv1.Plugin{}, golangv3.Plugin{}).NewBundleWithOptions() |
Please inform me if my changes are reasonable and why this approach is better than #3312. Maybe I am missing here something.
87da472
to
40e794a
Compare
cmd/main.go
Outdated
plugin.WithPlugins(kustomizecommonv1.Plugin{}, golangv3.Plugin{}), | ||
) | ||
bpgov3 := plugin.NewBundlePluginOptions() | ||
gov3Bundle, _ := bpgov3.WithName(golang.DefaultNameQualifier).WithVersion(plugin.Version{Number: 3}).WithDeprecationMessage(deprecateMessageGoV3Bundle).WithPlugins(kustomizecommonv1.Plugin{}, golangv3.Plugin{}).NewBundleWithOptions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gov3Bundle, _ := bpgov3.WithName(golang.DefaultNameQualifier).WithVersion(plugin.Version{Number: 3}).WithDeprecationMessage(deprecateMessageGoV3Bundle).WithPlugins(kustomizecommonv1.Plugin{}, golangv3.Plugin{}).NewBundleWithOptions() | |
gov3Bundle, _ := bpgov3.WithName(golang.DefaultNameQualifier).WithVersion(plugin.Version{Number: 3}).WithDeprecationMessage(deprecateMessageGoV3Bundle).WithPlugins(kustomizecommonv1.Plugin{}, golangv3.Plugin{}).Build() |
cmd/main.go
Outdated
plugin.WithDeprecationMessage(deprecateMessageGoV3Bundle), | ||
plugin.WithPlugins(kustomizecommonv1.Plugin{}, golangv3.Plugin{}), | ||
) | ||
bpgov3 := plugin.NewBundlePluginOptions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bpgov3 := plugin.NewBundlePluginOptions() | |
gov3 := plugin.NewBundlePluginBuilder() |
pkg/plugin/bundle.go
Outdated
@@ -31,31 +31,35 @@ type bundle struct { | |||
deprecateWarning string | |||
} | |||
|
|||
type BundleOption func(*bundle) | |||
type BundlePluginOptions struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type BundlePluginOptions struct { | |
type BundlePluginBuilder struct { |
pkg/plugin/bundle.go
Outdated
return func(opts *bundle) { | ||
opts.name = name | ||
} | ||
func NewBundlePluginOptions() BundlePluginOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func NewBundlePluginOptions() BundlePluginOptions { | |
func NewBundlePluginBuilder() BundlePluginOptions { |
pkg/plugin/bundle.go
Outdated
} | ||
|
||
supportedProjectVersions := CommonSupportedProjectVersions(bundleOpts.plugins...) | ||
func (bp *BundlePluginOptions) NewBundleWithOptions() (Bundle, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (bp *BundlePluginOptions) NewBundleWithOptions() (Bundle, error) { | |
func (bp *BundlePluginOptions) Build() (Bundle, error) { |
40e794a
to
5dacc46
Compare
Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
5dacc46
to
0d0b341
Compare
@NikhilSharmaWe: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
No need for this. |
Description
This PR uses bundle options struct instead of funcs for creating new bundles through
NewBundleWithOptions
function.Motivation
Fixes: #3307