-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sebastian Hoß <[email protected]>
- Loading branch information
Showing
2 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: The kube-custom-resources-rs Authors | ||
SPDX-License-Identifier: 0BSD | ||
--> | ||
|
||
# Contributor Guide | ||
|
||
:+1::tada: Thanks a lot for taking your time to contribute! :tada::+1: | ||
|
||
## Adding new CRDs | ||
|
||
To add new custom resource definitions to this project, please follow the steps outlined below. If anything is unclear or does not work on your computer, please don't hesitate to reach out or just create a partial pull request on GitHub with your current progress. | ||
|
||
### 0. Required Software | ||
|
||
In order to run all the commands mentioned below, you will need the following installed on your computer: | ||
|
||
- `rust`/`cargo`: https://www.rust-lang.org/tools/install | ||
- `kopium`: https://github.com/kube-rs/kopium | ||
- `yq`: https://github.com/mikefarah/yq | ||
- `bash`: https://www.gnu.org/software/bash/ | ||
|
||
### 1. Add CRD to catalog | ||
|
||
All CRDs of this project are managed in the [catalog](https://github.com/metio/kube-custom-resources-rs/blob/main/code-generator/src/catalog.rs) which contains a long list of projects along with the CRDs they are producing. We try to sort this list alphabetically in order to make it easier finding things, but this is not a hard requirement for your contribution. Each entry requires the following details: | ||
|
||
- `project_name`: The organization and name of a project, e.g. `prometheus-operator/prometheus-operator` is used for the project at https://github.com/prometheus-operator/prometheus-operator. | ||
- `license`: The SPDX license identifier for the CRD files. This is usually the same license as the project and the catalog file already contains constants for the most common licenses. | ||
- `urls`: The list of URLs where CRDs are located. It does not matter if that file contains other Kubernetes resources, our tooling will only extract CRDs from those files. | ||
|
||
### 2. Fetch the CRD | ||
|
||
We save a copy of all CRDs as part of this repository. In order to fetch your newly added CRDs run: | ||
|
||
```console | ||
$ cargo run --package code-generator --bin crd_v1_fetcher <project_name> | ||
``` | ||
|
||
The `<project_name>` argument is the same value you added to the catalog in step 1, e.g.: | ||
|
||
```console | ||
$ cargo run --package code-generator --bin crd_v1_fetcher prometheus-operator/prometheus-operator | ||
``` | ||
|
||
Note: You can run that binary without any argument in which case it will download **all** CRDs in the catalog. | ||
|
||
### 3. Update the dep5 file | ||
|
||
We want to be a [reuse](https://reuse.software/) compliant project and therefore need to attribute each file with its proper license. The [dep5](./.reuse/dep5) file contains license information for all CRDs. It is automatically generated by calling the following command and uses the license information you added to the catalog in step 1: | ||
|
||
```console | ||
$ cargo run --package code-generator --bin dep5_generator | ||
``` | ||
|
||
### 4. Generate Custom Resources | ||
|
||
Once we have all CRDs, we can generate Rust code for the custom resources with [kopium](https://github.com/kube-rs/kopium) by calling the following bash script from the root of this project: | ||
|
||
```console | ||
$ ./code-generator/generate.sh <project_name> | ||
``` | ||
|
||
The `<project_name>` argument is again the same value you added to the catalog in step 1, e.g.: | ||
|
||
```console | ||
$ ./code-generator/generate.sh prometheus-operator/prometheus-operator | ||
``` | ||
|
||
Note: You can run that script without any argument in which case it will generate code for **all** CRDs in the catalog. | ||
|
||
### 5. Update lib.rs | ||
|
||
Each group/version of every Kubernetes kind has its own feature in this project. All of them are referenced in the [lib.rs](./kube-custom-resources-rs/src/lib.rs) file which is automatically generated by calling: | ||
|
||
```console | ||
$ cargo run --package code-generator --bin lib_rs_generator | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters