Skip to content

Add ansible plugin scaffolding command into ansible-operator binary #149

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 3 commits into
base: main
Choose a base branch
from

Conversation

chiragkyal
Copy link
Contributor

@chiragkyal chiragkyal commented Jun 17, 2025

Description of the change:

This PR introduces ansible plugin scaffolding by integrating the functionality directly into the ansible-operator binary under a new scaffold subcommand.

Motivation for the change:

  • This change streamlines the process by providing a single, dedicated command-line tool.

Implementation Details

New scaffold Subcommand: The ansible-operator binary now includes a scaffold command, which provides all the project scaffolding capabilities (e.g., init, create api).

Unified CLI:: Users now only need ansible-operator.

  • To run the operator: ansible-operator run ...
  • To scaffold a new project: ansible-operator scaffold init ...
  • To add a new API: ansible-operator scaffold create api ...

E2E: Uses a common CLI entrypoint for hack/generate/samples/ansible/generate.go which is used to generate e2e testdata.

Example usage

make build

mkdir memcached-operator
cd memcached-operator

../ansible-operator scaffold init --domain example.com

../ansible-operator scaffold create api --group cache --version v1alpha1 --kind Memcached --generate-role

@chiragkyal chiragkyal force-pushed the ansible-cli branch 2 times, most recently from dd1bd80 to 0617ee8 Compare June 17, 2025 13:25
@chiragkyal chiragkyal changed the title Add new CLI for ansible plugin Add standalone ansible-cli command and release binaries Jun 17, 2025
Copy link
Contributor

@acornett21 acornett21 left a comment

Choose a reason for hiding this comment

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

IMO this doesn't need to be a separate binary build, this will confuse uses at release time. Just make this plunging available at the top level of the existing cmd entry point.

Signed-off-by: chiragkyal <ckyal@redhat.com>
Signed-off-by: chiragkyal <ckyal@redhat.com>
@chiragkyal chiragkyal changed the title Add standalone ansible-cli command and release binaries Add ansible plugin scaffold command into existing binary Jun 18, 2025
@chiragkyal chiragkyal changed the title Add ansible plugin scaffold command into existing binary Add ansible plugin scaffolding command into ansible-operator binary Jun 18, 2025

func GetPluginsCLI() *cli.CLI {
ansibleBundle, _ := plugin.NewBundleWithOptions(
plugin.WithName(ansible.Plugin{}.Name()),

Choose a reason for hiding this comment

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

We might not want to have base.ansible.sdk.operatorframework.io/v1 since it is not a base for Ansible ( only Ansible code without the config/ generated by kustomize/v2 ), so we might wish to to change it to be called ansible.operatorframework.io/v1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Updated the plugin name to reflect ansible.operatorframework.io/v1

)
pkg.CheckError("getting cli implementation:", err)
return c
return scaffold.GetPluginsCLI()
Copy link

@camilamacedo86 camilamacedo86 Jun 20, 2025

Choose a reason for hiding this comment

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

We should not include this code here.
Instead, we must ensure that the hack generator uses the actual binary, rather than mocking the CLI and invoking it directly.
The binary should be built locally and used during generation to validate that everything functions correctly—this is the approach taken in the Operator SDK.

Reference: operator-sdk/hack/generate/samples/generate_testdata.go#L30-L37
c/c @acornett21 ^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The binary should be built locally and used during generation to validate that everything functions correctly—this is the approach taken in the Operator SDK.

I think the current approach follows a deliberate design choice made in #4 PR, after which we are now generating the testdata on the fly using the helper library.
This PR is trying to unify the testdata generation with the binary's command execution. We created a single entrypoint (GetPluginsCLI()) that is called by both the main function for the final binary and by the hack script that generates the test samples.
It ensures that our testdata is always generated using the exact same logic and configuration that the end-user's binary will have. It creates a tight coupling that prevents any possible divergence between the test suite and the released artifact.

This change is a continuation of the existing pattern. I think we are not breaking the testdata generation flow or logic.

Signed-off-by: chiragkyal <ckyal@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants