How to build an old version of NGINX Ingress Controller and patch it

In this HOWTO, we will fix a bug in the ancient version of nginx ingress controller v0.20.0 and learn how to work with Go dependencies of older versions through dep + vendor.


The original article was taken with the consent of the author from the site


ingress-nginx version v0.20.0 adds extra slashes when rewrite. This prevents seamless migration to the latest version (v0.32.0), so developers in some cases had to do this design:

path: /service/api/v1/tokens
rewrite-target: /api/v1/tokens

If add / to the end a YAML object of type Ingressthen ingress-nginx 0.20.0 starts doing rewrite in / api / v1 / tokens //. It is impossible to refuse such a construction, because someone accesses the service with a slash at the end, and someone without.

We decided to patch the old NGINX Ingress to get rid of the annoying bug. And then move according to plan:

  • Change the paths and rewrites in ingresses to human ones first (with a slash at the end).
  • Migrate to a new Ingress Controller running on a different port.

But first, you need to fix the problem in the source code of the controller of the old version.


AT these lines variable location.Rewrite.Target change to strings.TrimSuffix (location.Rewrite.Target, “/”).

Download source:

go get
cd ~/go/src/

Switch to the branch you want to fix:

git checkout v0.20.0

We rule architecture in Makefile. so as not to collect an extra 40 minutes:

vim Makefile

(or sed -i -e 's/^ALL_ARCH.*/ALL_ARCH = amd64/g')

We introduce their edits:

vim internal/ingress/controller/template/template.go +539

(here we change the variable – see “Purpose”)

Fixim Docker image to build Go:

vim build/


  • change E2E_IMAGE on the;
  • delete in the same file –entrypoint $ {FLAGS}.

Save edits:

git add -A
git commit -m "Fix trailing slash bug"

Install the dependencies for the assembly:

dep ensure =v  # ключевой момент, без этого будет ругаться на internal инклуды

We start the assembly and wait (5 minutes):



We hang tag and push:

docker tag

docker push


By the way, we are looking for a cool Kubernetes admin.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *