Skip to content

Commit

Permalink
(doc) - refactory and clenup the Plugin section
Browse files Browse the repository at this point in the history
Over time, this section has grown incrementally, leading to content duplication and outdated or irrelevant information. To address this, we are now:

- Re-organizing the structure for better clarity.
- Fixing broken or outdated links.
- Removing duplicated and obsolete content.
- Re-writing and refining parts of the sections to ensure accuracy and relevance.
- Ensuring the Kubebuilder layout doc's standards
  • Loading branch information
camilamacedo86 committed Oct 9, 2024
1 parent 820b71d commit 3f1f568
Show file tree
Hide file tree
Showing 22 changed files with 1,115 additions and 917 deletions.
2 changes: 1 addition & 1 deletion VERSIONING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ take care of building and publishing the artifacts.
[envtest-ref]: https://book.kubebuilder.io/reference/artifacts.html
[tools-branch]: https://github.com/kubernetes-sigs/kubebuilder/tree/tools-releases
[kb-releases]:https://github.com/kubernetes-sigs/kubebuilder/releases
[cli-plugins-versioning]:docs/book/src/plugins/extending-cli.md#plugin-versioning
[cli-plugins-versioning]:docs/book/src/plugins/extending#plugin-versioning
20 changes: 9 additions & 11 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,16 @@
- [Plugins][plugins]

- [Available Plugins](./plugins/available-plugins.md)
- [To scaffold a project](./plugins/to-scaffold-project.md)
- [go/v4 (Default init scaffold)](./plugins/go-v4-plugin.md)
- [To add optional features](./plugins/to-add-optional-features.md)
- [grafana/v1-alpha](./plugins/grafana-v1-alpha.md)
- [deploy-image/v1-alpha](./plugins/deploy-image-plugin-v1-alpha.md)
- [To be extended for others tools](./plugins/to-be-extended.md)
- [kustomize/v2 (Default init scaffold with go/v4)](./plugins/kustomize-v2.md)
- [Extending the CLI](./plugins/extending-cli.md)
- [Creating your own plugins](./plugins/creating-plugins.md)
- [Testing your own plugins](./plugins/testing-plugins.md)
- [go/v4](./plugins/available/go-v4-plugin.md)
- [grafana/v1-alpha](./plugins/available/grafana-v1-alpha.md)
- [deploy-image/v1-alpha](./plugins/available/deploy-image-plugin-v1-alpha.md)
- [kustomize/v2](./plugins/available/kustomize-v2.md)
- [Extending](./plugins/extending.md)
- [CLI and Plugins](./plugins/extending/extending_cli_features_and_plugins.md)
- [External Plugins](./plugins/extending/external-plugins.md)
- [E2E Tests](./plugins/extending/testing-plugins.md)
- [Plugins Versioning](./plugins/plugins-versioning.md)
- [Creating external plugins](./plugins/external-plugins.md)


---

