sigs.k8s.io/kubebuilder/v3@v3.14.0/CONTRIBUTING.md (about) 1 # Contributing guidelines 2 3 This document describes how to contribute to the project. 4 5 ## Sign the CLA 6 7 Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests. 8 9 Please see https://git.k8s.io/community/CLA.md for more info. 10 11 ## Prerequisites 12 13 - [go](https://golang.org/dl/) version v1.21+. 14 - [docker](https://docs.docker.com/install/) version 17.03+. 15 - [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) version v1.11.3+. 16 - [kustomize](https://github.com/kubernetes-sigs/kustomize/blob/master/site/content/en/docs/Getting%20started/installation.md) v3.1.0+ 17 - Access to a Kubernetes v1.11.3+ cluster. 18 19 ## Contributing steps 20 21 1. Submit an issue describing your proposed change to the repo in question. 22 1. The [repo owners](OWNERS) will respond to your issue promptly. 23 1. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above). 24 1. Fork the desired repo, develop and test your code changes. 25 1. Submit a pull request. 26 27 In addition to the above steps, we adhere to the following best practices to maintain consistency and efficiency in our project: 28 29 - **Single Commit per PR:** Each Pull Request (PR) should contain only one commit. This approach simplifies tracking changes and makes the history more readable. 30 - **One Issue per PR:** Each PR should address a single specific issue or need. This helps in streamlining our workflow and makes it easier to identify and resolve problems such as revert the changes if required. 31 32 For more detailed guidelines, refer to the [Kubernetes Contributor Guide][k8s-contrubutiong-guide]. 33 34 ## How to build kubebuilder locally 35 36 Note that, by building the kubebuilder from the source code we are allowed to test the changes made locally. 37 38 1. Run the following command to clone your fork of the project locally in the dir /src/sigs.k8s.io/kubebuilder 39 40 ``` 41 $ git clone git@github.com:<user>/kubebuilder.git $GOPATH/src/sigs.k8s.io/kubebuilder 42 ``` 43 44 1. Ensure you activate module support before continue (`$ export GO111MODULE=on`) 45 1. Run the command `make install` to create a bin with the source code 46 47 **NOTE** In order to check the local environment run `make test-unit`. 48 49 ## What to do before submitting a pull request 50 51 1. Run the script `make generate` to update/generate the mock data used in the e2e test in `$GOPATH/src/sigs.k8s.io/kubebuilder/testdata/` 52 1. Run `make test-unit test-e2e-local` 53 54 - e2e tests use [`kind`][kind] and [`setup-envtest`][setup-envtest]. If you want to bring your own binaries, place them in `$(go env GOPATH)/bin`. 55 56 **IMPORTANT:** The `make generate` is very helpful. By using it, you can check if good part of the commands still working successfully after the changes. Also, note that its usage is a pre-requirement to submit a PR. 57 58 Following the targets that can be used to test your changes locally. 59 60 | Command | Description | Is called in the CI? | 61 | ------------------- | ------------------------------------------------------------- | -------------------- | 62 | make test-unit | Runs go tests | no | 63 | make test | Runs tests in shell (`./test.sh`) | yes | 64 | make lint | Run [golangci][golangci] lint checks | yes | 65 | make lint-fix | Run [golangci][golangci] to automatically perform fixes | no | 66 | make test-coverage | Run coveralls to check the % of code covered by tests | yes | 67 | make check-testdata | Checks if the testdata dir is updated with the latest changes | yes | 68 | make test-e2e-local | Runs the CI e2e tests locally | no | 69 70 **NOTE** To use the `make lint` is required to install `golangci-lint` locally. More info: https://github.com/golangci/golangci-lint#install 71 72 ### Test Plugin 73 74 If your intended PR creates a new plugin, make sure the PR also provides test cases. Testing should include: 75 76 1. `e2e tests` to validate the behavior of the proposed plugin. 77 2. `sample projects` to verify the scaffolded output from the plugin. 78 79 #### 1. Plugin E2E Tests 80 81 All the plugins provided by Kubebuilder should be validated through `e2e-tests` across multiple platforms. 82 83 Current Kubebuilder provides the testing framework that includes testing code based on [ginkgo](https://github.com/onsi/ginkgo), [Github Actions](https://github.com/Kavinjsir/kubebuilder/blob/docs%2Ftest-plugin/.github/workflows/testdata.yml) for unit tests, and multiple env tests driven by [test-infra](https://github.com/kubernetes/test-infra/blob/master/config/jobs/kubernetes-sigs/kubebuilder/kubebuilder-presubmits.yaml). 84 85 To fully test the proposed plugin: 86 87 1. Create a new package(folder) under `test/e2e/<your-plugin>`. 88 2. Create [e2e_suite_test.go](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/v4/e2e_suite_test.go), which imports the necessary testing framework. 89 3. Create `generate_test.go` ([ref](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/v4/generate_test.go)). That should: 90 - Introduce/Receive a `TextContext` instance 91 - Trigger the plugin's bound subcommands. See [Init](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/utils/test_context.go#L213), [CreateAPI](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.6.0/test/e2e/utils/test_context.go#L222) 92 - Use [PluginUtil](https://pkg.go.dev/sigs.k8s.io/kubebuilder/v3/pkg/plugin/util) to verify the scaffolded outputs. See [InsertCode](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/pkg/plugin/util/util.go#L67), [ReplaceInFile](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.6.0/pkg/plugin/util/util.go#L196), [UncommendCode](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.6.0/pkg/plugin/util/util.go#L86) 93 4. Create `plugin_cluster_test.go` ([ref](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/v4/plugin_cluster_test.go)). That should: 94 95 - 4.1. Setup testing environment, e.g: 96 97 - Cleanup environment, create temp dir. See [Prepare](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/utils/test_context.go#L97) 98 - If your test will cover the provided features then, ensure that you install prerequisites CRDs: See [InstallCertManager](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/utils/test_context.go#L138), [InstallPrometheusManager](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.6.0/test/e2e/utils/test_context.go#L171) 99 100 - 4.2. Run the function from `generate_test.go`. 101 102 - 4.3. Further make sure the scaffolded output works, e.g: 103 104 - Execute commands in your `Makefile`. See [Make](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/utils/test_context.go#L240) 105 - Temporary load image of the testing controller. See [LoadImageToKindCluster](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/utils/test_context.go#L283) 106 - Call Kubectl to validate running resources. See [utils.Kubectl](https://pkg.go.dev/sigs.k8s.io/kubebuilder/v3/test/e2e/utils#Kubectl) 107 108 - 4.4. Delete temporary resources after testing exited, e.g: 109 - Uninstall prerequisites CRDs: See [UninstallPrometheusOperManager](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/utils/test_context.go#L183) 110 - Delete temp dir. See [Destroy](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/utils/test_context.go#L255) 111 112 5. Add the command in [test/e2e/plugin](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/e2e/setup.sh#L65) to run your testing code: 113 114 ```shell 115 go test $(dirname "$0")/<your-plugin-test-folder> $flags -timeout 30m 116 ``` 117 118 #### 2. Sample Projects from the Plugin 119 120 It is also necessary to test consistency of the proposed plugin across different env and the integration with other plugins. 121 122 This is performed by generating sample projects based on the plugins. The CI workflow defined in Github Action would validate the availability and the consistency. 123 124 See: 125 126 - [test/testdata/generated.sh](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/test/testdata/generate.sh#L144) 127 - [make generate](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/Makefile#L70) 128 129 ## PR Process 130 131 See [VERSIONING.md](VERSIONING.md) for a full description. TL;DR: 132 133 Every PR should be annotated with an icon indicating whether it's 134 a: 135 136 - Breaking change: :warning: (`:warning:`) 137 - Non-breaking feature: :sparkles: (`:sparkles:`) 138 - Patch fix: :bug: (`:bug:`) 139 - Docs: :book: (`:book:`) 140 - Infra/Tests/Other: :seedling: (`:seedling:`) 141 - No release note: :ghost: (`:ghost:`) 142 143 Use :ghost: (no release note) only for the PRs that change or revert unreleased 144 changes, which don't deserve a release note. Please don't abuse it. 145 146 You can also use the equivalent emoji directly, since GitHub doesn't 147 render the `:xyz:` aliases in PR titles. 148 149 If the PR is "plugin" scoped, you may also append the responding plugin names in the prefix. 150 [For instance](https://github.com/kubernetes-sigs/kubebuilder/commit/0b36d0c4021bbf52f29d5a990157466761ec180c): 151 152 ``` 153 🐛 (kustomize/v2-alpha): Fix typo issue in the labels added to the manifests 154 ``` 155 156 Individual commits should not be tagged separately, but will generally be 157 assumed to match the PR. For instance, if you have a bugfix in with 158 a breaking change, it's generally encouraged to submit the bugfix 159 separately, but if you must put them in one PR, mark the commit 160 separately. 161 162 ## Where the CI Tests are configured 163 164 1. See the [action files](.github/workflows) to check its tests, and the scripts used on it. 165 2. Note that the prow tests used in the CI are configured in [kubernetes-sigs/kubebuilder/kubebuilder-presubmits.yaml](https://github.com/kubernetes/test-infra/blob/master/config/jobs/kubernetes-sigs/kubebuilder/kubebuilder-presubmits.yaml). 166 3. Check that all scripts used by the CI are defined in the project. 167 4. Notice that our policy to test the project is to run against k8s version N-2. So that the old version should be removed when there is a new k8s version available. 168 169 ## How to contribute to docs 170 171 The docs are published off of three branches: 172 173 - `book-v3`: [book.kubebuilder.io](https://book.kubebuilder.io) -- current docs 174 - `book-v2`: [book-v2.book.kubebuilder.io](https://book-v2.book.kubebuilder.io) -- legacy docs 175 - `book-v1`: [book-v1.book.kubebuilder.io](https://book-v1.book.kubebuilder.io) -- legacy docs 176 - `master`: [master.book.kubebuilder.io](https://master.book.kubebuilder.io) -- "nightly" docs 177 178 See [VERSIONING.md](VERSIONING.md#book-releases) for more information. 179 180 There are certain writing style guidelines for Kubernetes documentation, checkout [style guide](https://kubernetes.io/docs/contribute/style/style-guide/) for more information. 181 182 ### How to preview the changes performed in the docs 183 184 Check the CI job after to do the Pull Request and then, click on in the `Details` of `netlify/kubebuilder/deploy-preview` 185 186 ## Community, discussion and support 187 188 Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/). 189 190 You can reach the maintainers of this project at: 191 192 - [Slack](http://slack.k8s.io/) 193 - [Mailing List](https://groups.google.com/forum/#!forum/kubebuilder) 194 195 ## Becoming a reviewer or approver 196 197 Contributors may eventually become official reviewers or approvers in 198 Kubebuilder and the related repositories. See 199 [CONTRIBUTING-ROLES.md](docs/CONTRIBUTING-ROLES.md) for more information. 200 201 ## Code of conduct 202 203 Participation in the Kubernetes community is governed by the [Kubernetes Code of Conduct](code-of-conduct.md). 204 205 [golangci]: https://github.com/golangci/golangci-lint 206 [kind]: https://kind.sigs.k8s.io/#installation-and-usage 207 [setup-envtest]: https://book.kubebuilder.io/reference/envtest 208 [k8s-contrubutiong-guide]: https://www.kubernetes.dev/docs/guide/contributing/