|
| 1 | +# Copyright 2022 The Kubernetes Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +GIT_TAG ?= $(shell git describe --tags --dirty --always) |
| 16 | +# Image URL to use all building/pushing image targets |
| 17 | +IMAGE_BUILD_CMD ?= docker build |
| 18 | +IMAGE_PUSH_CMD ?= docker push |
| 19 | +IMAGE_BUILD_EXTRA_OPTS ?= |
| 20 | +IMAGE_REGISTRY ?= ccr.ccs.tencentyun.com/elastic-ai |
| 21 | +IMAGE_NAME := elastic-queue |
| 22 | +IMAGE_REPO ?= $(IMAGE_REGISTRY)/$(IMAGE_NAME) |
| 23 | +IMAGE_TAG ?= $(IMAGE_REPO):$(GIT_TAG) |
| 24 | +KUEUE_DIR ?= ./vendor/sigs.k8s.io/kueue |
| 25 | +# kubeflow training-operator for elastic-queue version |
| 26 | +TRAINING_OPERATOR_DIR ?= ./config/kubeflow/trainingoperator |
| 27 | +TRAINING_OPERATOR_IMG ?= $(IMAGE_REGISTRY)/training-operator |
| 28 | + |
| 29 | +ifdef EXTRA_TAG |
| 30 | +IMAGE_EXTRA_TAG ?= $(IMAGE_REPO):$(EXTRA_TAG) |
| 31 | +endif |
| 32 | +ifdef IMAGE_EXTRA_TAG |
| 33 | +IMAGE_BUILD_EXTRA_OPTS += -t $(IMAGE_EXTRA_TAG) |
| 34 | +endif |
| 35 | + |
| 36 | +# Use distroless as minimal base image to package the manager binary |
| 37 | +# Refer to https://github.com/GoogleContainerTools/distroless for more details |
| 38 | +BASE_IMAGE ?= gcr.io/distroless/static:nonroot |
| 39 | +BUILDER_IMAGE ?= golang:1.18 |
| 40 | + |
| 41 | +# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. |
| 42 | +ENVTEST_K8S_VERSION = 1.23 |
| 43 | + |
| 44 | +INTEGRATION_TARGET ?= ./test/integration/... |
| 45 | + |
| 46 | +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
| 47 | +ifeq (,$(shell go env GOBIN)) |
| 48 | +GOBIN=$(shell go env GOPATH)/bin |
| 49 | +else |
| 50 | +GOBIN=$(shell go env GOBIN) |
| 51 | +endif |
| 52 | + |
| 53 | +GO_CMD ?= go |
| 54 | +GO_FMT ?= gofmt |
| 55 | +GO_TEST_FLAGS ?= -race |
| 56 | + |
| 57 | +# Setting SHELL to bash allows bash commands to be executed by recipes. |
| 58 | +# This is a requirement for 'setup-envtest.sh' in the test target. |
| 59 | +# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
| 60 | +SHELL = /usr/bin/env bash -o pipefail |
| 61 | +.SHELLFLAGS = -ec |
| 62 | + |
| 63 | +.PHONY: all |
| 64 | +all: build |
| 65 | + |
| 66 | +##@ General |
| 67 | + |
| 68 | +# The help target prints out all targets with their descriptions organized |
| 69 | +# beneath their categories. The categories are represented by '##@' and the |
| 70 | +# target descriptions by '##'. The awk commands is responsible for reading the |
| 71 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 72 | +# file as xyz: ## something, and then pretty-format the target and help. Then, |
| 73 | +# if there's a line with ##@ something, that gets pretty-printed as a category. |
| 74 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 75 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 76 | +# More info on the awk command: |
| 77 | +# http://linuxcommand.org/lc3_adv_awk.php |
| 78 | + |
| 79 | +.PHONY: help |
| 80 | +help: ## Display this help. |
| 81 | + @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) |
| 82 | + |
| 83 | +##@ Development |
| 84 | + |
| 85 | +.PHONY: manifests |
| 86 | +manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. |
| 87 | + $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./$(KUEUE_DIR)/..." output:crd:artifacts:config=config/crd/bases |
| 88 | + |
| 89 | +.PHONY: generate |
| 90 | +generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. |
| 91 | + $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./$(KUEUE_DIR)/..." |
| 92 | + |
| 93 | +.PHONY: fmt |
| 94 | +fmt: ## Run go fmt against code. |
| 95 | + $(GO_CMD) fmt ./... |
| 96 | + |
| 97 | +.PHONY: fmt-verify |
| 98 | +fmt-verify: |
| 99 | + @out=`$(GO_FMT) -w -l -d $$(find . -name '*.go')`; \ |
| 100 | + if [ -n "$$out" ]; then \ |
| 101 | + echo "$$out"; \ |
| 102 | + exit 1; \ |
| 103 | + fi |
| 104 | + |
| 105 | +.PHONY: gomod-verify |
| 106 | +gomod-verify: |
| 107 | + $(GO_CMD) mod tidy |
| 108 | + git --no-pager diff --exit-code go.mod go.sum |
| 109 | + |
| 110 | +.PHONY: vet |
| 111 | +vet: ## Run go vet against code. |
| 112 | + $(GO_CMD) vet ./... |
| 113 | + |
| 114 | +.PHONY: test |
| 115 | +test: generate fmt vet ## Run tests. |
| 116 | + $(GO_CMD) test $(GO_TEST_FLAGS) ./pkg/... -coverprofile cover.out |
| 117 | + |
| 118 | +.PHONY: test-integration |
| 119 | +test-integration: manifests generate fmt vet envtest ginkgo ## Run tests. |
| 120 | + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" \ |
| 121 | + $(GINKGO) -v $(INTEGRATION_TARGET) |
| 122 | + |
| 123 | +.PHONY: ci-lint |
| 124 | +ci-lint: golangci-lint |
| 125 | + $(GOLANGCI_LINT) run --timeout 7m0s |
| 126 | + |
| 127 | +.PHONY: verify |
| 128 | +verify: gomod-verify vet ci-lint fmt-verify |
| 129 | + |
| 130 | +##@ Build |
| 131 | + |
| 132 | +.PHONY: build |
| 133 | +build: generate fmt vet ## Build manager binary. |
| 134 | + $(GO_CMD) build -o bin/manager main.go |
| 135 | + |
| 136 | +.PHONY: run |
| 137 | +run: fmt vet ## Run a controller from your host. |
| 138 | + $(GO_CMD) run ./main.go |
| 139 | + |
| 140 | +# Build the container image |
| 141 | +.PHONY: image-build |
| 142 | +image-build: |
| 143 | + $(IMAGE_BUILD_CMD) -t $(IMAGE_TAG) \ |
| 144 | + --build-arg BASE_IMAGE=$(BASE_IMAGE) \ |
| 145 | + --build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \ |
| 146 | + $(IMAGE_BUILD_EXTRA_OPTS) ./ |
| 147 | + |
| 148 | +.PHONY: image-push |
| 149 | +image-push: |
| 150 | + $(IMAGE_PUSH_CMD) $(IMAGE_TAG) |
| 151 | + if [ -n "$(IMAGE_EXTRA_TAG)" ]; then \ |
| 152 | + $(IMAGE_PUSH_CMD) $(IMAGE_EXTRA_TAG); \ |
| 153 | + fi |
| 154 | + |
| 155 | +##@ Deployment |
| 156 | + |
| 157 | +ifndef ignore-not-found |
| 158 | + ignore-not-found = false |
| 159 | +endif |
| 160 | + |
| 161 | +clean-manifests = (cd config/manager && $(KUSTOMIZE) edit set image controller=ccr.ccs.tencentyun.com/elastic-ai/elastic-queue:main) |
| 162 | + |
| 163 | +.PHONY: install |
| 164 | +install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. |
| 165 | + $(KUSTOMIZE) build config/crd | kubectl apply -f - |
| 166 | + |
| 167 | +.PHONY: uninstall |
| 168 | +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. |
| 169 | + $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - |
| 170 | + |
| 171 | +.PHONY: deploy |
| 172 | +deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. |
| 173 | + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMAGE_TAG} |
| 174 | + $(KUSTOMIZE) build config/default | kubectl apply -f - |
| 175 | + @$(call clean-manifests) |
| 176 | + |
| 177 | +.PHONY: undeploy |
| 178 | +undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. |
| 179 | + $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - |
| 180 | + |
| 181 | +##@ Release |
| 182 | +.PHONY: artifacts |
| 183 | +artifacts: kustomize |
| 184 | + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMAGE_TAG} |
| 185 | + if [ -d artifacts ]; then rm -rf artifacts; fi |
| 186 | + @mkdir -p artifacts |
| 187 | + $(KUSTOMIZE) build config/default -o artifacts/manifests.yaml |
| 188 | + ## Release kubeflow trainnig-operator for elastic-queue version |
| 189 | + cd $(TRAINING_OPERATOR_DIR)/overlays/standalone && $(KUSTOMIZE) edit set image kubeflow/training-operator=${TRAINING_OPERATOR_IMG} |
| 190 | + $(KUSTOMIZE) build $(TRAINING_OPERATOR_DIR)/overlays/standalone -o artifacts/kubeflow-training-operator-manifests.yaml |
| 191 | + |
| 192 | +##@ Tools |
| 193 | +PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) |
| 194 | +GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint |
| 195 | +.PHONY: golangci-lint |
| 196 | +golangci-lint: ## Download golangci-lint locally if necessary. |
| 197 | + @GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.0 |
| 198 | + |
| 199 | +CONTROLLER_GEN = $(shell pwd)/bin/controller-gen |
| 200 | +.PHONY: controller-gen |
| 201 | +controller-gen: ## Download controller-gen locally if necessary. |
| 202 | + @GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0 |
| 203 | + |
| 204 | +KUSTOMIZE = $(shell pwd)/bin/kustomize |
| 205 | +.PHONY: kustomize |
| 206 | +kustomize: ## Download kustomize locally if necessary. |
| 207 | + @GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install sigs.k8s.io/kustomize/kustomize/v4@v4.5.2 |
| 208 | + |
| 209 | +ENVTEST = $(shell pwd)/bin/setup-envtest |
| 210 | +.PHONY: envtest |
| 211 | +envtest: ## Download envtest-setup locally if necessary. |
| 212 | + @GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest |
| 213 | + |
| 214 | +GINKGO = $(shell pwd)/bin/ginkgo |
| 215 | +.PHONY: ginkgo |
| 216 | +ginkgo: ## Download ginkgo locally if necessary. |
| 217 | + @GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install github.com/onsi/ginkgo/v2/ginkgo@v2.1.4 |
0 commit comments