|
1 |
| -# CNPG-I-EXAMPLE |
| 1 | +# CNPG-I Hello World Plugin |
2 | 2 |
|
3 |
| -A "hello world" example implementation of the |
4 |
| -[CloudNativePG](https://github.com/cloudnative-pg/cloudnative-pg/) |
5 |
| -plugin interface [CNPG-I](https://github.com/cloudnative-pg/cnpg-i). |
| 3 | +A [CNPG-I](https://github.com/cloudnative-pg/cnpg-i) plugin to add labels and |
| 4 | +annotations |
| 5 | +to [CloudNativePG](https://github.com/cloudnative-pg/cloudnative-pg/) clusters. |
6 | 6 |
|
7 |
| -- [Concepts](doc/concepts.md) |
8 |
| -- [Workflow](doc/workflow.md) |
| 7 | +This project serves as an introductory guide to bootstrapping |
| 8 | +a [CNPG-I](https://github.com/cloudnative-pg/cnpg-i) plugin and leveraging |
| 9 | +lifecycle hooks within a development environment. While similar results can be |
| 10 | +achieved through simpler methods such as mutating webhooks or CNPG's built-in |
| 11 | +features, this project is specifically designed to familiarize developers with |
| 12 | +the plugin workflow. By understanding how lifecycle hooks interact with other |
| 13 | +interfaces, developers can gain a deeper insight into implementing complex |
| 14 | +resource changes in real-world applications. |
9 | 15 |
|
10 |
| -This plugin uses the [pluginhelper](https://github.com/cloudnative-pg/cnpg-i-machinery/tree/main/pkg/pluginhelper) from [`cnpg-i-machinery`](https://github.com/cloudnative-pg/cnpg-i-machinery) to simplify the plugin's implementation. |
| 16 | +This plugin uses |
| 17 | +the [pluginhelper](https://github.com/cloudnative-pg/cnpg-i-machinery/tree/main/pkg/pluginhelper) |
| 18 | +from [`cnpg-i-machinery`](https://github.com/cloudnative-pg/cnpg-i-machinery) to |
| 19 | +simplify the plugin's implementation. |
| 20 | + |
| 21 | +## Running the plugin |
| 22 | + |
| 23 | +To see the plugin in execution, you need to have a Kubernetes cluster running |
| 24 | +(we'll use [Kind](https://kind.sigs.k8s.io)) and the |
| 25 | +[CloudNativePG](https://github.com/cloudnative-pg/cloudnative-pg/) operator |
| 26 | +installed. The plugin also requires certificates to communicate with the |
| 27 | +operator, hence we are also installing [cert-manager](https://cert-manager.io/) |
| 28 | +to manage them. |
| 29 | + |
| 30 | +``` shell |
| 31 | +kind create cluster --name cnpg-i-hello-world |
| 32 | +# Choose the latest version of CloudNativePG (at least 1.24) |
| 33 | +kubectl apply --server-side -f \ |
| 34 | + https://github.com/cloudnative-pg/cloudnative-pg/releases/download/vX.Y.Z/cnpg-X.Y.Z.yaml |
| 35 | +# Choose the latest version of cert-manager |
| 36 | +kubectl apply -f \ |
| 37 | + https://github.com/cert-manager/cert-manager/releases/download/vX.Y.Z/cert-manager.yaml |
| 38 | +``` |
| 39 | + |
| 40 | +Then install the plugin by applying the manifest: |
| 41 | + |
| 42 | +<!-- TODO: reevaluate on release and set release-please to automatically update it--> |
| 43 | + |
| 44 | +``` shell |
| 45 | +kubectl apply -f https://github.com/cloudnative-pg/cnpg-i-hello-world/releases/download/v0.1.0/manifest.yaml |
| 46 | +``` |
| 47 | + |
| 48 | +Finally, create a cluster resource to see the plugin in action. There are three |
| 49 | +examples in the `doc/examples` directory: |
| 50 | + |
| 51 | +1. [Cluster with labels and annotations](doc/examples/cluster-example.yaml): |
| 52 | + adds the defined labels and annotations to the pods. Showcases the plugin |
| 53 | + capability of altering the lifecycle of the CloudNativePG resources. |
| 54 | +2. [Cluster with no parameters](doc/examples/cluster-example-no-parameters.yaml): |
| 55 | + defaults the plugin settings of the cluster. Showcases the plugin capability |
| 56 | + of altering the defaulting webhook behavior. |
| 57 | +3. [Cluster with wrong parameters](doc/examples/cluster-example-with-mistake.yaml): |
| 58 | + includes an error in the configuration. Showcases the plugin capability of |
| 59 | + validating its own configuration. |
| 60 | + |
| 61 | +## Plugin development |
| 62 | + |
| 63 | +For additional details on the plugin implementation refer to |
| 64 | +the [development documentation](doc/development.md). |
0 commit comments