|
| 1 | +# Kustomize Plugin |
| 2 | + |
| 3 | +The kustomize plugin allows you to scaffold all kustomize manifests used to work with the language plugins such as `go/v2` and `go/v3`. |
| 4 | +By using the kustomize plugin, you can create your own language plugins and ensure that you will have the same configurations |
| 5 | +and features provided by it. |
| 6 | + |
| 7 | +Note that projects such as [Operator-sdk][sdk] consume the Kubebuilder project as a lib and provide options to work with other languages |
| 8 | +like Ansible and Helm. The kustomize plugin allows them to easily keep a maintained configuration and ensure that all languages have |
| 9 | +the same configuration. It is also helpful if you are looking to provide nice plugins which will perform changes on top of |
| 10 | +what is scaffolded by default. With this approach we do not need to keep manually updating this configuration in all possible language plugins |
| 11 | +which uses the same and we are also |
| 12 | +able to create "helper" plugins which can work with many projects and languages. |
| 13 | + |
| 14 | +<aside class="note"> |
| 15 | +<h1>Examples</h1> |
| 16 | + |
| 17 | +You can check the kustomize content by looking at the `config/` directory. Samples are provided under the [testdata][testdata] |
| 18 | +directory of the Kubebuilder project. |
| 19 | + |
| 20 | +</aside> |
| 21 | + |
| 22 | + |
| 23 | +## When to use it |
| 24 | + |
| 25 | +- If you are looking to scaffold the kustomize configuration manifests for your own language plugin |
| 26 | + |
| 27 | +## How to use it |
| 28 | + |
| 29 | +If you are looking to define that your language plugin should use kustomize use the [Bundle Plugin][bundle] |
| 30 | +to specify that your language plugin is a composition with your plugin responsable for scaffold |
| 31 | +all that is laguage specific and kustomize for its configuration, see: |
| 32 | + |
| 33 | +```go |
| 34 | + // Bundle plugin which built the golang projects scaffold by Kubebuilder go/v3 |
| 35 | + // The follow code is creating a new plugin with its name and version via composition |
| 36 | + // You can define that one plugin is composite by 1 or Many others plugins |
| 37 | + gov3Bundle, _ := plugin.NewBundle(golang.DefaultNameQualifier, plugin.Version{Number: 3}, |
| 38 | + kustomizecommonv1.Plugin{}, // scaffold the config/ directory and all kustomize files |
| 39 | + golangv3.Plugin{}, // Scaffold the Golang files and all that specific for the language e.g. go.mod, apis, controllers |
| 40 | + ) |
| 41 | +``` |
| 42 | + |
| 43 | +Also, with Kubebuilder, you can use kustomize alone via: |
| 44 | + |
| 45 | +```sh |
| 46 | +kubebuilder init --plugins=kustomize/v1 |
| 47 | +$ ls -la |
| 48 | +total 24 |
| 49 | +drwxr-xr-x 6 camilamacedo86 staff 192 31 Mar 09:56 . |
| 50 | +drwxr-xr-x 11 camilamacedo86 staff 352 29 Mar 21:23 .. |
| 51 | +-rw------- 1 camilamacedo86 staff 129 26 Mar 12:01 .dockerignore |
| 52 | +-rw------- 1 camilamacedo86 staff 367 26 Mar 12:01 .gitignore |
| 53 | +-rw------- 1 camilamacedo86 staff 94 31 Mar 09:56 PROJECT |
| 54 | +drwx------ 6 camilamacedo86 staff 192 31 Mar 09:56 config |
| 55 | +``` |
| 56 | + |
| 57 | +Or combined with the base language plugins: |
| 58 | + |
| 59 | +```sh |
| 60 | +# Provides the same scaffold of go/v3 plugin which is a composition (kubebuilder init --plugins=go/v3) |
| 61 | +kubebuilder init --plugins=kustomize/v1,base.go.kubebuilder.io/v3 --domain example.org --repo example.org/guestbook-operator |
| 62 | +``` |
| 63 | + |
| 64 | +## Subcommands |
| 65 | + |
| 66 | +The kustomize plugin implements the following subcommands: |
| 67 | + |
| 68 | +* init (`$ kubebuilder init [OPTIONS]`) |
| 69 | +* create api (`$ kubebuilder create api [OPTIONS]`) |
| 70 | +* create webhook (`$ kubebuilder create api [OPTIONS]`) |
| 71 | + |
| 72 | +<aside class="note"> |
| 73 | +<h1>Create API and Webhook</h1> |
| 74 | + |
| 75 | +Its implementation for the subcommand create api will scaffold the kustomize manifests |
| 76 | +which are specific for each API, see [here][kustomize-create-api]. The same applies |
| 77 | +to its implementation for create webhook. |
| 78 | + |
| 79 | +</aside> |
| 80 | + |
| 81 | +## Affected files |
| 82 | + |
| 83 | +The following scaffolds will be created or updated by this plugin: |
| 84 | + |
| 85 | +* `config/*` |
| 86 | + |
| 87 | +## Further resources |
| 88 | + |
| 89 | +* Check the kustomize [plugin implementation](https://github.com/kubernetes-sigs/kubebuilder/tree/master/pkg/plugins/common/kustomize) |
| 90 | +* Check the [kustomize documentation][kustomize-docs] |
| 91 | +* Check the [kustomize repository][kustomize-github] |
| 92 | + |
| 93 | +[sdk]:https://github.com/operator-framework/operator-sdk |
| 94 | +[testdata]: https://github.com/kubernetes-sigs/kubebuilder/tree/master/testdata/ |
| 95 | +[bundle]: https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugin/bundle.go |
| 96 | +[kustomize-create-api]: https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/common/kustomize/v1/scaffolds/api.go#L72-L84 |
| 97 | +[kustomize-docs]: https://kustomize.io/ |
| 98 | +[kustomize-github]: https://github.com/kubernetes-sigs/kustomize |
0 commit comments