kubebuilder icon indicating copy to clipboard operation
kubebuilder copied to clipboard

Document helpers and options to write plugins

Open camilamacedo86 opened this issue 3 years ago • 4 comments
trafficstars

What do you want to happen?

Would be nice if we could add to docs the following info to help those that are looking to build their own plugins:

If you are looking to create an external plugin that will add code on top of what is scaffold by default with the create API see that we do that in deploy-image here and you have many ways to achieve this goal:

  • a) You can overwrite the scaffold done with the go/v3 (for example) by using this option: https://github.com/kubernetes-sigs/kubebuilder/blob/df1ed6ccf19df40bd929157a91eaae6a9215bfc6/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go#L58

  • b) You can use the plugin utils to inject and/or replace code, see: https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/api.go#L170-L266

  • c) Note that you can call create api --plugins=go/v3,yourplugin/v1 and just ensure that the create api subcommand will overwrite or you can import the code as we decide to do in the deploy image to allow re-use it and make eaiser for users just call create api --plugins=deploy.image/v1alpha1, see: https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/api.go#L77-L98

Another option also is to use the Bundle Plugin which will build a new plugin done by composition that does the call in chain as we can do by --plugins=a/v1,b/v2 and, see: https://book.kubebuilder.io/plugins/creating-plugins.html

  mylanguagev1Bundle, _ := plugin.NewBundle(language.DefaultNameQualifier, plugin.Version{Number: 1},
        kustomizecommonv1.Plugin{}, // extend the common base from Kuebebuilder
        mylanguagev1.Plugin{}, // your plugin language which will do the scaffolds for the specific language on top of the common base
    )

Motivated by: https://github.com/kubernetes-sigs/kubebuilder/issues/2871

Extra Labels

/kind documentation

camilamacedo86 avatar Aug 15 '22 12:08 camilamacedo86

Hi @Kavinjsir,

This one is to doc how to use the helper and options. You did some docs already, so you might want to look if we can improve the docs for we finish this one.

camilamacedo86 avatar Oct 01 '22 09:10 camilamacedo86

Hi @camilamacedo86 , the idea here looks good to me. Since you've already provided rich context above, it looks a great support for me to start. Before moving on, I have some questions:

  1. Where would you like to have the documentation in book? Maybe add a new section in create-your-own-plugin?
  2. Are you suggesting that we may provide two recommended patterns (as you mentioned above) to developers, so that they would create plugins following the ideas without misunderstanding?
  3. Is that the first pattern consists of 3 steps (a -> b -> c) , and, that is to say, creating a new external plugin can be similar as how deploy-image is implemented?
  4. For the another option as you mentioned, is that to instruct developers to create a bundle of plugins chains if necessary; that is to say: apply an integration work between kb plugins and the external one?

Kavinjsir avatar Oct 06 '22 03:10 Kavinjsir

/assign

Kavinjsir avatar Oct 06 '22 03:10 Kavinjsir

HI @Kavinjsir,

My idea here would to be supplement the docs (I think create-your-own-plugin is a good place for that) to provide the info in the description. So that, we can help out those that are looking to build their own plugins.

See that it was required to help out in the discussion topic linked here.

camilamacedo86 avatar Oct 06 '22 13:10 camilamacedo86