forked from project-codeflare/multi-cluster-app-dispatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
225 lines (193 loc) · 9.89 KB
/
Makefile
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
BIN_DIR=_output/bin
CAT_CMD=$(if $(filter $(OS),Windows_NT),type,cat)
RELEASE_VER:=
CURRENT_DIR=$(shell pwd)
GIT_BRANCH:=$(shell git symbolic-ref --short HEAD 2>&1 | grep -v fatal)
#define the GO_BUILD_ARGS if you need to pass additional arguments to the go build
GO_BUILD_ARGS?=
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.9.2
CODEGEN_VERSION ?= v0.27.2
## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
APPLYCONFIGURATION_GEN ?= $(LOCALBIN)/applyconfiguration-gen
CLIENT_GEN ?= $(LOCALBIN)/client-gen
LISTER_GEN ?= $(LOCALBIN)/lister-gen
INFORMER_GEN ?= $(LOCALBIN)/informer-gen
TAG:=$(shell echo "")
# Check for current branch name and update 'RELEASE_VER' and 'TAG'
ifneq ($(strip $(GIT_BRANCH)),)
RELEASE_VER:= $(shell git describe --tags --abbrev=0)
TAG:=${TAG}${GIT_BRANCH}
# replace invalid characters that might exist in the branch name
TAG:=$(shell echo ${TAG} | sed 's/[^a-zA-Z0-9]/-/g')
TAG:=${TAG}-${RELEASE_VER}
endif
.PHONY: print-global-variables
# Build the controller executable for use in docker image build
mcad-controller: init generate-code
ifeq ($(strip $(GO_BUILD_ARGS)),)
$(info Compiling controller)
CGO_ENABLED=0 go build -o ${BIN_DIR}/mcad-controller ./cmd/kar-controllers/
else
$(info Compiling controller with build arguments: '${GO_BUILD_ARGS}')
go build $(GO_BUILD_ARGS) -o ${BIN_DIR}/mcad-controller ./cmd/kar-controllers/
endif
print-global-variables:
$(info "---")
$(info "MAKE GLOBAL VARIABLES:")
$(info " "BIN_DIR="$(BIN_DIR)")
$(info " "GIT_BRANCH="$(GIT_BRANCH)")
$(info " "RELEASE_VER="$(RELEASE_VER)")
$(info " "TAG="$(TAG)")
$(info " "GO_BUILD_ARGS="$(GO_BUILD_ARGS)")
$(info "---")
verify: generate-code
# hack/verify-gofmt.sh
# hack/verify-golint.sh
# hack/verify-gencode.sh
init:
mkdir -p ${BIN_DIR}
verify-tag-name: print-global-variables
# Check for invalid tag name
t=${TAG} && [ $${#t} -le 128 ] || { echo "Target name $$t has 128 or more chars"; false; }
.PHONY: generate-client ## Generate client packages
generate-client: code-generator
rm -rf pkg/client/applyconfiguration pkg/client/clientset/versioned pkg/client/informers/externalversions pkg/client/listers/controller/v1beta1 pkg/client/listers/quotasubtree/v1alpha1
$(APPLYCONFIGURATION_GEN) \
--input-dirs="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" \
--go-header-file="hack/boilerplate/boilerplate.go.txt" \
--output-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/applyconfiguration" \
--trim-path-prefix "github.com/project-codeflare/multi-cluster-app-dispatcher"
$(CLIENT_GEN) \
--input="pkg/apis/controller/v1beta1" \
--input="pkg/apis/quotaplugins/quotasubtree/v1alpha1" \
--input-base="github.com/project-codeflare/multi-cluster-app-dispatcher" \
--go-header-file="hack/boilerplate/boilerplate.go.txt" \
--clientset-name "versioned" \
--output-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/clientset" \
--output-base="." \
--trim-path-prefix "github.com/project-codeflare/multi-cluster-app-dispatcher"
$(LISTER_GEN) \
--input-dirs="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" \
--input-dirs="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/quotaplugins/quotasubtree/v1alpha1" \
--go-header-file="hack/boilerplate/boilerplate.go.txt" \
--output-base="." \
--output-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/listers" \
--trim-path-prefix "github.com/project-codeflare/multi-cluster-app-dispatcher"
$(INFORMER_GEN) \
--input-dirs="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" \
--input-dirs="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/quotaplugins/quotasubtree/v1alpha1" \
--versioned-clientset-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/clientset/versioned" \
--listers-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/listers" \
--go-header-file="hack/boilerplate/boilerplate.go.txt" \
--output-base="." \
--output-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/informers" \
--trim-path-prefix "github.com/project-codeflare/multi-cluster-app-dispatcher"
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: code-generator
code-generator: $(APPLYCONFIGURATION_GEN) $(CLIENT_GEN) $(LISTER_GEN) $(INFORMER_GEN) $(CONTROLLER_GEN)
.PHONY: applyconfiguration-gen
applyconfiguration-gen: $(APPLYCONFIGURATION_GEN)
$(APPLYCONFIGURATION_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/applyconfiguration-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/applyconfiguration-gen@$(CODEGEN_VERSION)
.PHONY: client-gen
client-gen: $(CLIENT_GEN)
$(CLIENT_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/client-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/client-gen@$(CODEGEN_VERSION)
.PHONY: lister-gen
lister-gen: $(LISTER_GEN)
$(LISTER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/lister-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/lister-gen@$(CODEGEN_VERSION)
.PHONY: informer-gen
informer-gen: $(INFORMER_GEN)
$(INFORMER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/informer-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/informer-gen@$(CODEGEN_VERSION)
.PHONY: manifests
manifests: controller-gen ## Generate CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd:allowDangerousTypes=true paths="./pkg/apis/..." output:crd:artifacts:config=config/crd/bases
.PHONY: generate-code
generate-code: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate/boilerplate.go.txt" paths="./pkg/apis/..."
images: verify-tag-name generate-code update-deployment-crds
$(info List executable directory)
$(info repo id: ${git_repository_id})
$(info branch: ${GIT_BRANCH})
$(info Build the docker image)
ifeq ($(strip $(GO_BUILD_ARGS)),)
docker build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
else
docker build --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
endif
images-podman: verify-tag-name generate-code update-deployment-crds
$(info List executable directory)
$(info repo id: ${git_repository_id})
$(info branch: ${GIT_BRANCH})
$(info Build the docker image)
ifeq ($(strip $(GO_BUILD_ARGS)),)
podman build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
else
podman build --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
endif
push-images: verify-tag-name
ifeq ($(strip $(quay_repository)),)
$(info No registry information provided. To push images to a docker registry please set)
$(info environment variables: quay_repository, quay_token, and quay_id. Environment)
else
$(info Log into quay)
docker login quay.io -u ${quay_id} --password ${quay_token}
$(info Tag the latest image)
docker tag mcad-controller:${TAG} ${quay_repository}/mcad-controller:${TAG}
$(info Push the docker image to registry)
docker push ${quay_repository}/mcad-controller:${TAG}
ifeq ($(strip $(git_repository_id)),main)
$(info Update the `dev` tag when built from `main`)
docker tag mcad-controller:${TAG} ${quay_repository}/mcad-controller:latest
docker push ${quay_repository}/mcad-controller:latest
endif
ifneq ($(TAG:release-v%=%),$(TAG))
$(info Update the `stable` tag to point `latest` release image)
docker tag mcad-controller:${TAG} ${quay_repository}/mcad-controller:stable
docker push ${quay_repository}/mcad-controller:stable
endif
endif
# easy-deploy can be used for building and pushing a custom image of MCAD and deploying it on your K8s cluster for development.
# Example: "make easy-deploy TAG=<image tag> USERNAME=<quay.io username>"
easy-deploy: images-podman
podman tag localhost/mcad-controller:${TAG} quay.io/${USERNAME}/mcad-controller:${TAG}
podman push quay.io/${USERNAME}/mcad-controller:${TAG}
cd deployment && helm install mcad-controller mcad-controller --namespace kube-system --wait --set image.repository=quay.io/${USERNAME}/mcad-controller --set image.tag=${TAG}
run-test:
$(info Running unit tests...)
go test -v -coverprofile cover.out -race -parallel 8 ./pkg/...
run-e2e: verify-tag-name update-deployment-crds
ifeq ($(strip $(quay_repository)),)
echo "Running e2e with MCAD local image: mcad-controller ${TAG} IfNotPresent."
hack/run-e2e-kind.sh mcad-controller ${TAG} IfNotPresent
else
echo "Running e2e with MCAD registry image image: ${quay_repository}/mcad-controller ${TAG}."
hack/run-e2e-kind.sh ${quay_repository}/mcad-controller ${TAG}
endif
coverage:
# KUBE_COVER=y hack/make-rules/test.sh $(WHAT) $(TESTS)
clean:
rm -rf _output/
#CRD file maintenance rules
DEPLOYMENT_CRD_DIR=deployment/mcad-controller/crds
CRD_BASE_DIR=config/crd/bases
MCAD_CRDS= ${DEPLOYMENT_CRD_DIR}/quota.codeflare.dev_quotasubtrees.yaml \
${DEPLOYMENT_CRD_DIR}/workload.codeflare.dev_appwrappers.yaml \
${DEPLOYMENT_CRD_DIR}/workload.codeflare.dev_schedulingspecs.yaml
update-deployment-crds: ${MCAD_CRDS}
${DEPLOYMENT_CRD_DIR}/quota.codeflare.dev_quotasubtrees.yaml : ${CRD_BASE_DIR}/quota.codeflare.dev_quotasubtrees.yaml
${DEPLOYMENT_CRD_DIR}/workload.codeflare.dev_appwrappers.yaml : ${CRD_BASE_DIR}/workload.codeflare.dev_appwrappers.yaml
${DEPLOYMENT_CRD_DIR}/workload.codeflare.dev_schedulingspecs.yaml : ${CRD_BASE_DIR}/workload.codeflare.dev_schedulingspecs.yaml
$(DEPLOYMENT_CRD_DIR)/%: ${CRD_BASE_DIR}/%
cp $< $@