Skip to content
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

Closed

Conversation

NikhilSharmaWe
Copy link
Member

Description

This PR uses bundle options struct instead of funcs for creating new bundles through NewBundleWithOptions function.

Motivation

Fixes: #3307

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: NikhilSharmaWe
Once this PR has been reviewed and has the lgtm label, please assign pwittrock for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 1, 2023
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 1, 2023
@NikhilSharmaWe NikhilSharmaWe marked this pull request as draft May 1, 2023 12:53
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 1, 2023
@NikhilSharmaWe NikhilSharmaWe marked this pull request as ready for review May 1, 2023 12:56
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 1, 2023
@@ -37,26 +37,21 @@ import (
grafanav1alpha1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/v1alpha"
)

// nolint:lll
Copy link
Member

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?

Comment on lines 34 to 39
type BundlePlugin struct {
Options struct {
name string
version Version
plugins []Plugin
supportedProjectVersions []config.Version
deprecateWarning string
}
}
Copy link
Member

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?

Suggested change
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
}

Comment on lines 44 to 45
func NewBundlePlugin() BundlePlugin {
return BundlePlugin{}
Copy link
Member

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.

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 {
Copy link
Member

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?

Copy link
Member Author

@NikhilSharmaWe NikhilSharmaWe May 1, 2023

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

gov3Bundle, _ := bpgov3.WithName(golang.DefaultNameQualifier).WithVersion(plugin.Version{Number: 3}).WithDeprecationMessage(deprecateMessageGoV3Bundle).WithPlugins(kustomizecommonv1.Plugin{}, golangv3.Plugin{}).NewBundleWithOptions()
Which also makes the lint test fails to have to skip them, therefore #3379 (comment).

Please inform me if my changes are reasonable and why this approach is better than #3312. Maybe I am missing here something.

@NikhilSharmaWe NikhilSharmaWe force-pushed the upgradeBundle branch 3 times, most recently from 87da472 to 40e794a Compare May 1, 2023 14:44
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()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bpgov3 := plugin.NewBundlePluginOptions()
gov3 := plugin.NewBundlePluginBuilder()

@@ -31,31 +31,35 @@ type bundle struct {
deprecateWarning string
}

type BundleOption func(*bundle)
type BundlePluginOptions struct {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type BundlePluginOptions struct {
type BundlePluginBuilder struct {

return func(opts *bundle) {
opts.name = name
}
func NewBundlePluginOptions() BundlePluginOptions {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func NewBundlePluginOptions() BundlePluginOptions {
func NewBundlePluginBuilder() BundlePluginOptions {

}

supportedProjectVersions := CommonSupportedProjectVersions(bundleOpts.plugins...)
func (bp *BundlePluginOptions) NewBundleWithOptions() (Bundle, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (bp *BundlePluginOptions) NewBundleWithOptions() (Bundle, error) {
func (bp *BundlePluginOptions) Build() (Bundle, error) {

Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
@k8s-ci-robot
Copy link
Contributor

@NikhilSharmaWe: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubebuilder-e2e-k8s-1-26-0 0d0b341 link true /test pull-kubebuilder-e2e-k8s-1-26-0

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.

@NikhilSharmaWe
Copy link
Member Author

No need for this.
The current implementation is reasonable and probably better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate the current method API to build bundles and create new version to work with Options
4 participants