2025-01-29 23:44:09 +02:00
# Image URL to use all building/pushing image targets
IMG ?= docker.io/netbirdio/kubernetes-operator:latest
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (, $( shell go env GOBIN ) )
GOBIN = $( shell go env GOPATH) /bin
else
GOBIN = $( shell go env GOBIN)
endif
# 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
.PHONY : all
all : build
##@ Development
2026-04-30 10:24:16 +02:00
## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
2025-01-29 23:44:09 +02:00
.PHONY : manifests
2026-04-30 10:24:16 +02:00
manifests :
2026-04-02 11:05:16 +02:00
go tool controller-gen crd paths = "./..." output:crd:artifacts:config= helm/kubernetes-operator/crds
2026-04-24 16:22:04 +02:00
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
2025-01-29 23:44:09 +02:00
2026-04-30 10:24:16 +02:00
## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
2025-01-29 23:44:09 +02:00
.PHONY : generate
2026-04-30 10:24:16 +02:00
generate :
2026-04-13 12:20:35 +02:00
go tool controller-gen applyconfiguration:headerFile= "hack/boilerplate.go.txt" object:headerFile= "hack/boilerplate.go.txt" paths = "./..."
2025-01-29 23:44:09 +02:00
.PHONY : test
2026-04-30 10:24:16 +02:00
test : manifests 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
.PHONY : test -e 2e
2026-04-30 10:24:16 +02:00
test-e2e : manifests
2025-01-29 23:44:09 +02:00
@command -v kind >/dev/null 2>& 1 || { \
echo "Kind is not installed. Please install Kind manually." ; \
exit 1; \
}
@kind get clusters | grep -q 'kind' || { \
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests." ; \
exit 1; \
}
go test ./test/e2e/ -v -ginkgo.v
.PHONY : lint
2026-04-30 10:24:16 +02:00
lint :
@golangci-lint run ./...
2025-01-29 23:44:09 +02:00
##@ Build
.PHONY : build
2026-04-30 10:24:16 +02:00
build : manifests
2025-01-29 23:44:09 +02:00
go build -o bin/manager cmd/main.go
.PHONY : run
2026-04-30 10:24:16 +02:00
run : manifests
2025-01-29 23:44:09 +02:00
go run ./cmd/main.go
.PHONY : docker -build
2026-04-30 10:24:16 +02:00
docker-build :
2026-04-02 11:05:16 +02:00
docker build -t ${ IMG } .
2025-01-29 23:44:09 +02:00
2026-04-30 10:24:16 +02:00
## Generate a consolidated YAML with CRDs and deployment.
2025-01-29 23:44:09 +02:00
.PHONY : build -installer
2026-04-30 10:24:16 +02:00
build-installer : manifests
2025-01-30 00:04:35 +02:00
mkdir -p manifests
2026-04-30 10:24:16 +02:00
helm template --include-crds kubernetes-operator helm/kubernetes-operator > manifests/install.yaml
2025-01-29 23:44:09 +02:00
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
2026-04-30 10:24:16 +02:00
## Install CRDs into the K8s cluster specified in ~/.kube/config.
2025-01-29 23:44:09 +02:00
.PHONY : install
2026-04-30 10:24:16 +02:00
install : manifests
kubectl apply --server-side -f helm/kubernetes-operator/crds
2025-01-29 23:44:09 +02:00
2026-04-30 10:24:16 +02:00
## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
2025-01-29 23:44:09 +02:00
.PHONY : uninstall
2026-04-30 10:24:16 +02:00
uninstall : manifests
kubectl delete -f helm/kubernetes-operator/crds
2025-01-29 23:44:09 +02:00
2026-04-30 10:24:16 +02:00
## Deploy controller to the K8s cluster specified in ~/.kube/config.
2025-01-29 23:44:09 +02:00
.PHONY : deploy
2026-04-30 10:24:16 +02:00
deploy : manifests
helm install -n netbird --create-namespace kubernetes-operator --set operator.image.tag= $( word 2,$( subst :, ,${ IMG } )) helm/kubernetes-operator
2025-01-29 23:44:09 +02:00
2026-04-30 10:24:16 +02:00
## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
2025-01-29 23:44:09 +02:00
.PHONY : undeploy
2026-04-30 10:24:16 +02:00
undeploy :
helm uninstall -n netbird kubernetes-operator
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