ingress-nginx-helm/docs/developer-guide/getting-started.md

91 lines
2.4 KiB
Markdown
Raw Normal View History

# Developing for NGINX Ingress Controller
2017-10-21 00:14:27 +00:00
This document explains how to get started with developing for NGINX Ingress controller.
2020-07-22 01:31:51 +00:00
## Prerequisites
2018-04-24 20:29:31 +00:00
2020-07-22 01:31:51 +00:00
Install [Go 1.14](https://golang.org/dl/) or later.
2020-07-22 01:31:51 +00:00
!!! note
The project uses [Go Modules](https://github.com/golang/go/wiki/Modules)
Install [Docker](https://docs.docker.com/engine/install/) (v19.03.0 or later with experimental feature on)
2020-07-22 01:31:51 +00:00
!!! important
The majority of make tasks run as docker containers
2018-04-24 20:29:31 +00:00
2020-07-22 01:31:51 +00:00
## Quick Start
2018-04-24 20:29:31 +00:00
2017-10-21 00:14:27 +00:00
2020-07-22 01:31:51 +00:00
1. Fork the repository
2. Clone the repository to any location in your work station
3. Add a `GO111MODULE` environment variable with `export GO111MODULE=on`
4. Run `go mod download` to install dependencies
2017-10-21 00:14:27 +00:00
2020-07-22 01:31:51 +00:00
### Local build
2017-10-21 00:14:27 +00:00
2020-07-22 01:31:51 +00:00
Start a local Kubernetes cluster using [kind](https://kind.sigs.k8s.io/), build and deploy the ingress controller
2017-10-21 00:14:27 +00:00
```console
2020-07-22 01:31:51 +00:00
make dev-env
2017-10-21 00:14:27 +00:00
```
- If you are working on the v1.x.x version of this controler, and you want to create a cluster with kubernetes version 1.22, then please visit the [documentation for kind](https://kind.sigs.k8s.io/docs/user/configuration/#a-note-on-cli-parameters-and-configuration-files), and look for how to set a custom image for the kind node (image: kindest/node...), in the kind config file.
2017-10-21 00:14:27 +00:00
2020-07-22 01:31:51 +00:00
### Testing
2017-10-21 00:14:27 +00:00
2020-07-22 01:31:51 +00:00
**Run go unit tests**
2017-10-21 00:14:27 +00:00
```console
2020-07-22 01:31:51 +00:00
make test
2017-10-21 00:14:27 +00:00
```
2020-07-22 01:31:51 +00:00
**Run unit-tests for lua code**
```console
2020-07-22 01:31:51 +00:00
make lua-test
```
2020-07-22 01:31:51 +00:00
Lua tests are located in the directory `rootfs/etc/nginx/lua/test`
2020-07-22 01:31:51 +00:00
!!! important
Test files must follow the naming convention `<mytest>_test.lua` or it will be ignored
2017-10-21 00:14:27 +00:00
2020-07-22 01:31:51 +00:00
**Run e2e test suite**
2017-10-21 00:14:27 +00:00
```console
2020-07-22 01:31:51 +00:00
make kind-e2e-test
2017-10-21 00:14:27 +00:00
```
2020-07-22 01:31:51 +00:00
To limit the scope of the tests to execute, we can use the environment variable `FOCUS`
2017-10-21 00:14:27 +00:00
```console
2020-07-22 01:31:51 +00:00
FOCUS="no-auth-locations" make kind-e2e-test
2017-10-21 00:14:27 +00:00
```
2020-07-22 01:31:51 +00:00
!!! note
The variable `FOCUS` defines Ginkgo [Focused Specs](https://onsi.github.io/ginkgo/#focused-specs)
2017-10-21 00:14:27 +00:00
Valid values are defined in the describe definition of the e2e tests like [Default Backend](https://github.com/kubernetes/ingress-nginx/blob/main/test/e2e/defaultbackend/default_backend.go#L29)
2017-10-21 00:14:27 +00:00
2020-08-14 10:38:00 +00:00
The complete list of tests can be found [here](e2e-tests.md)
2017-10-21 00:14:27 +00:00
2020-07-22 01:31:51 +00:00
### Custom docker image
2017-10-21 00:14:27 +00:00
2020-07-22 01:31:51 +00:00
In some cases, it can be useful to build a docker image and publish such an image to a private or custom registry location.
2017-10-21 00:14:27 +00:00
2020-07-22 01:31:51 +00:00
This can be done setting two environment variables, `REGISTRY` and `TAG`
2017-10-21 00:14:27 +00:00
```console
2020-07-22 01:31:51 +00:00
export TAG="dev"
export REGISTRY="$USER"
2020-07-22 01:31:51 +00:00
make build image
2017-10-21 00:14:27 +00:00
```
2020-07-22 01:31:51 +00:00
and then publish such version with
```console
2020-07-22 01:31:51 +00:00
docker push $REGISTRY/controller:$TAG
2017-10-21 00:14:27 +00:00
```