Expand Down
8 changes: 1 addition & 7 deletions docs/book/src/plugins/available-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@ This section describes the plugins supported and shipped in with the Kubebuilder
{{#include to-add-optional-features.md }}
{{#include to-be-extended.md }}

<aside class="note">

<h1>Plugins Versioning</h1>

**ALPHA** plugins can introduce breaking changes. For further info see [Plugins Versioning](./plugins/plugins-versioning.md).

</aside>
[plugin-versions]: plugins-versioning.md
111 changes: 111 additions & 0 deletions docs/book/src/plugins/available/deploy-image-plugin-v1-alpha.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Deploy Image Plugin (deploy-image/v1-alpha)

The `deploy-image` plugin allows users to create [controllers][controller-runtime] and custom resources that deploy and manage container images on the cluster, following Kubernetes best practices. It simplifies the complexities of deploying images while allowing users to customize their projects as needed.

By using this plugin, you will get:

- A controller implementation to deploy and manage an Operand (image) on the cluster.
- Tests to verify the reconciliation logic, using [ENVTEST][envtest].
- Custom resource samples updated with the necessary specifications.
- Environment variable support for managing the Operand (image) within the manager.

<aside class="note">
<h1>Examples</h1>

See the `project-v4-with-plugins` directory under the [testdata][testdata]
directory in the Kubebuilder project to check an example
of scaffolding created using this plugin.

The `Memcached` API and its controller was scaffolded
using the command:

```shell
kubebuilder create api \
--group example.com \
--version v1alpha1 \
--kind Memcached \
--image=memcached:memcached:1.6.26-alpine3.19 \
--image-container-command="memcached,--memory-limit=64,-o,modern,-v" \
--image-container-port="11211" \
--run-as-user="1001" \
--plugins="deploy-image/v1-alpha"
```

The `Busybox` API was created with:

```shell
kubebuilder create api \
--group example.com \
--version v1alpha1 \
--kind Busybox \
--image=busybox:1.36.1 \
--plugins="deploy-image/v1-alpha"
```
</aside>


## When to use it?

- This plugin is ideal for users who are just getting started with Kubernetes operators.
- It helps users deploy and manage an image (Operand) using the [Operator pattern][operator-pattern].
- If you're looking for a quick and efficient way to set up a custom controller and manage a container image, this plugin is a great choice.

## How to use it?

1. **Initialize your project**:
After creating a new project with `kubebuilder init`, you can use this
plugin to create APIs. Ensure that you've completed the
[quick start][quick-start] guide before proceeding.

2. **Create APIs**:
With this plugin, you can [create APIs][create-apis] to specify the image (Operand) you want to deploy on the cluster. You can also optionally specify the command, port, and security context using various flags:

Example command:
```sh
kubebuilder create api --group example.com --version v1alpha1 --kind Memcached --image=memcached:1.6.15-alpine --image-container-command="memcached,--memory-limit=64,modern,-v" --image-container-port="11211" --run-as-user="1001" --plugins="deploy-image/v1-alpha"
```

<aside class="warning">
<h1>Note on make run:</h1>

When running the project locally with `make run`, the Operand image
provided will be stored as an environment variable in the
`config/manager/manager.yaml` file.

Ensure you export the environment variable before running the project locally, such as:

```shell
export MEMCACHED_IMAGE="memcached:1.4.36-alpine"
```

</aside>

## Subcommands

The `deploy-image` plugin includes the following subcommand:

- `create api`: Use this command to scaffold the API and controller code to manage the container image.

## Affected files

When using the `create api` command with this plugin, the following
files are affected, in addition to the existing Kubebuilder scaffolding:

- `controllers/*_controller_test.go`: Scaffolds tests for the controller.
- `controllers/*_suite_test.go`: Scaffolds or updates the test suite.
- `api/<version>/*_types.go`: Scaffolds the API specs.
- `config/samples/*_.yaml`: Scaffolds default values for the custom resource.
- `main.go`: Updates the file to add the controller setup.
- `config/manager/manager.yaml`: Updates to include environment variables for storing the image.

## Further Resources:

- Check out this [video][video] to see how it works.

[video]: https://youtu.be/UwPuRjjnMjY
[operator-pattern]: https://kubernetes.io/docs/concepts/extend-kubernetes/operator/
[controller-runtime]: https://github.com/kubernetes-sigs/controller-runtime
[testdata]: ./.././../../../../testdata/project-v4-with-plugins
[envtest]: ./../../reference/envtest.md
[quick-start]: ./../../quick-start.md
[create-apis]: ../../cronjob-tutorial/new-api.md
53 changes: 53 additions & 0 deletions docs/book/src/plugins/available/go-v4-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# go/v4 (go.kubebuilder.io/v4)

**(Default Scaffold)**

Kubebuilder will scaffold using the `go/v4` plugin only if specified when initializing the project.
This plugin is a composition of the `kustomize.common.kubebuilder.io/v2` and `base.go.kubebuilder.io/v4` plugins
using the [Bundle Plugin][bundle]. It scaffolds a project template
that helps in constructing sets of [controllers][controller-runtime].

By following the [quickstart][quickstart] and creating any project,
you will be using this plugin by default.

<aside class="note">
<h1>Examples</h1>

You can check samples using this plugin by looking at the `project-v4-<options>` projects under the [testdata][testdata]
directory on the root directory of the Kubebuilder project.

</aside>

## How to use it ?

To create a new project with the `go/v4` plugin the following command can be used:

```sh
kubebuilder init --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io/project --plugins=go/v4
```

## Subcommands supported by the plugin

- Init - `kubebuilder init [OPTIONS]`
- Edit - `kubebuilder edit [OPTIONS]`
- Create API - `kubebuilder create api [OPTIONS]`
- Create Webhook - `kubebuilder create webhook [OPTIONS]`

## Further resources

- To see the composition of plugins, you can check the source code for the Kubebuilder [main.go][plugins-main].
- Check the code implementation of the [base Golang plugin `base.go.kubebuilder.io/v4`][v4-plugin].
- Check the code implementation of the [Kustomize/v2 plugin][kustomize-plugin].
- Check [controller-runtime][controller-runtime] to know more about controllers.

[controller-runtime]: https://github.com/kubernetes-sigs/controller-runtime
[quickstart]: ./../../quick-start.md
[testdata]: ./../../../../../testdata
[plugins-main]: ./../../../../../cmd/main.go
[kustomize-plugin]: ./../../plugins/avaialable/kustomize-v2.md
[kustomize]: https://github.com/kubernetes-sigs/kustomize
[standard-go-project]: https://github.com/golang-standards/project-layout
[v4-plugin]: ./../../../../../pkg/plugins/golang/v4
[migration-guide-doc]: ./../../migration/migration_guide_gov3_to_gov4.md
[project-doc]: ./../../reference/project-config.md
[bundle]: ./../../../../../pkg/plugin/bundle.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Grafana Plugin (`grafana/v1-alpha`)

The Grafana plugin is an optional plugin that can be used to scaffold Grafana Dashboards to allow you to check out the default metrics which are exported by projects using [controller-runtime][controller-runtime].
The Grafana plugin is an optional plugin that can be used to
scaffold Grafana Dashboards to allow you to check out the
default metrics which are exported by projects
using [controller-runtime][controller-runtime].

<aside class="note">
<h1>Examples</h1>

You can check its default scaffold by looking at the `project-v3-with-metrics` projects under the [testdata][testdata] directory on the root directory of the Kubebuilder project.
You can check its default scaffold by looking at the `project-v4-with-plugins` projects
under the [testdata][testdata] directory on the root directory of the Kubebuilder project.

</aside>

## When to use it ?

- If you are looking to observe the metrics exported by [controller metrics][controller-metrics] and collected by Prometheus via [Grafana][grafana].
- If you are looking to observe the metrics
exported by [controller metrics][controller-metrics] and
collected by Prometheus via [Grafana][grafana].

## How to use it ?

Expand All @@ -21,10 +27,10 @@ You can check its default scaffold by looking at the `project-v3-with-metrics` p
- Access to [Prometheus][prometheus].
- Prometheus should have an endpoint exposed. (For `prometheus-operator`, this is similar as: http://prometheus-k8s.monitoring.svc:9090 )
- The endpoint is ready to/already become the datasource of your Grafana. See [Add a data source](https://grafana.com/docs/grafana/latest/datasources/add-a-data-source/)
- Access to [Grafana](https://grafana.com/docs/grafana/latest/setup-grafana/installation/). Make sure you have:
- [Dashboard edit permission](https://grafana.com/docs/grafana/next/administration/roles-and-permissions/#dashboard-permissions)
- Access to [Grafana][grafana-install]. Make sure you have:
- [Dashboard edit permission][grafana-permissions]
- Prometheus Data source
![pre](https://user-images.githubusercontent.com/18136486/176119794-f6d69b0b-93f0-4f9e-a53c-daf9f77dadae.gif)
![pre][prometheus-data-source]

<aside class="note">

Expand Down Expand Up @@ -204,7 +210,7 @@ This time, the plugin will generate `grafana/custom-metrics/custom-metrics-dashb

See an example of how to visualize your custom metrics:

![output2](https://user-images.githubusercontent.com/18136486/186933170-d2e0de71-e079-4d1b-906a-99a549d66ebf.gif)
![output2][show-case]

## Subcommands

Expand All @@ -222,22 +228,29 @@ The following scaffolds will be created or updated by this plugin:

## Further resources

- Check out [video to show how it works](https://youtu.be/-w_JjcV8jXc)
- Checkout the [video to show how the custom metrics feature works](https://youtu.be/x_0FHta2HXc)
- Refer to a sample of `servicemonitor` provided by [kustomize plugin][kustomize-plugin]
- Check out [video to show how it works][video]
- Checkout the [video to show how the custom metrics feature works][video-custom-metrics]
- Refer to a sample of `serviceMonitor` provided by [kustomize plugin][kustomize-plugin]
- Check the [plugin implementation][plugin-implementation]
- [Grafana Docs][grafana-docs] of importing JSON file
- The usage of servicemonitor by [Prometheus Operator][servicemonitor]
- The usage of serviceMonitor by [Prometheus Operator][servicemonitor]

[controller-metrics]: https://book.kubebuilder.io/reference/metrics-reference.html
[controller-runtime]: https://github.com/kubernetes-sigs/controller-runtime
[grafana]: https://grafana.com/docs/grafana/next/
[grafana-docs]: https://grafana.com/docs/grafana/latest/dashboards/export-import/#import-dashboard
[kustomize-plugin]: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v3/config/prometheus/monitor.yaml
[kube-prometheus]: https://github.com/prometheus-operator/kube-prometheus
[plugin-implementation]: https://github.com/kubernetes-sigs/kubebuilder/tree/master/pkg/plugins/optional/grafana/alphav1
[prometheus]: https://prometheus.io/docs/introduction/overview/
[prom-operator]: https://prometheus-operator.dev/docs/prologue/introduction/
[reference-metrics-doc]: https://book.kubebuilder.io/reference/metrics.html#exporting-metrics-for-prometheus
[servicemonitor]: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/getting-started.md#related-resources
[testdata]: https://github.com/kubernetes-sigs/kubebuilder/tree/master/testdata
[grafana-install]: https://grafana.com/docs/grafana/latest/setup-grafana/installation/
[grafana-permissions]: https://grafana.com/docs/grafana/next/administration/roles-and-permissions/#dashboard-permissions
[prometheus-data-source]: https://user-images.githubusercontent.com/18136486/176119794-f6d69b0b-93f0-4f9e-a53c-daf9f77dadae.gif
[video]: https://youtu.be/-w_JjcV8jXc
[video-custom-metrics]: https://youtu.be/x_0FHta2HXc
[show-case]: https://user-images.githubusercontent.com/18136486/186933170-d2e0de71-e079-4d1b-906a-99a549d66ebf.gif
[controller-metrics]: ./../../reference/metrics-reference.md
[kustomize-plugin]: ./../../../../../testdata/project-v4-with-plugins/config/prometheus/monitor.yaml
[plugin-implementation]: ./../../../../../pkg/plugins/optional/grafana/
[reference-metrics-doc]: ./../../reference/metrics.md#exporting-metrics-for-prometheus
[testdata]: https://github.com/kubernetes-sigs/kubebuilder/tree/master/testdata/project-v4-with-plugins

Loading

0 comments on commit 3f1f568

Please sign in to comment.