github.com/kubewharf/katalyst-core@v0.5.3/Makefile (about) 1 # Copyright 2022 The Katalyst 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 GOPROXY := $(shell go env GOPROXY) 16 ifeq ($(GOPROXY),) 17 GOPROXY := https://proxy.golang.org 18 endif 19 export GOPROXY 20 21 MakeFilePath := $(shell dirname $(MAKEFILE_LIST)) 22 23 GIT_COMMIT = $(shell git rev-parse HEAD) 24 ifeq ($(shell git tag --points-at ${GIT_COMMIT}),) 25 GIT_VERSION=$(shell echo ${GIT_COMMIT} | cut -c 1-7) 26 else 27 GIT_VERSION=$(shell git describe --abbrev=0 --tags --always) 28 endif 29 30 IMAGE_TAG = ${GIT_VERSION} 31 REGISTRY ?= docker.io 32 REGISTRY_NAMESPACE ?= kubewharf 33 REGISTRY_USER ?= "" 34 REGISTRY_PWD ?= "" 35 36 .EXPORT_ALL_VARIABLES: 37 38 39 all: generate 40 41 ## -------------------------------------- 42 ## Generate / Manifests 43 ## -------------------------------------- 44 45 .PHONY: generate 46 generate: 47 $(MAKE) generate-pb 48 49 50 ## -------------------------------------- 51 ## Generate / Protocols 52 ## -------------------------------------- 53 54 .PHONY: generate-pb 55 generate-pb: generate-sys-advisor-cpu-plugin generate-advisor-svc generate-borwein-inference-svc 56 57 TempRepoDir := $(shell mktemp -d) 58 SysAdvisorCPUPluginPath = $(MakeFilePath)/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/ 59 .PHONY: generate-sys-advisor-cpu-plugin ## Generate protocol for cpu resource plugin with sys-advisor 60 generate-sys-advisor-cpu-plugin: 61 mkdir -p $(TempRepoDir)/github.com/kubewharf && \ 62 mkdir -p $(TempRepoDir)/github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc && \ 63 mkdir -p $(TempRepoDir)/github.com/gogo && \ 64 git clone https://github.com/kubewharf/kubelet.git $(TempRepoDir)/github.com/kubewharf/kubelet && \ 65 git clone https://github.com/gogo/protobuf.git $(TempRepoDir)/github.com/gogo/protobuf && \ 66 cp -f $(MakeFilePath)/pkg/agent/qrm-plugins/advisorsvc/advisor_svc.proto $(TempRepoDir)/github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc/ && \ 67 targetTag=`cat $(MakeFilePath)/go.mod | grep kubewharf/kubelet | awk '{print $$4}'` && \ 68 cd $(TempRepoDir)/github.com/kubewharf/kubelet && \ 69 git fetch --tags && \ 70 git checkout $$targetTag && \ 71 cd - && \ 72 protoc -I=$(SysAdvisorCPUPluginPath) -I=$(TempRepoDir) --gogo_out=plugins=grpc,paths=source_relative:$(SysAdvisorCPUPluginPath) $(SysAdvisorCPUPluginPath)cpu.proto && \ 73 cat $(MakeFilePath)/hack/boilerplate.go.txt "$(SysAdvisorCPUPluginPath)cpu.pb.go" > tmpfile && mv tmpfile "$(SysAdvisorCPUPluginPath)cpu.pb.go" 74 if [ `uname` == "Linux" ]; then sedi=(-i); else sedi=(-i ""); fi && \ 75 sed "$${sedi[@]}" s,github.com/kubewharf/kubelet,k8s.io/kubelet,g $(SysAdvisorCPUPluginPath)cpu.pb.go 76 77 AdvisorSvcPath = $(MakeFilePath)/pkg/agent/qrm-plugins/advisorsvc/ 78 .PHONY: generate-advisor-svc ## Generate protocol for general qrm-plugin with sys-advisor 79 generate-advisor-svc: 80 targetTag=`cat $(MakeFilePath)/go.mod | grep kubewharf/kubelet | awk '{print $$4}'` && \ 81 cd $(GOPATH)/src/github.com/kubewharf/kubelet && \ 82 git fetch --tags && \ 83 git checkout $$targetTag && \ 84 cd - && \ 85 protoc -I=$(AdvisorSvcPath) -I=$(TempRepoDir) --gogo_out=plugins=grpc,paths=source_relative:$(AdvisorSvcPath) $(AdvisorSvcPath)advisor_svc.proto && \ 86 cat $(MakeFilePath)/hack/boilerplate.go.txt "$(AdvisorSvcPath)advisor_svc.pb.go" > tmpfile && mv tmpfile "$(AdvisorSvcPath)advisor_svc.pb.go" 87 if [ `uname` == "Linux" ]; then sedi=(-i); else sedi=(-i ""); fi && \ 88 sed "$${sedi[@]}" s,github.com/kubewharf/kubelet,k8s.io/kubelet,g $(AdvisorSvcPath)advisor_svc.pb.go 89 90 BorweinInferenceSvcPath = $(MakeFilePath)/pkg/agent/sysadvisor/plugin/inference/models/borwein/inferencesvc/ 91 .PHONY: generate-borwein-inference-svc ## Generate protocol for borwein inference service 92 generate-borwein-inference-svc: 93 protoc -I=$(BorweinInferenceSvcPath) -I=$(TempRepoDir) --gogo_out=plugins=grpc,paths=source_relative:$(BorweinInferenceSvcPath) $(BorweinInferenceSvcPath)inference_svc.proto && \ 94 cat $(MakeFilePath)/hack/boilerplate.go.txt "$(BorweinInferenceSvcPath)inference_svc.pb.go" > tmpfile && mv tmpfile "$(BorweinInferenceSvcPath)inference_svc.pb.go" 95 96 97 ## -------------------------------------- 98 ## Cleanup / Verification 99 ## -------------------------------------- 100 101 .PHONY: clean 102 clean: ## Remove all generated files 103 $(MAKE) clean-bin 104 105 .PHONY: clean-bin 106 clean-bin: ## Remove all generated binaries 107 rm -rf bin 108 rm -rf hack/tools/bin 109 rm -rf output 110 111 .PHONY: fmt 112 fmt: ## Run go fmt against code. 113 go fmt ./... 114 115 .PHONY: fmt-strict 116 fmt-strict: ## Run go fmt against code. 117 gofumpt -l -w . 118 119 .PHONY: vet 120 vet: ## Run go vet against code. 121 go vet ./... 122 123 .PHONY: test 124 test: ## Run go test against code. 125 go test -v -coverprofile=coverage.txt -parallel=16 -p=16 -covermode=atomic -race -coverpkg=./... \ 126 `go list ./pkg/... | grep -E -v "pkg/scheduler|pkg/controller/resource-recommend|pkg/util/resource-recommend"` 127 128 .PHONY: license 129 license: 130 ./hack/add-license.sh 131 132 133 ## -------------------------------------- 134 ## Build binaries and images 135 ## -------------------------------------- 136 137 # For now, only build binary and images for linux/amd64 platform by default 138 build-binaries: 139 bash -c "build/build.sh ${TARGET}" 140 141 build-images: BUILD_IMAGES=y 142 build-images: build-binaries 143 144 controller: 145 $(MAKE) build-binaries TARGET=katalyst-controller 146 147 agent: 148 $(MAKE) build-binaries TARGET=katalyst-agent 149 150 webhook: 151 $(MAKE) build-binaries TARGET=katalyst-webhook 152 153 scheduler: 154 $(MAKE) build-binaries TARGET=katalyst-scheduler 155 156 metric: 157 $(MAKE) build-binaries TARGET=katalyst-metric 158 159 all-binaries: controller agent webhook scheduler metric 160 161 image-controller: 162 $(MAKE) build-images TARGET=katalyst-controller 163 164 image-agent: 165 $(MAKE) build-images TARGET=katalyst-agent 166 167 image-webhook: 168 $(MAKE) build-images TARGET=katalyst-webhook 169 170 image-scheduler: 171 $(MAKE) build-images TARGET=katalyst-scheduler 172 173 image-metric: 174 $(MAKE) build-images TARGET=katalyst-metric 175 176 all-images: image-controller image-agent image-webhook image-scheduler image-metric 177 178 docker-login: 179 ifneq ($(REGISTRY_USER), "") 180 docker login -u $(REGISTRY_USER) -p $(REGISTRY_PWD) $(REGISTRY) 181 else 182 @echo No login credential provided, skip log in... 183 endif 184 185 push-image-controller: docker-login image-controller 186 docker push "${REGISTRY}/${REGISTRY_NAMESPACE}/katalyst-controller:${IMAGE_TAG}" 187 188 push-image-agent: docker-login image-agent 189 docker push "${REGISTRY}/${REGISTRY_NAMESPACE}/katalyst-agent:${IMAGE_TAG}" 190 191 push-image-webhook: docker-login image-webhook 192 docker push "${REGISTRY}/${REGISTRY_NAMESPACE}/katalyst-webhook:${IMAGE_TAG}" 193 194 push-image-scheduler: docker-login image-scheduler 195 docker push "${REGISTRY}/${REGISTRY_NAMESPACE}/katalyst-scheduler:${IMAGE_TAG}" 196 197 push-image-metric: docker-login image-metric 198 docker push "${REGISTRY}/${REGISTRY_NAMESPACE}/katalyst-metric:${IMAGE_TAG}" 199 200 push-all-images: docker-login push-image-controller push-image-agent push-image-webhook push-image-scheduler push-image-metric