-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile.operator
More file actions
118 lines (89 loc) · 4.33 KB
/
Makefile.operator
File metadata and controls
118 lines (89 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
.PHONY: help manifests generate controller-gen install uninstall deploy undeploy build run docker-build docker-push test fmt vet kustomize
# Variables
IMG ?= mcp-runtime-operator:latest
ARCH ?= $(shell go env GOARCH)
DOCKER_PLATFORM ?= linux/$(ARCH)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
# 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.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
##@ General
help: ## Display this help message.
@echo "Usage: make -f Makefile.operator [target]"
@echo ""
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*##"; printf ""} /^[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)
##@ Development
manifests: controller-gen ## Generate ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=mcp-runtime-operator-role crd webhook paths="./api/..." output:crd:artifacts:config=config/crd/bases
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
@mkdir -p $(shell dirname $(CONTROLLER_GEN))
$(call go-get-tool,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0,$(CONTROLLER_GEN))
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,sigs.k8s.io/kustomize/kustomize/v5@latest,$(KUSTOMIZE))
##@ Deployment
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl apply -f -
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -
##@ Build
build: generate fmt vet ## Build operator binary.
@echo "Building operator..."
go build -o bin/manager cmd/operator/main.go
@echo "Operator binary built: bin/manager"
run: manifests generate fmt vet ## Run operator against the configured Kubernetes cluster in ~/.kube/config.
go run ./cmd/operator/main.go
docker-build: test ## Build Docker image with the operator.
@echo "Building Docker image: ${IMG}"
DOCKER_BUILDKIT=0 docker build --platform=${DOCKER_PLATFORM} -t ${IMG} -f Dockerfile.operator .
@echo "Docker image built: ${IMG}"
docker-build-operator-no-test: manifests generate fmt vet ## Build Docker image without running tests (used for test mode / airgapped CI).
@echo "Building Docker image (tests skipped): ${IMG}"
DOCKER_BUILDKIT=0 docker build --platform=${DOCKER_PLATFORM} -t ${IMG} -f Dockerfile.operator .
@echo "Docker image built: ${IMG}"
docker-push: ## Push Docker image to registry.
@echo "Pushing Docker image: ${IMG}"
docker push ${IMG}
@echo "Docker image pushed: ${IMG}"
docker-build-operator: docker-build ## Alias for docker-build for compatibility.
@echo "Operator Docker build completed"
##@ Testing
test: manifests generate fmt vet ## Run all tests.
go test ./... -coverprofile cover.out
coverage: test ## Generate code coverage report.
@echo "Coverage report generated: cover.out"
@go tool cover -func=cover.out | tail -1
##@ Code Quality
fmt: ## Format Go code using go fmt.
go fmt ./...
vet: ## Run go vet against code.
go vet ./...
# go-get-tool will 'go get' any package with the name $1 and install it to $2.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@mkdir -p $(shell dirname $(2))
@[ -f $(2) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(1)" ;\
CGO_ENABLED=0 GOBIN=$(PROJECT_DIR)/bin go install $(1) ;\
rm -rf $$TMP_DIR ;\
}
endef