Skip to main content
Version: v1.4.x

Development Setup

This document describes the steps to get started with development. You can either utilize Codespaces or setup a local environment.

Local Setup

Prerequisites:

Get things running

  • Get dependencies with go get

  • This project uses make. You can utilize make help to see available targets. For local deployment make targets help to build, test and deploy.

Making changes

Please refer to Development Reference for more details on the specific commands.

To test your changes on a cluster:

# generate necessary api files (optional - only needed if changes to api folder).
make generate

# build applicable images
make docker-build-manager MANAGER_IMG=eraser-manager:dev
make docker-build-remover REMOVER_IMG=remover:dev
make docker-build-collector COLLECTOR_IMG=collector:dev
make docker-build-trivy-scanner TRIVY_SCANNER_IMG=eraser-trivy-scanner:dev

# make sure updated image is present on cluster (e.g., see kind example below)
kind load docker-image \
eraser-manager:dev \
eraser-trivy-scanner:dev \
remover:dev \
collector:dev

make manifests
make deploy

# to remove the deployment
make undeploy

To test your changes to manager locally:

make run

Example Output:

you@local:~/eraser$ make run
docker build . \
-t eraser-tooling \
-f build/tooling/Dockerfile
[+] Building 7.8s (8/8) FINISHED
=> => naming to docker.io/library/eraser-tooling 0.0s
docker run -v /home/eraser/config:/config -w /config/manager \
registry.k8s.io/kustomize/kustomize:v3.8.9 edit set image controller=eraser-manager:dev
docker run -v /home/eraser:/eraser eraser-tooling controller-gen \
crd \
rbac:roleName=manager-role \
webhook \
paths="./..." \
output:crd:artifacts:config=config/crd/bases
rm -rf manifest_staging
mkdir -p manifest_staging/deploy
docker run --rm -v /home/eraser:/eraser \
registry.k8s.io/kustomize/kustomize:v3.8.9 build \
/eraser/config/default -o /eraser/manifest_staging/deploy/eraser.yaml
docker run -v /home/eraser:/eraser eraser-tooling controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go run ./main.go
{"level":"info","ts":1652985685.1663408,"logger":"controller-runtime.metrics","msg":"Metrics server is starting to listen","addr":":8080"}
...

Development Reference

Eraser is using tooling from kubebuilder. For Eraser this tooling is containerized into the eraser-tooling image. The make targets can use this tooling and build the image when necessary.

You can override the default configuration using environment variables. Below you can find a reference of targets and configuration options.

Common Configuration

Environment VariableDescription
VERSIONSpecifies the version (i.e., the image tag) of eraser to be used.
MANAGER_IMGDefines the image url for the Eraser manager. Used for tagging, pulling and pushing the image
REMOVER_IMGDefines the image url for the Eraser. Used for tagging, pulling and pushing the image
COLLECTOR_IMGDefines the image url for the Collector. Used for tagging, pulling and pushing the image

Linting

  • make lint

Lints the go code.

Environment VariableDescription
GOLANGCI_LINTSpecifies the go linting binary to be used for linting.

Development

  • make generate

Generates necessary files for the k8s api stored under api/v1alpha1/zz_generated.deepcopy.go. See the kubebuilder docs for details.

  • make manifests

Generates the eraser deployment yaml files under manifest_staging/deploy.

Configuration Options:

Environment VariableDescription
REMOVER_IMGDefines the image url for the Eraser.
MANAGER_IMGDefines the image url for the Eraser manager.
KUSTOMIZE_VERSIONDefine Kustomize version for generating manifests.
  • make test

Runs the unit tests for the eraser project.

Configuration Options:

Environment VariableDescription
ENVTESTSpecifies the envtest setup binary.
ENVTEST_K8S_VERSIONSpecifies the Kubernetes version for envtest setup command.
  • make e2e-test

Runs e2e tests on a cluster.

Configuration Options:

Environment VariableDescription
REMOVER_IMGEraser image to be used for e2e test.
MANAGER_IMGEraser manager image to be used for e2e test.
KUBERNETES_VERSIONKubernetes version for e2e test.
TEST_COUNTSets repetition for test. Please refer to go docs for details.
TIMEOUTSets timeout for test. Please refer to go docs for details.
TESTFLAGSSets additional test flags

Build

  • make build

Builds the eraser manager binaries.

  • make run

Runs the eraser manager on your local machine.

  • make docker-build-manager

Builds the docker image for the eraser manager.

Configuration Options:

Environment VariableDescription
CACHE_FROMSets the target of the buildx --cache-from flag see buildx reference.
CACHE_TOSets the target of the buildx --cache-to flag see buildx reference.
PLATFORMSets the target platform for buildx see buildx reference.
OUTPUT_TYPESets the output for buildx see buildx reference.
MANAGER_IMGSpecifies the target repository, image name and tag for building image.
  • make docker-push-manager

Builds the docker image for the eraser manager.

Configuration Options:

Environment VariableDescription
MANAGER_IMGSpecifies the target repository, image name and tag for building image.
  • make docker-build-remover

Builds the docker image for eraser remover.

Configuration Options:

Environment VariableDescription
CACHE_FROMSets the target of the buildx --cache-from flag see buildx reference.
CACHE_TOSets the target of the buildx --cache-to flag see buildx reference.
PLATFORMSets the target platform for buildx see buildx reference.
OUTPUT_TYPESets the output for buildx see buildx reference.
REMOVER_IMGSpecifies the target repository, image name and tag for building image.
  • make docker-push-remover

Builds the docker image for the eraser remover.

Configuration Options:

Environment VariableDescription
REMOVER_IMGSpecifies the target repository, image name and tag for building image.
  • make docker-build-collector

Builds the docker image for the eraser collector.

Configuration Options:

Environment VariableDescription
CACHE_FROMSets the target of the buildx --cache-from flag see buildx reference.
CACHE_TOSets the target of the buildx --cache-to flag see buildx reference.
PLATFORMSets the target platform for buildx see buildx reference.
OUTPUT_TYPESets the output for buildx see buildx reference.
COLLECTOR_IMGSpecifies the target repository, image name and tag for building image.
  • make docker-push-collector

Builds the docker image for the eraser collector.

Configuration Options:

Environment VariableDescription
COLLECTOR_IMGSpecifies the target repository, image name and tag for building image.

Deployment

  • make install

Install CRDs into the K8s cluster specified in ~/.kube/config.

Configuration Options:

Environment VariableDescription
KUSTOMIZE_VERSIONKustomize version used to generate k8s resources for deployment.
  • make uninstall

Uninstall CRDs from the K8s cluster specified in ~/.kube/config.

Configuration Options:

Environment VariableDescription
KUSTOMIZE_VERSIONKustomize version used to generate k8s resources for deployment.
  • make deploy

Deploys eraser to the cluster specified in ~/.kube/config.

Configuration Options:

Environment VariableDescription
KUSTOMIZE_VERSIONKustomize version used to generate k8s resources for deployment.
MANAGER_IMGSpecifies the eraser manager image version to be used for deployment
  • make undeploy

Undeploy controller from the K8s cluster specified in ~/.kube/config.

Configuration Options:

Environment VariableDescription
KUSTOMIZE_VERSIONKustomize version used to generate k8s resources that need to be removed.

Release

  • make release-manifest

Generates k8s manifests files for a release.

Configuration Options:

Environment VariableDescription
NEWVERSIONSets the new version in the Makefile
  • make promote-staging-manifest

Promotes the k8s deployment yaml files to release.