Flagger
Search…
Development Guide
This document describes how to build, test and run Flagger from source.

Setup dev environment

Flagger is written in Go and uses Go modules for dependency management.
On your dev machine install the following tools:
  • go >= 1.14
  • git >= 2.20
  • bash >= 5.0
  • make >= 3.81
  • kubectl >= 1.16
  • kustomize >= 3.5
  • helm >= 3.0
  • docker >= 19.03
You'll also need a Kubernetes cluster for testing Flagger. You can use Minikube, Kind, Docker desktop or any remote cluster (AKS/EKS/GKE/etc) Kubernetes version 1.16 or newer.
To start contributing to Flagger, fork the repository on GitHub.
Create a dir inside your GOPATH:
1
mkdir -p $GOPATH/src/github.com/fluxcd
Copied!
Clone your fork:
1
cd $GOPATH/src/github.com/fluxcd
2
git clone https://github.com/YOUR_USERNAME/flagger
3
cd flagger
Copied!
Set Flagger repository as upstream:
1
git remote add upstream https://github.com/fluxcd/flagger.git
Copied!
Sync your fork regularly to keep it up-to-date with upstream:
1
git fetch upstream
2
git checkout main
3
git merge upstream/main
Copied!

Build

Download Go modules:
1
go mod download
Copied!
Build Flagger binary:
1
make build
Copied!
Build load tester binary:
1
make loadtester-build
Copied!

Code changes

We require all commits to be signed. By signing off with your signature, you certify that you wrote the patch or otherwise have the right to contribute the material by the rules of the DCO.
If your user.name and user.email are configured in your Git config, you can sign your commit automatically with:
1
git commit -s
Copied!
Before submitting a PR, make sure your changes are covered by unit tests.
If you made changes to go.mod run:
1
go mod tidy
Copied!
If you made changes to pkg/apis regenerate Kubernetes client sets with:
1
make codegen
Copied!
Run code formatters:
1
make fmt
Copied!
Run unit tests:
1
make test
Copied!

API changes

If you made changes to pkg/apis regenerate the Kubernetes client sets with:
1
make codegen
Copied!
Update the validation spec in artifacts/flagger/crd.yaml and run:
1
make crd
Copied!
Note that any change to the CRDs must be accompanied by an update to the Open API schema.

Manual testing

Install a service mesh and/or an ingress controller on your cluster and deploy Flagger using one of the install options listed here.
If you made changes to the CRDs, apply your local copy with:
1
kubectl apply -f artifacts/flagger/crd.yaml
Copied!
Shutdown the Flagger instance installed on your cluster (replace the namespace with your mesh/ingress one):
1
kubectl -n istio-system scale deployment/flagger --replicas=0
Copied!
Port forward to your Prometheus instance:
1
kubectl -n istio-system port-forward svc/prometheus 9090:9090
Copied!
Run Flagger locally against your remote cluster by specifying a kubeconfig path:
1
go run cmd/flagger/ -kubeconfig=$HOME/.kube/config \
2
-log-level=info \
3
-mesh-provider=istio \
4
-metrics-server=http://localhost:9090
Copied!
Another option to manually test your changes is to build and push the image to your container registry:
1
make build
2
docker build -t <YOUR-DOCKERHUB-USERNAME>/flagger:<YOUR-TAG> .
3
docker push <YOUR-DOCKERHUB-USERNAME>/flagger:<YOUR-TAG>
Copied!
Deploy your image on the cluster and scale up Flagger:
1
kubectl -n istio-system set image deployment/flagger flagger=<YOUR-DOCKERHUB-USERNAME>/flagger:<YOUR-TAG>
2
kubectl -n istio-system scale deployment/flagger --replicas=1
Copied!
Now you can use one of the tutorials to manually test your changes.

Integration testing

Flagger end-to-end tests can be run locally with Kubernetes Kind.
Create a Kind cluster:
1
kind create cluster
Copied!
Build Flagger container image and load it on the cluster:
1
make build
2
docker build -t test/flagger:latest .
3
kind load docker-image test/flagger:latest
Copied!
Run the Istio e2e tests:
1
./test/istio/run.sh
Copied!
For each service mesh and ingress controller, there is a dedicated e2e test suite, choose one that matches your changes from this list.
When you open a pull request on Flagger repo, the unit and integration tests will be run in CI.
Last modified 5mo ago