Skip to content

Commit

Permalink
improvements for contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Mar 18, 2020
1 parent c749b4c commit b70e9ca
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ bin/*
# skip testdata go.mod, since it may have
# different result depending on go version
/testdata/project-v2/go.sum
/testdata/project-v2-addon/go.sum
/testdata/project-v2-multigroup/go.sum
19 changes: 12 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ jobs:
include:
- stage: linting
before_script: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.3
script: ./scripts/verify.sh
script: make lint
after_success: echo "Linting check succeeded"
after_failure: echo "Linting check failed. Run make lint to check it locally"

- stage: golden
# The golden_test.sh check if the the testdata is updated according to the current changes
# To update the testdata use the Makefile targets `make generate-setup` then `make generate-testdata`
script: ./golden_test.sh
- stage: testdata
# Check if the the testdata is updated according to the current changes
# To update the testdata use the Makefile target `make generate`
script: make check-testdata
after_success: echo "Generate check succeeded."
after_failure: echo "Generate check failed. Run make test-gen to check it locally and use make generate to fix it"

- stage: coverage
# The following module is used to integrate the project with coveralls.io. It allow us to easily sent the data.
Expand All @@ -44,10 +48,11 @@ jobs:
script:
- make test-coverage
- $GOPATH/bin/goveralls -service=travis-ci -coverprofile=coverage-all.out -repotoken=$COVERALLS_TOKEN

after_success: echo "Coverage check succeeded. See in goveralls if the % of code covered with tests decreased."
after_failure: echo "Coverage step failed. Run make test-coverage to check it locally"
stages:
- linting
- golden
- testdata
- test
- coverage

Expand Down
34 changes: 25 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Contributing guidelines

This document describes how to contribute to the project.

## Sign the CLA

Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests.

Please see https://git.k8s.io/community/CLA.md for more info.

## Prerequisites

- [go](https://golang.org/dl/) version v1.13+.
- [dep](https://github.com/golang/dep) dep v0.5+
- [docker](https://docs.docker.com/install/) version 17.03+.
Expand All @@ -15,6 +18,7 @@ Please see https://git.k8s.io/community/CLA.md for more info.
- Access to a Kubernetes v1.11.3+ cluster.

## Contributing steps

1. Submit an issue describing your proposed change to the repo in question.
1. The [repo owners](OWNERS) will respond to your issue promptly.
1. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above).
Expand All @@ -23,26 +27,38 @@ Please see https://git.k8s.io/community/CLA.md for more info.

## How to build kubebuilder locally

Note that, by building the kubebuilder from the source code we are allowed to test the changes made locally.

1. Run the following command to clone your fork of the project locally in the dir /src/sigs.k8s.io/kubebuilder

```
$ git clone [email protected]:<user>/kubebuilder.git $GOPATH/src/sigs.k8s.io/kubebuilder
```

1. Ensure you activate module support before continue (`$ export GO111MODULE=on`)
1. Build the project by using the command `make build`
1. Run the command `make install` to create a bin with the source code

## How to test kubebuilder locally
**NOTE** In order to check the local environment run `make go-test`.

## What to do before submitting a pull request

1. Run the tests by using the command `make test`. It will execute unit tests.
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/`
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/`

**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.

**NOTE** To run `make lint` is required to install `golangci-lint` locally it. More info: https://github.com/golangci/golangci-lint#install

## Where the CI Tests are configured?
Following the targets that can be used to test your changes locally.

| Command | Description | Is called in the CI? |
|--- |--- |--- |
| make go-test | Runs go tests | no |
| make test| Runs tests in shell (`./test.sh`) | yes |
| make lint | Check the code implementation | yes |
| make test-coverage | Run coveralls to check the % of code covered by tests | yes |
| make check-testdata | Checks if the testdata dir is updated with the latest changes | yes |

**NOTE** To use the `make lint` is required to install `golangci-lint` locally. More info: https://github.com/golangci/golangci-lint#install

## Where the CI Tests are configured

1. See the [Travis](.travis.yml) file to check its tests and the scripts used on it.
1. 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).
Expand All @@ -62,7 +78,7 @@ If adding doc for an unreleased feature, the PR should target `master` branch.
If updating existing docs, the PR should target `master` branch and then
cherry-picked into `book-v2` branch.

### How to preview the changes performed in the docs?
### How to preview the changes performed in the docs

Check the CI job after to do the Pull Request and then, click on in the `Details` of `netlify/kubebuilder/deploy-preview`

Expand All @@ -71,7 +87,6 @@ Check the CI job after to do the Pull Request and then, click on in the `Details
Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).

You can reach the maintainers of this project at:

- [Slack](http://slack.k8s.io/)
- [Mailing List](https://groups.google.com/forum/#!forum/kubebuilder)

Expand All @@ -84,3 +99,4 @@ KubeBuilder and the related repositories. See
## Code of conduct

Participation in the Kubernetes community is governed by the [Kubernetes Code of Conduct](code-of-conduct.md).

19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ generate: ## Update/generate all mock data. You should run this commands to upda

.PHONY: generate-testdata
generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/kubebuilder
GO111MODULE=on ./generate_golden.sh
GO111MODULE=on ./generate_testdata.sh

.PHONY: generate-vendor
generate-vendor: ## (Deprecated) Update/generate the vendor by using the path $GOPATH/src/sigs.k8s.io/kubebuilder-test
Expand All @@ -68,22 +68,21 @@ lint: ## Run code lint checks

##@ Tests

.PHONY: test
test: ## Run the go tests ($ go test -v ./cmd/... ./pkg/...)
.PHONY: go-test
go-test: ## Run the go tests ($ go test -v ./cmd/... ./pkg/...)
go test -v ./cmd/... ./pkg/...

.PHONY: test-ci
test-ci: ## Run the unit tests (used in the CI)
./setup.sh
.PHONY: test
test: ## Run the unit tests (used in the CI)
./test.sh

.PHONY: test-e2e
test-e2e: ## Run the integration tests (used in the CI)
./test_e2e.sh

.PHONY: test-coverage
test-coverage: ## Run coveralls
# remove all coverage files if exists
- rm -rf *.out
# run the go tests and gen the file coverage-all used to do the integration with coverrals.io
go test -failfast -tags=integration -coverprofile=coverage-all.out -covermode=count ./pkg/... ./cmd/...

.PHONY: check-testdata
check-testdata: ## Run the script to ensure that the testdata is updated
./check_testdata.sh
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ Before you file an issue, please search existing issues to see if your issue is
For realtime discussion, you can join the [#kubebuilder](https://slack.k8s.io/#kubebuilder) slack channel. Slack requires registration, but the Kubernetes team is open invitation to anyone to register here. Feel free to come and ask any questions.

## Contributing

Contributions are greatly appreciated. The maintainers actively manage the issues list, and try to highlight issues suitable for newcomers.
The project follows the typical GitHub pull request model. See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
Before starting any work, please either comment on an existing issue, or file a new one.

## Supportability

Currently, Kubebuilder officially supports OSX and Linux platforms. So, if you are using a Windows OS you may find issues. Contributions towards supporting Windows are welcome.
12 changes: 6 additions & 6 deletions golden_test.sh → check_testdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ check_directory=testdata

# Check testdata directory first. If there are any uncommitted change, fail the test.
if [[ `git status ${check_directory} --porcelain` ]]; then
header_text "Golden test precondition failed!"
header_text "Please commit the change under testdata directory before running the golden test"
header_text "Generate Testdata test precondition failed!"
header_text "Please commit the change under testdata directory before running the Generate Testdata test"
exit 1
fi

./generate_golden.sh
./generate_testdata.sh

# Check if there are any changes to files under testdata directory.
if [[ `git status ${check_directory} --porcelain` ]]; then
header_text "git status ${check_directory} --porcelain"
git status ${check_directory} --porcelain
header_text "git diff ${check_directory}"
git diff ${check_directory}
header_text "Golden test failed!"
header_text "Please make sure you have run ./generate_golden.sh if you have changed the scaffolding"
header_text "Generate Testdata failed!"
header_text "Please, if you have changed the scaffolding make sure you have run: make generate"
exit 1
else
header_text "Golden test passed!"
header_text "Generate Testdata passed!"
fi
File renamed without changes.
2 changes: 1 addition & 1 deletion testdata/project-v2-addon/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ require (
k8s.io/apimachinery v0.17.2
k8s.io/client-go v0.17.2
sigs.k8s.io/controller-runtime v0.5.0
sigs.k8s.io/kubebuilder-declarative-pattern v0.0.0-20200226054827-748a6481b2a4
sigs.k8s.io/kubebuilder-declarative-pattern v0.0.0-20200317144824-bbf1fb2a4a9a
)

0 comments on commit b70e9ca

Please sign in to comment.