11
2- # Image URL to use all building/pushing image targets
3- IMG ?= controller:latest
42# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5- ENVTEST_K8S_VERSION = 1.28.0
3+ ENVTEST_K8S_VERSION = 1.28.3
64
75# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
86ifeq (,$(shell go env GOBIN) )
@@ -42,11 +40,39 @@ all: build
4240help : # # Display this help.
4341 @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 )
4442
43+ PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
44+ ARTIFACTS ?= $(PROJECT_DIR ) /bin
45+ GINKGO_VERSION ?= $(shell go list -m -f '{{.Version}}' github.com/onsi/ginkgo/v2)
46+ GO_VERSION := $(shell awk '/^go /{print $$2}' go.mod|head -n1)
47+
48+ GINKGO = $(shell pwd) /bin/ginkgo
49+ .PHONY : ginkgo
50+ ginkgo : # # Download ginkgo locally if necessary.
51+ test -s $(LOCALBIN ) /ginkgo || \
52+ GOBIN=$(LOCALBIN ) go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION )
53+
54+ INTEGRATION_TARGET ?= ./test/integration/...
55+
56+ BASE_IMAGE ?= gcr.io/distroless/static:nonroot
57+ DOCKER_BUILDX_CMD ?= docker buildx
58+ IMAGE_BUILD_CMD ?= $(DOCKER_BUILDX_CMD ) build
59+ IMAGE_BUILD_EXTRA_OPTS ?=
60+ IMAGE_REGISTRY ?= docker.io/inftyai
61+ IMAGE_NAME ?= llmaz
62+ IMAGE_REPO := $(IMAGE_REGISTRY ) /$(IMAGE_NAME )
63+ GIT_TAG ?= $(shell git describe --tags --dirty --always)
64+ IMG ?= $(IMAGE_REPO ) :$(GIT_TAG )
65+ BUILDER_IMAGE ?= golang:$(GO_VERSION )
66+
4567# #@ Development
4668
4769.PHONY : manifests
4870manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
49- $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
71+ $(CONTROLLER_GEN ) \
72+ rbac:roleName=manager-role output:rbac:artifacts:config=config/rbac \
73+ crd:generateEmbeddedObjectMeta=true output:crd:artifacts:config=config/crd/bases \
74+ webhook output:webhook:artifacts:config=config/webhook \
75+ paths=" ./..."
5076
5177.PHONY : generate
5278generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -90,34 +116,6 @@ build: manifests generate fmt vet ## Build manager binary.
90116run : manifests generate fmt vet # # Run a controller from your host.
91117 go run ./cmd/main.go
92118
93- # If you wish to build the manager image targeting other platforms you can use the --platform flag.
94- # (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
95- # More info: https://docs.docker.com/develop/develop-images/build_enhancements/
96- .PHONY : docker-build
97- docker-build : # # Build docker image with the manager.
98- $(CONTAINER_TOOL ) build -t ${IMG} .
99-
100- .PHONY : docker-push
101- docker-push : # # Push docker image with the manager.
102- $(CONTAINER_TOOL ) push ${IMG}
103-
104- # PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
105- # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
106- # - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
107- # - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
108- # - 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)
109- # To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
110- PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
111- .PHONY : docker-buildx
112- docker-buildx : # # Build and push docker image for the manager for cross-platform support
113- # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
114- sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
115- - $(CONTAINER_TOOL ) buildx create --name project-v3-builder
116- $(CONTAINER_TOOL ) buildx use project-v3-builder
117- - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile.cross .
118- - $(CONTAINER_TOOL ) buildx rm project-v3-builder
119- rm Dockerfile.cross
120-
121119# #@ Deployment
122120
123121ifndef ignore-not-found
@@ -135,7 +133,7 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
135133.PHONY : deploy
136134deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
137135 cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
138- $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
136+ $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply --server-side --force-conflicts - f -
139137
140138.PHONY : undeploy
141139undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
@@ -177,3 +175,21 @@ $(CONTROLLER_GEN): $(LOCALBIN)
177175envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
178176$(ENVTEST ) : $(LOCALBIN )
179177 test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
178+
179+ .PHONY : image-build
180+ image-build :
181+ $(IMAGE_BUILD_CMD ) -t $(IMG ) \
182+ --build-arg BASE_IMAGE=$(BASE_IMAGE ) \
183+ --build-arg BUILDER_IMAGE=$(BUILDER_IMAGE ) \
184+ --build-arg CGO_ENABLED=$(CGO_ENABLED ) \
185+ $(PUSH ) \
186+ $(IMAGE_BUILD_EXTRA_OPTS ) ./
187+
188+ .PHONY : image-push
189+ image-push : PUSH=--push
190+ image-push : image-build
191+
192+ .PHONY : test-integration
193+ test-integration : manifests fmt vet envtest ginkgo # # Run integration tests.
194+ KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " \
195+ $(GINKGO ) --junit-report=junit.xml --output-dir=$(ARTIFACTS ) -v $(INTEGRATION_TARGET )
0 commit comments