|
| 1 | +PROJECT_FULL_NAME := mcp-operator |
| 2 | +REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) |
| 3 | +EFFECTIVE_VERSION := $(shell $(REPO_ROOT)/hack/common/get-version.sh) |
| 4 | + |
| 5 | +COMMON_MAKEFILE ?= $(REPO_ROOT)/hack/common/Makefile |
| 6 | +ifneq (,$(wildcard $(COMMON_MAKEFILE))) |
| 7 | +include $(COMMON_MAKEFILE) |
| 8 | +endif |
| 9 | + |
| 10 | +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
| 11 | +ifeq (,$(shell go env GOBIN)) |
| 12 | +GOBIN=$(shell go env GOPATH)/bin |
| 13 | +else |
| 14 | +GOBIN=$(shell go env GOBIN) |
| 15 | +endif |
| 16 | + |
| 17 | +# CONTAINER_TOOL defines the container tool to be used for building images. |
| 18 | +# Be aware that the target commands are only tested with Docker which is |
| 19 | +# scaffolded by default. However, you might want to replace it to use other |
| 20 | +# tools. (i.e. podman) |
| 21 | +CONTAINER_TOOL ?= docker |
| 22 | + |
| 23 | +# Setting SHELL to bash allows bash commands to be executed by recipes. |
| 24 | +# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
| 25 | +SHELL = /usr/bin/env bash -o pipefail |
| 26 | +.SHELLFLAGS = -ec |
| 27 | + |
| 28 | +COMPONENTS ?= mcp-operator |
| 29 | +API_CODE_DIRS := $(REPO_ROOT)/api/constants/... $(REPO_ROOT)/api/errors/... $(REPO_ROOT)/api/install/... $(REPO_ROOT)/api/v1alpha1/... $(REPO_ROOT)/api/core/v1alpha1/... |
| 30 | +ROOT_CODE_DIRS := $(REPO_ROOT)/cmd/... $(REPO_ROOT)/internal/... $(REPO_ROOT)/test/... |
| 31 | + |
| 32 | +##@ General |
| 33 | + |
| 34 | +ifndef HELP_TARGET |
| 35 | +.PHONY: help |
| 36 | +help: ## Display this help. |
| 37 | + @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) |
| 38 | +endif |
| 39 | + |
| 40 | +##@ Development |
| 41 | + |
| 42 | +.PHONY: manifests |
| 43 | +manifests: controller-gen ## Generate CustomResourceDefinition objects. |
| 44 | + @echo "> Remove existing CRD manifests" |
| 45 | + rm -rf config/crd/bases/ |
| 46 | + rm -rf config/webhook/manifests/ |
| 47 | + rm -rf api/crds/manifests/ |
| 48 | + @echo "> Generating CRD Manifests" |
| 49 | + @$(CONTROLLER_GEN) crd paths="$(REPO_ROOT)/api/core/v1alpha1/..." output:crd:artifacts:config=config/crd/bases |
| 50 | + @$(CONTROLLER_GEN) crd paths="$(REPO_ROOT)/api/core/v1alpha1/..." output:crd:artifacts:config=api/crds/manifests |
| 51 | + @$(CONTROLLER_GEN) webhook paths="$(REPO_ROOT)/api/..." |
| 52 | + |
| 53 | +.PHONY: generate |
| 54 | +generate: generate-code manifests generate-docs format ## Generates code (DeepCopy stuff, CRDs), documentation index, and runs formatter. |
| 55 | + |
| 56 | +.PHONY: generate-code |
| 57 | +generate-code: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. Also fetches external APIs. |
| 58 | + @echo "> Fetching External APIs" |
| 59 | + @go run $(REPO_ROOT)/hack/external-apis/main.go |
| 60 | + @echo "> Generating DeepCopy Methods" |
| 61 | + @$(CONTROLLER_GEN) object paths="$(REPO_ROOT)/api/core/v1alpha1/..." |
| 62 | + |
| 63 | +.PHONY: format |
| 64 | +format: goimports ## Formats the imports. |
| 65 | + @FORMATTER=$(FORMATTER) $(REPO_ROOT)/hack/common/format.sh $(API_CODE_DIRS) $(ROOT_CODE_DIRS) |
| 66 | + |
| 67 | +.PHONY: verify |
| 68 | +verify: golangci-lint jq goimports ## Runs linter, 'go vet', and checks if the formatter has been run. |
| 69 | + @test "$(SKIP_DOCS_INDEX_CHECK)" = "true" || \ |
| 70 | + ( echo "> Verify documentation index ..." && \ |
| 71 | + JQ=$(JQ) $(REPO_ROOT)/hack/common/verify-docs-index.sh ) |
| 72 | + @( echo "> Verifying api module ..." && \ |
| 73 | + pushd $(REPO_ROOT)/api &>/dev/null && \ |
| 74 | + go vet $(API_CODE_DIRS) && \ |
| 75 | + $(LINTER) run -c $(REPO_ROOT)/.golangci.yaml $(API_CODE_DIRS) && \ |
| 76 | + popd &>/dev/null ) |
| 77 | + @( echo "> Verifying root module ..." && \ |
| 78 | + pushd $(REPO_ROOT) &>/dev/null && \ |
| 79 | + go vet $(ROOT_CODE_DIRS) && \ |
| 80 | + $(LINTER) run -c $(REPO_ROOT)/.golangci.yaml $(ROOT_CODE_DIRS) && \ |
| 81 | + popd &>/dev/null ) |
| 82 | + @test "$(SKIP_FORMATTING_CHECK)" = "true" || \ |
| 83 | + ( echo "> Checking for unformatted files ..." && \ |
| 84 | + FORMATTER=$(FORMATTER) $(REPO_ROOT)/hack/common/format.sh --verify $(API_CODE_DIRS) $(ROOT_CODE_DIRS) ) |
| 85 | + |
| 86 | +.PHONY: test |
| 87 | +test: #envtest ## Run tests. |
| 88 | +# KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(ROOT_CODE_DIRS) -coverprofile cover.out |
| 89 | + @( echo "> Test root module ..." && \ |
| 90 | + pushd $(REPO_ROOT) &>/dev/null && \ |
| 91 | + go test $(ROOT_CODE_DIRS) -coverprofile cover.root.out && \ |
| 92 | + go tool cover --html=cover.root.out -o cover.root.html && \ |
| 93 | + go tool cover -func cover.root.out | tail -n 1 && \ |
| 94 | + popd &>/dev/null ) |
| 95 | + |
| 96 | + @( echo "> Test api module ..." && \ |
| 97 | + pushd $(REPO_ROOT)/api &>/dev/null && \ |
| 98 | + go test $(API_CODE_DIRS) -coverprofile cover.api.out && \ |
| 99 | + go tool cover --html=cover.api.out -o cover.api.html && \ |
| 100 | + go tool cover -func cover.api.out | tail -n 1 && \ |
| 101 | + popd &>/dev/null ) |
| 102 | + |
| 103 | +##@ Build Dependencies |
| 104 | + |
| 105 | +## Location to install dependencies to |
| 106 | +LOCALBIN ?= $(REPO_ROOT)/bin |
| 107 | + |
| 108 | +# Tool Binaries |
| 109 | +ENVTEST ?= $(LOCALBIN)/setup-envtest |
| 110 | + |
| 111 | +# Tool Versions |
| 112 | +SETUP_ENVTEST_VERSION ?= release-0.16 |
| 113 | + |
| 114 | +ifndef LOCALBIN_TARGET |
| 115 | +.PHONY: localbin |
| 116 | +localbin: |
| 117 | + @test -d $(LOCALBIN) || mkdir -p $(LOCALBIN) |
| 118 | +endif |
| 119 | + |
| 120 | +.PHONY: envtest |
| 121 | +envtest: localbin ## Download envtest-setup locally if necessary. |
| 122 | + @test -s $(LOCALBIN)/setup-envtest && test -s $(LOCALBIN)/setup-envtest_version && cat $(LOCALBIN)/setup-envtest_version | grep -q $(SETUP_ENVTEST_VERSION) || \ |
| 123 | + ( echo "Installing setup-envtest $(SETUP_ENVTEST_VERSION) ..."; \ |
| 124 | + GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_VERSION) && \ |
| 125 | + echo $(SETUP_ENVTEST_VERSION) > $(LOCALBIN)/setup-envtest_version ) |
| 126 | + |
| 127 | +##@ Local Setup |
| 128 | + |
| 129 | +DISABLE_AUTHENTICATION ?= true |
| 130 | +DISABLE_AUTHORIZATION ?= true |
| 131 | +DISABLE_CLOUDORCHESTRATOR ?= true |
| 132 | +DISABLE_MANAGEDCONTROLPLANE ?= false |
| 133 | +DISABLE_APISERVER ?= true |
| 134 | +DISABLE_LANDSCAPER ?= true |
| 135 | +LOCAL_GOARCH ?= $(shell go env GOARCH) |
| 136 | + |
| 137 | +.PHONY: dev-local |
| 138 | +dev-local: dev-clean image-build-local dev-cluster load-image helm-install-local ## All-in-one command for creating a fresh local setup. |
| 139 | + |
| 140 | +.PHONY: dev-clean |
| 141 | +dev-clean: ## Removes the kind cluster for local setup. |
| 142 | + $(KIND) delete cluster --name=$(PROJECT_FULL_NAME)-dev |
| 143 | + |
| 144 | +.PHONY: dev-cluster |
| 145 | +dev-cluster: ## Creates a kind cluster for running a local setup. |
| 146 | + $(KIND) create cluster --name=$(PROJECT_FULL_NAME)-dev |
| 147 | + |
| 148 | +.PHONY: load-image |
| 149 | +load-image: ## Loads the image into the local setup kind cluster. |
| 150 | + $(KIND) load docker-image local/mcp-operator:${EFFECTIVE_VERSION}-linux-$(LOCAL_GOARCH) --name=$(PROJECT_FULL_NAME)-dev |
| 151 | + |
| 152 | +.PHONY: helm-install-local |
| 153 | +helm-install-local: ## Installs the MCP Operator into the local setup kind cluster by using its helm chart. |
| 154 | + helm upgrade --install $(PROJECT_FULL_NAME) charts/$(PROJECT_FULL_NAME)/ --set image.repository=local/mcp-operator --set image.tag=${EFFECTIVE_VERSION}-linux-$(LOCAL_GOARCH) --set image.pullPolicy=Never \ |
| 155 | + --set authentication.disabled=$(DISABLE_AUTHENTICATION) \ |
| 156 | + --set authorization.disabled=$(DISABLE_AUTHORIZATION) \ |
| 157 | + --set cloudOrchestrator.disabled=$(DISABLE_CLOUDORCHESTRATOR) \ |
| 158 | + --set managedcontrolplane.disabled=$(DISABLE_MANAGEDCONTROLPLANE) \ |
| 159 | + --set apiserver.disabled=$(DISABLE_APISERVER) \ |
| 160 | + --set landscaper.disabled=$(DISABLE_LANDSCAPER) |
| 161 | + |
| 162 | +.PHONY: install |
| 163 | +install: manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config (or $KUBECONFIG). Usually not required, as the MCP Operator installs the CRDs on its own. |
| 164 | + $(KUBECTL) apply -f config/crd/bases |
| 165 | + |
0 commit comments