Skip to content

🌱 (chore): unify init and edit subcommands into a single command struct #4776

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kersten
Copy link
Contributor

@kersten kersten commented Apr 10, 2025

  • Replaces separate init/edit subcommands with a shared subcommand type
  • Uses dynamic scaffolder injection for each command
  • Adds suite and plugin tests for Grafana plugin

…and struct

- Replaces separate init/edit subcommands with a shared `subcommand` type
- Uses dynamic scaffolder injection for each command
- Adds suite and plugin tests for Grafana plugin
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kersten
Once this PR has been reviewed and has the lgtm label, please assign kavinjsir for approval. For more information see the 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 requested a review from Kavinjsir April 10, 2025 11:58
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 10, 2025
@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 10, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @kersten. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@kersten kersten changed the title refactor(grafana): unify init and edit subcommands into a single command struct 🌱 (chore): unify init and edit subcommands into a single command struct Apr 11, 2025
config config.Config
scaffolder plugins.Scaffolder
cmd string
exampleDescription string
}
Copy link
Member

@camilamacedo86 camilamacedo86 Apr 11, 2025

Choose a reason for hiding this comment

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

Hi @kersten 👋

Thanks so much for taking the time to look into this one — really appreciate your work here! 🎉

That said, I don’t think we need to introduce a new structure for this.

The init and edit commands should still go through the existing scaffolded interfaces. This helps ensure that descriptions, example snippets, and the UI behave consistently for both commands.

I believe we can follow the same pattern we used for the HelmPlugin:
https://github.com/kubernetes-sigs/kubebuilder/tree/master/pkg/plugins/optional/helm/v1alpha

In that case, the edit command simply calls into the same internal logic used by init, since they perform the same scaffolding work. For reference:

func (p *editSubcommand) Scaffold(fs machinery.Filesystem) error {
scaffolder := scaffolds.NewInitHelmScaffolder(p.config, p.force)
scaffolder.InjectFS(fs)
err := scaffolder.Scaffold()
if err != nil {
return fmt.Errorf("error scaffolding Helm chart: %w", err)
}
// Track the resources following a declarative approach
return insertPluginMetaToConfig(p.config, pluginConfig{})
}

It keeps the code DRY and easier to maintain while still providing a great user experience across both commands.

See:

Screenshot 2025-04-11 at 11 15 35

Thanks again — looking forward to your thoughts! 🙌

"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/grafana/v1alpha"
)

var _ = Describe("Grafana Plugin", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this change to achieve the intended goal?

If not, what do you think about starting with a PR that increases the Grafana plugin test coverage first? That way, we can define a clearer scope and build on top of that with more confidence.

Let me know your thoughts! 😊

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 11, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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-sigs/prow repository.

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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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.

3 participants