2025-01-29 23:44:09 +02:00
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
2026-05-04 14:44:10 +02:00
ifeq (, $( shell go env GOBIN ) )
GOBIN = $( shell go env GOPATH) /bin
else
GOBIN = $( shell go env GOBIN)
endif
2025-01-29 23:44:09 +02:00
2026-05-06 12:26:32 +02:00
IMG_REGISTRY ?= ghcr.io
IMG_REPOSITORY ?= netbirdio/netbird-operator
2026-05-04 14:44:10 +02:00
IMG_TAG ?= dev
2026-05-05 12:31:30 +02:00
IMG_REF := $( IMG_REGISTRY) /$( IMG_REPOSITORY) :$( IMG_TAG)
2025-01-29 23:44:09 +02:00
.PHONY : generate
2026-05-13 12:48:38 +02:00
generate : api /v 1/zz_generated .deepcopy .go api /v 1alpha 1/zz_generated .deepcopy .go pkg /applyconfigurations config /crd /bases charts /netbird -operator /crds docs /api -reference .md
2026-05-04 14:44:10 +02:00
api/v1/zz_generated.deepcopy.go api/v1alpha1/zz_generated.deepcopy.go : $( shell find api -not -name 'zz_generated *') hack /boilerplate .go .txt
@go tool controller-gen object:headerFile= "hack/boilerplate.go.txt" paths = "./..."
pkg/applyconfigurations : $( shell find api -not -name 'zz_generated *') hack /boilerplate .go .txt
@go tool controller-gen applyconfiguration:headerFile= "hack/boilerplate.go.txt" object:headerFile= "hack/boilerplate.go.txt" paths = "./..."
@touch pkg/applyconfigurations
2026-05-13 12:48:38 +02:00
config/crd/bases : $( shell find api )
@go tool controller-gen crd paths = "./..." output:crd:artifacts:config= config/crd/bases
@touch config/crd/bases
charts/netbird-operator/crds : $( GENERATED_CRDS )
@rm -rf $@
@mkdir -p $@
@cp config/crd/bases/* $@
2026-05-04 14:44:10 +02:00
docs/api-reference.md : $( shell find api ) docs /.crd -ref -docs .yaml
@go tool crd-ref-docs --log-level error --output-path docs/api-reference.md --renderer markdown --source-path api/v1alpha1 --config docs/.crd-ref-docs.yaml
.PHONY : lint
lint :
@golangci-lint run ./...
2025-01-29 23:44:09 +02:00
.PHONY : test
2026-05-04 14:44:10 +02:00
test : setup -envtest
2025-01-29 23:44:09 +02:00
KUBEBUILDER_ASSETS = " $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test -v $$ ( go list ./... | grep -v /e2e) -coverprofile cover.out
2026-05-05 12:31:30 +02:00
test-e2e : build -image
cd ./test/e2e && IMG_REF = ${ IMG_REF } go test ./... -v -count 1
2025-01-29 23:44:09 +02:00
.PHONY : build
2026-05-13 14:02:51 +02:00
build : generate bin /linux -$( shell go env GOARCH ) /netbird -operator
2025-01-29 23:44:09 +02:00
2026-05-04 14:44:10 +02:00
bin/linux-%/netbird-operator : $( shell find api cmd internal pkg ) go .mod go .sum
2026-05-13 14:02:51 +02:00
@CGO_ENABLED= 0 GOOS = linux GOARCH = $* go build -ldflags= "-w -s" -trimpath -o $@ cmd/main.go
2025-01-29 23:44:09 +02:00
2026-05-04 14:44:10 +02:00
.PHONY : build -image
build-image : build
2026-05-06 12:26:32 +02:00
@DOCKER_BUILDKIT= 1 docker build -t ${ IMG_REF } .
2026-05-05 12:31:30 +02:00
@echo ${ IMG_REF }
2026-05-04 14:44:10 +02:00
.PHONY : build -image -multiarch
build-image-multiarch : generate bin /linux -amd 64/netbird -operator bin /linux -arm 64/netbird -operator
2026-05-06 12:26:32 +02:00
@DOCKER_BUILDKIT= 1 docker build --platform linux/amd64,linux/arm64 -t ${ IMG_REF } .
2026-05-05 12:31:30 +02:00
@echo ${ IMG_REF }
2025-01-29 23:44:09 +02:00
.PHONY : install
2026-05-04 14:44:10 +02:00
install : generate
2026-05-13 12:48:38 +02:00
kustomize build config/crd | kubectl apply -f -
2025-01-29 23:44:09 +02:00
.PHONY : uninstall
2026-05-05 11:12:50 +02:00
uninstall :
2026-05-13 12:48:38 +02:00
kustomize build config/crd | kubectl delete -f -
2025-01-29 23:44:09 +02:00
2026-05-13 12:48:38 +02:00
.PHONY : run
2026-05-05 11:12:50 +02:00
run : install
kubectl create namespace netbird --dry-run= client -o yaml | kubectl apply -f -
go run cmd/main.go --enable-webhooks= false --netbird-api-key= $$ { NB_API_KEY} --runtime-namespace netbird
2025-01-29 23:44:09 +02:00
##@ Dependencies
## Location to install dependencies to
LOCALBIN ?= $( shell pwd ) /bin
$(LOCALBIN) :
mkdir -p $( LOCALBIN)
## Tool Binaries
ENVTEST ?= $( LOCALBIN) /setup-envtest
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
ENVTEST_VERSION ?= $( shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}' )
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
ENVTEST_K8S_VERSION ?= $( shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}' )
.PHONY : setup -envtest
setup-envtest : envtest ## Download the binaries required for ENVTEST in the local bin directory.
@echo "Setting up envtest binaries for Kubernetes version $( ENVTEST_K8S_VERSION) ..."
@$( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path || { \
echo "Error: Failed to set up envtest binaries for version $( ENVTEST_K8S_VERSION) ." ; \
exit 1; \
}
.PHONY : envtest
2026-04-30 10:24:16 +02:00
2025-01-29 23:44:09 +02:00
envtest : $( ENVTEST ) ## Download setup-envtest locally if necessary.
$(ENVTEST) : $( LOCALBIN )
$( call go-install-tool,$( ENVTEST) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,$( ENVTEST_VERSION))
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package = $( 2) @$( 3) ; \
echo "Downloading $$ {package}" ; \
rm -f $( 1) || true ; \
GOBIN = $( LOCALBIN) go install $$ { package} ; \
mv $( 1) $( 1) -$( 3) ; \
} ; \
ln -sf $( 1) - $( 3) $( 1)
endef