Skip to content

Commit bfbf331

Browse files
authored
Updating Contribution Guide (#2397)
1 parent ddfbfb4 commit bfbf331

File tree

1 file changed

+94
-43
lines changed

1 file changed

+94
-43
lines changed

_about/CONTRIBUTING.md

Lines changed: 94 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,122 @@
1-
## Developing the provider
1+
# Contributor Guide
22

3-
Thank you for your interest in contributing to the Kubernetes provider. We welcome your contributions. Here you'll find information to help you get started with provider development.
3+
Thank you for your interest in contributing to the Kubernetes provider. We welcome your contributions. Here, you'll find information to help you get started with provider development.
44

5-
## Documentation
5+
If you want to learn more about developing a Terraform provider, please refer to the [Plugin Development documentation](https://developer.hashicorp.com/terraform/plugin).
66

7-
Our [provider development documentation](https://www.terraform.io/docs/extend/) provides a good start into developing an understanding of provider development. It's the best entry point if you are new to contributing to this provider.
7+
## Configuring Environment
88

9-
To learn more about how to create issues and pull requests in this repository, and what happens after they are created, you may refer to the resources below:
10-
- [Issue creation and lifecycle](ISSUES.md)
11-
- [Pull Request creation and lifecycle](PULL_REQUESTS.md)
9+
1. Install Golang
1210

11+
[Install](https://go.dev/doc/install) the version of Golang as indicated in the [go.mod](../go.mod) file.
1312

14-
## Building the provider
13+
1. Fork this repo
1514

16-
Clone repository to: `$GOPATH/src/github.com/hashicorp/terraform-provider-kubernetes`
15+
[Fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) the provider repository and clone it on your computer.
1716

18-
```sh
19-
$ mkdir -p $GOPATH/src/github.com/hashicorp; cd $GOPATH/src/github.com/hashicorp
20-
$ git clone [email protected]:hashicorp/terraform-provider-kubernetes
21-
```
17+
Here is an example of how to clone this repository and switch to the directory:
2218

23-
Enter the provider directory and build the provider
19+
```console
20+
$ git clone https://github.com/<YOUR-USERNAME>/terraform-provider-kubernetes.git
21+
$ cd terraform-provider-kubernetes
22+
```
2423

25-
```sh
26-
$ cd $GOPATH/src/github.com/hashicorp/terraform-provider-kubernetes
27-
$ make build
28-
```
24+
From now on, we are going to assume that you have a copy of the repository on your computer and work within the `terraform-provider-kubernetes` directory.
2925

30-
Statically linking binaries can be required for testing development builds in containers not providing all dependencies, e.g.:
26+
1. Prepare a Kubernetes Cluster
3127

32-
```
33-
# CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"'
34-
```
28+
While our preference is to use [KinD](https://kind.sigs.k8s.io/) for setting up a Kubernetes cluster for development and test purposes, feel free to opt for the solution that best suits your preferences. Please bear in mind that some acceptance tests might require specific cluster settings, which we maintain in the KinD [configuration file](../.github/config/acceptance_tests_kind_config.yaml).
29+
30+
Here is an example of how to provision a Kubernetes cluster using the configuration file:
31+
32+
```console
33+
$ kind create cluster --config=./.github/config/acceptance_tests_kind_config.yaml
34+
```
35+
36+
KinD comes with a default Node image version that depends on the KinD version and thus might not be always the one you want to use. The above command can be extended with the `--image` option to spin up a particular Kubernetes version:
37+
38+
```console
39+
$ kind create cluster \
40+
--config=./.github/config/acceptance_tests_kind_config.yaml \
41+
--image kindest/node:v1.28.0@sha256:b7a4cad12c197af3ba43202d3efe03246b3f0793f162afb40a33c923952d5b31
42+
```
43+
44+
Refer to the KinD [releases](https://github.com/kubernetes-sigs/kind/releases) to get the right image.
45+
46+
From now on, we are going to assume that the Kubernetes configuration is stored in the `$HOME/.kube/config` file, and the current context is set to a newly created KinD cluster.
47+
48+
Once the Kubernetes cluster is up and running, we strongly advise you to run acceptance tests before making any changes to ensure they work with your setup. Please refer to the [Testing](#testing) section for more details.
3549

36-
## Contributing to the provider
3750

38-
### Contributing Resources
51+
## Making Changes
3952

40-
In order to prevent breaking changes and migration of user-created resources, resources included in this provider will be limited to stable (aka `v1`) and beta APIs (with beta resources, readiness for inclusion will be assessed individually). You can find `v1` resources in the Kubernetes [API documentation](https://kubernetes.io/docs/reference/#api-reference) for the appropriate version of Kubernetes.
53+
### Adding a New Resource
4154

42-
### Development Environment
55+
This quick guide covers best practices for adding a new Resource.
4356

44-
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.9+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.
57+
1. Ensure all dependncies are installed.
58+
1. Add an SDK Client.
59+
1. Add Resource Schema and define attributes [see Kubernetes Documentation](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs). A best and recommended practice is reuse constants from the Kuberentes packages as a default value in an attribute or within a validation function.
60+
1. Scaffold an empty/new resource.
61+
1. Add Acceptance Tests(s) for the resource.
62+
1. Run Acceptance Tests(s) for this resource.
63+
1. Add Documentation for this resource by editing the `.md.tmpl` file to include the appropriate [Data Fields](https://pkg.go.dev/text/template) and executing `tfplugindocs generate` command [see Terraform PluginDocs](https://github.com/hashicorp/terraform-plugin-docs#data-fields) then inspecting the corresponding `.md` file in the `/docs` to see all changes. The Data Fields that are currently apart of the templates are those for the Schema ({{ .SchemaMarkdown }}), Name ({{ .Name }}) and ({{ .Description }}).
64+
1. Execute `make docs-lint` and `make tests-lint` commands
65+
1. Create a Pull Request for your changes.
4566

46-
To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
67+
### Adding a New Data Source
4768

48-
```sh
49-
$ make build
50-
...
51-
$ $GOPATH/bin/terraform-provider-kubernetes
52-
...
69+
1. Ensure all dependncies are installed.
70+
1. Add an SDK Client.
71+
1. Add Data Source Schema and define attributes [see Kubernetes Documentation](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs).
72+
A best and recommended practice is reuse constants from the Kuberentes packages as a default value in an attribute or within a validation function.
73+
1. Scaffold an empty/new resource.
74+
1. Add Acceptance Tests(s) for the data source.
75+
1. Run Acceptance Tests(s) for this data source.
76+
1. Add Documentation for this data source by editing the `.md.tmpl` file to include the appropriate [Data Fields](https://pkg.go.dev/text/template) and executing `tfplugindocs generate` command [see Terraform PluginDocs](https://github.com/hashicorp/terraform-plugin-docs#data-fields) then inspecting the corresponding `.md` file in the `/docs` to see all changes. The Data Fields that are currently apart of the templates are those for the Schema ({{ .SchemaMarkdown }}), Name ({{ .Name }}) and ({{ .Description }}).
77+
1. Execute `make docs-lint` and `make tests-lint` commands
78+
1. Create a Pull Request for your changes.
79+
80+
### Adding/Editing Documentation
81+
All Documentation is edited in the `.md.tmpl` file. Please note that the `tfplugindocs generate` command should be executed to ensure it is updated and reflected in the `.md` files.
82+
83+
## Testing
84+
85+
The Kubernetes provider includes two types of tests: [unit](https://developer.hashicorp.com/terraform/plugin/sdkv2/testing/unit-testing) tests and [acceptance](https://developer.hashicorp.com/terraform/plugin/sdkv2/testing/acceptance-tests) tests.
86+
87+
Before running any tests, make sure that the `KUBE_CONFIG_PATH` environment variable points to the Kubernetes configuration file:
88+
89+
```console
90+
$ export KUBE_CONFIG_PATH=$HOME/.kube/config
5391
```
5492

55-
In order to test the provider, you can simply run `make test`.
93+
The following commands demonstrate how to run unit and acceptance tests respectively.
5694

57-
```sh
58-
$ make test
95+
```console
96+
$ make test # unit tests
97+
$ make testacc TESTARGS="-run ^TestAcc" # acceptance tests
5998
```
6099

61-
In order to run the full suite of Acceptance tests, run `make testacc`.
100+
1. Run existing tests
101+
1. Write/Update tests
102+
1. Run tests with new changes
62103

63-
*Note:* Acceptance tests create real resources, and often cost money to run.
104+
## Updating changelog
64105

65-
```sh
66-
$ make testacc
67-
```
106+
A PR that is merged may or may not be added to the changelog. Not every change should be in the changelog since they don't affect users directly. Some instances of PRs that could be excluded are:
107+
108+
- unit and acceptance tests fixes
109+
- minor documentation changes
110+
111+
However, PRs of the following categories should be added to the appropriate section:
112+
113+
* `FEATURES`
114+
* `ENHANCEMENTS`
115+
* `MAJOR BUG FIXES`
116+
117+
Please refer to our [ChangeLog Guide](../CHANGELOG_GUIDE.md).
118+
119+
## Creating & Submiting a PR
68120

69-
### Tests
121+
Please refer to this [guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).
70122

71-
In general, adding test coverage (unit tests and acceptance tests) to new features or bug fixes in your PRs, and sharing the logs of a successful test run on your branch will greatly speed up the acceptance of your PR. Most of our tests can be run against a `kind` cluster, so no additional infrastructure is required.

0 commit comments

Comments
 (0)