1- # Image URL to use all building/pushing image targets
2- IMG ?= controller:latest
1+ # address-controller — core controllers for IP addresses as a first-class
2+ # resource (IPAddressClass / IPAddress / IPAddressClaim).
3+
4+ # Image coordinates. TAG defaults to something unique per commit; override for
5+ # releases (e.g. make docker-push TAG=v0.1.0) or floating tags (TAG=main).
6+ IMG_REPO ?= ghcr.io/lllamnyp/address-controller
7+ TAG ?= $(shell git describe --tags --always --dirty)
8+ IMG ?= $(IMG_REPO ) :$(TAG )
9+ PLATFORMS ?= linux/amd64,linux/arm64
10+
11+ CHART := chart/address-controller
12+ # Chart.yaml carries a 0.0.0 placeholder; the real version is stamped here.
13+ CHART_VERSION ?= 0.1.0
314
415# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
516ifeq (,$(shell go env GOBIN) )
@@ -9,9 +20,6 @@ GOBIN=$(shell go env GOBIN)
920endif
1021
1122# CONTAINER_TOOL defines the container tool to be used for building images.
12- # Be aware that the target commands are only tested with Docker which is
13- # scaffolded by default. However, you might want to replace it to use other
14- # tools. (i.e. podman)
1523CONTAINER_TOOL ?= docker
1624
1725# Setting SHELL to bash allows bash commands to be executed by recipes.
@@ -24,26 +32,17 @@ all: build
2432
2533# #@ General
2634
27- # The help target prints out all targets with their descriptions organized
28- # beneath their categories. The categories are represented by '##@' and the
29- # target descriptions by '##'. The awk command is responsible for reading the
30- # entire set of makefiles included in this invocation, looking for lines of the
31- # file as xyz: ## something, and then pretty-format the target and help. Then,
32- # if there's a line with ##@ something, that gets pretty-printed as a category.
33- # More info on the usage of ANSI control characters for terminal formatting:
34- # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
35- # More info on the awk command:
36- # http://linuxcommand.org/lc3_adv_awk.php
37-
3835.PHONY : help
3936help : # # Display this help.
4037 @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
4138
4239# #@ Development
4340
4441.PHONY : manifests
45- manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
46- $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
42+ manifests : controller-gen # # Generate the CRDs and the ClusterRole straight into the Helm chart.
43+ $(CONTROLLER_GEN ) rbac:roleName=address-controller crd paths=" ./..." \
44+ output:crd:artifacts:config=$(CHART ) /crds \
45+ output:rbac:artifacts:config=$(CHART ) /templates
4746
4847.PHONY : generate
4948generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -61,23 +60,6 @@ vet: ## Run go vet against code.
6160test : manifests generate fmt vet setup-envtest # # Run tests.
6261 KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
6362
64- # TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
65- # The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
66- # Prometheus and CertManager are installed by default; skip with:
67- # - PROMETHEUS_INSTALL_SKIP=true
68- # - CERT_MANAGER_INSTALL_SKIP=true
69- .PHONY : test-e2e
70- test-e2e : manifests generate fmt vet # # Run the e2e tests. Expected an isolated environment using Kind.
71- @command -v kind > /dev/null 2>&1 || { \
72- echo " Kind is not installed. Please install Kind manually." ; \
73- exit 1; \
74- }
75- @kind get clusters | grep -q ' kind' || { \
76- echo " No Kind cluster is running. Please start a Kind cluster before running the e2e tests." ; \
77- exit 1; \
78- }
79- go test ./test/e2e/ -v -ginkgo.v
80-
8163.PHONY : lint
8264lint : golangci-lint # # Run golangci-lint linter
8365 $(GOLANGCI_LINT ) run
@@ -86,10 +68,6 @@ lint: golangci-lint ## Run golangci-lint linter
8668lint-fix : golangci-lint # # Run golangci-lint linter and perform fixes
8769 $(GOLANGCI_LINT ) run --fix
8870
89- .PHONY : lint-config
90- lint-config : golangci-lint # # Verify golangci-lint linter configuration
91- $(GOLANGCI_LINT ) config verify
92-
9371# #@ Build
9472
9573.PHONY : build
@@ -100,62 +78,40 @@ build: manifests generate fmt vet ## Build manager binary.
10078run : manifests generate fmt vet # # Run a controller from your host.
10179 go run ./cmd/main.go
10280
103- # If you wish to build the manager image targeting other platforms you can use the --platform flag.
104- # (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
105- # More info: https://docs.docker.com/develop/develop-images/build_enhancements/
10681.PHONY : docker-build
107- docker-build : # # Build docker image with the manager .
108- $(CONTAINER_TOOL ) build -t ${ IMG} .
82+ docker-build : # # Build the controller image for the host platform .
83+ $(CONTAINER_TOOL ) build -t $( IMG ) .
10984
11085.PHONY : docker-push
111- docker-push : # # Push docker image with the manager.
112- $(CONTAINER_TOOL ) push ${IMG}
113-
114- # PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
115- # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
116- # - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
117- # - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
118- # - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
119- # To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
120- PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
86+ docker-push : # # Push the controller image.
87+ $(CONTAINER_TOOL ) push $(IMG )
88+
12189.PHONY : docker-buildx
122- docker-buildx : # # Build and push docker image for the manager for cross-platform support
123- # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
124- sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
125- - $(CONTAINER_TOOL ) buildx create --name address-controller-builder
126- $(CONTAINER_TOOL ) buildx use address-controller-builder
127- - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
128- - $(CONTAINER_TOOL ) buildx rm address-controller-builder
129- rm Dockerfile.cross
130-
131- .PHONY : build-installer
132- build-installer : manifests generate kustomize # # Generate a consolidated YAML with CRDs and deployment.
133- mkdir -p dist
134- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
135- $(KUSTOMIZE ) build config/default > dist/install.yaml
90+ docker-buildx : # # Build and push a multi-platform controller image (requires buildx).
91+ $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) -t $(IMG ) .
13692
137- # #@ Deployment
93+ # #@ Helm
13894
139- ifndef ignore-not-found
140- ignore-not-found = false
141- endif
95+ .PHONY : helm-lint
96+ helm-lint : # # Lint the chart.
97+ helm lint $( CHART )
14298
143- .PHONY : install
144- install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
145- $(KUSTOMIZE ) build config/crd | $(KUBECTL ) apply -f -
99+ .PHONY : helm-package
100+ helm-package : manifests helm-lint # # Package the chart into dist/ with the version stamped.
101+ mkdir -p dist
102+ helm package $(CHART ) --version $(CHART_VERSION ) --app-version $(TAG ) -d dist
146103
147- .PHONY : uninstall
148- uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion .
149- $( KUSTOMIZE ) build config/crd | $( KUBECTL ) delete --ignore-not-found= $( ignore-not-found ) -f -
104+ .PHONY : install-crds
105+ install-crds : manifests # # Apply the CRDs to the cluster in ~/.kube/config (Helm only installs, never upgrades, crds/) .
106+ kubectl apply -f $( CHART ) /crds
150107
151108.PHONY : deploy
152- deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
153- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
154- $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
109+ deploy : manifests # # Install/upgrade the chart into the cluster in ~/.kube/config.
110+ helm upgrade --install address-controller $(CHART ) --namespace address-controller-system --create-namespace
155111
156112.PHONY : undeploy
157- undeploy : kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion .
158- $( KUSTOMIZE ) build config/default | $( KUBECTL ) delete --ignore-not-found= $( ignore-not-found ) -f -
113+ undeploy : # # Uninstall the chart (CRDs and their objects are left behind by design) .
114+ helm uninstall address-controller --namespace address-controller-system
159115
160116# #@ Dependencies
161117
@@ -165,26 +121,18 @@ $(LOCALBIN):
165121 mkdir -p $(LOCALBIN )
166122
167123# # Tool Binaries
168- KUBECTL ?= kubectl
169- KUSTOMIZE ?= $(LOCALBIN ) /kustomize
170124CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
171125ENVTEST ?= $(LOCALBIN ) /setup-envtest
172126GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
173127
174128# # Tool Versions
175- KUSTOMIZE_VERSION ?= v5.5.0
176129CONTROLLER_TOOLS_VERSION ?= v0.17.1
177130# ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
178131ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-% d.% d", $$2, $$3}')
179132# ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
180133ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.% d", $$3}')
181134GOLANGCI_LINT_VERSION ?= v1.63.4
182135
183- .PHONY : kustomize
184- kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
185- $(KUSTOMIZE ) : $(LOCALBIN )
186- $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION ) )
187-
188136.PHONY : controller-gen
189137controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
190138$(CONTROLLER_GEN ) : $(LOCALBIN )
0 commit comments