-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile
290 lines (241 loc) · 12.6 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#
# Copyright (c) 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
SHELL = /bin/bash
# The operator image name to be used. By default it point to internal repo.
# Can be swapped with the public operator for building the final bundle image
OPERATOR_IMAGE ?= registry.toolbox.iotg.sclab.intel.com/cpp/openvino-operator
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
# TARGET_PLATFORM can be k8s or openshift
TARGET_PLATFORM =? k8s
# ADD_NOTEBOOK_K8S can be used to add functionality of notebook in K8S bundle
# version for openshift testing purposes. Testing requires mocked resources
# of buildconfig and images stream
ADD_NOTEBOOK_K8S =? 0
# Build-time variables to inject into binaries
export GIT_COMMIT = $(shell git rev-parse HEAD)
# Build settings
export TOOLS_DIR = tools/bin
export SCRIPTS_DIR = tools/scripts
REPO = $(shell go list -m)
BUILD_DIR = build
GO_ASMFLAGS = -asmflags "all=-trimpath=$(shell dirname $(PWD))"
GO_GCFLAGS = -gcflags "all=-trimpath=$(shell dirname $(PWD))"
GO_BUILD_ARGS = \
$(GO_GCFLAGS) $(GO_ASMFLAGS)
export GO111MODULE = on
export CGO_ENABLED = 0
export PATH := $(PWD)/$(BUILD_DIR):$(PATH)
ifneq ($(PLATFORM_KUBECONFIG), )
export KUBECONFIG=$(PLATFORM_KUBECONFIG)
endif
# TAG by default includes the git commit. It can be set manually to any user friendly name like release name.
# the catalog imamge includes also the tag in a format <branch>-latest
IMAGE_TAG ?= $(shell git rev-parse --short HEAD)
##@ Development
.PHONY: fix
fix: ## Fixup files in the repo.
go mod tidy
go fmt ./...
.PHONY: clean
clean: ## Cleanup build artifacts and tool binaries.
rm -rf $(BUILD_DIR) dist $(TOOLS_DIR)
##@ Build
.PHONY: build
build: ## Build operator-sdk, ansible-operator, and helm-operator.
@mkdir -p $(BUILD_DIR)
go mod download
go build $(GO_BUILD_ARGS) -o $(BUILD_DIR)/openvino-operator ./cmd
run: build # Run against the configured Kubernetes cluster in ~/.kube/config
./$(BUILD_DIR)/openvino-operator run
run_k8s: build # Run against the configured Kubernetes cluster in ~/.kube/config
./$(BUILD_DIR)/openvino-operator run --watches-file watches_k8s.yaml
.PHONY: test-unit
TEST_PKGS = $(shell go list ./...)
test-unit: ## Run unit tests
go test -coverprofile=coverage.out -covermode=count -short $(TEST_PKGS)
docker-build: ## Build docker image with the manager.
docker build -t ${OPERATOR_IMAGE}:${IMAGE_TAG} --build-arg https_proxy=$(https_proxy) --build-arg http_proxy=$(http_proxy) -f docker/Dockerfile .
docker-push: ## Push docker image with the manager.
docker push ${OPERATOR_IMAGE}:${IMAGE_TAG}
BUNDLE_REPOSITORY ?= registry.toolbox.iotg.sclab.intel.com/cpp/openvino-operator-bundle
CATALOG_REPOSITORY ?= registry.toolbox.iotg.sclab.intel.com/cpp/openvino-operator-catalog
bundle_build:
ifeq ($(TARGET_PLATFORM), openshift)
echo "Building openshift bundle"
sed -i "s|registry.connect.redhat.com/intel/ovms-operator@sha256:9049f5d4e3c764fdca057b60e41ea62c3ca49207433f593668091850d27977d4|$(OPERATOR_IMAGE):$(IMAGE_TAG)|" bundle/manifests/openvino-operator.clusterserviceversion.yaml
docker build -t $(BUNDLE_REPOSITORY):$(IMAGE_TAG) -f bundle/Dockerfile bundle
sed -i "s|$(OPERATOR_IMAGE):$(IMAGE_TAG)|registry.connect.redhat.com/intel/ovms-operator@sha256:9049f5d4e3c764fdca057b60e41ea62c3ca49207433f593668091850d27977d4|" bundle/manifests/openvino-operator.clusterserviceversion.yaml
else
echo "Building kubernetes bundle"
ifeq ($(ADD_NOTEBOOK_K8S), 1)
sed -i "s|registry.redhat.io/openshift4/ose-kube-rbac-proxy@sha256:12f0c23da8a11e77c4aa58bd38143ab34858405c66936296aaebf21b4e61fd92|gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0|" bundle/manifests/openvino-operator.clusterserviceversion.yaml
sed -i "s|registry.connect.redhat.com/intel/ovms-operator@sha256:9049f5d4e3c764fdca057b60e41ea62c3ca49207433f593668091850d27977d4|$(OPERATOR_IMAGE):$(IMAGE_TAG)|" bundle/manifests/openvino-operator.clusterserviceversion.yaml
docker build -t $(BUNDLE_REPOSITORY)-k8s:$(IMAGE_TAG) -f bundle/Dockerfile bundle
sed -i "s|$(OPERATOR_IMAGE):$(IMAGE_TAG)|registry.connect.redhat.com/intel/ovms-operator@sha256:9049f5d4e3c764fdca057b60e41ea62c3ca49207433f593668091850d27977d4|" bundle/manifests/openvino-operator.clusterserviceversion.yaml
sed -i "s|gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0|registry.redhat.io/openshift4/ose-kube-rbac-proxy@sha256:da5714b93ac39277affdc10c3ba142d8c032ed0ddb2ba61c04cbddac710464c4|" bundle/manifests/openvino-operator.clusterserviceversion.yaml
else
sed -i "s|quay.io/openvino/ovms-operator:1.2.0|$(OPERATOR_IMAGE):$(IMAGE_TAG)|" bundle_k8s/manifests/openvino-operator.clusterserviceversion.yaml
docker build -t $(BUNDLE_REPOSITORY)-k8s:$(IMAGE_TAG) -f bundle_k8s/Dockerfile bundle_k8s
sed -i "s|$(OPERATOR_IMAGE):$(IMAGE_TAG)|quay.io/openvino/ovms-operator:1.2.0|" bundle_k8s/manifests/openvino-operator.clusterserviceversion.yaml
endif
endif
bundle_push:
ifeq ($(TARGET_PLATFORM), openshift)
docker push $(BUNDLE_REPOSITORY):$(IMAGE_TAG)
else
docker push $(BUNDLE_REPOSITORY)-k8s:$(IMAGE_TAG)
endif
catalog_build:
ifeq ($(TARGET_PLATFORM), openshift)
docker -v | grep -q podman ; if [ $$? -eq 0 ]; then \
opm index add --bundles $(BUNDLE_REPOSITORY):$(IMAGE_TAG) --from-index registry.redhat.io/redhat/certified-operator-index:v4.10 -c podman --tag $(CATALOG_REPOSITORY):$(IMAGE_TAG) ;\
else sudo opm index add --bundles $(BUNDLE_REPOSITORY):$(IMAGE_TAG) --from-index registry.redhat.io/redhat/certified-operator-index:v4.10 -c docker --tag $(CATALOG_REPOSITORY):$(IMAGE_TAG) ;\
fi
docker tag $(CATALOG_REPOSITORY):$(IMAGE_TAG) $(CATALOG_REPOSITORY):$(BRANCH)-latest
else
sudo opm index add --bundles quay.io/operatorhubio/ovms-operator:v0.1.0,quay.io/operatorhubio/ovms-operator:v0.2.0,quay.io/operatorhubio/ovms-operator:v1.0.0,quay.io/operatorhubio/ovms-operator:v1.1.0,$(BUNDLE_REPOSITORY)-k8s:$(IMAGE_TAG) -c docker --tag $(CATALOG_REPOSITORY)-k8s:$(IMAGE_TAG)
docker tag $(CATALOG_REPOSITORY)-k8s:$(IMAGE_TAG) $(CATALOG_REPOSITORY)-k8s:$(BRANCH)-latest
endif
catalog_push:
ifeq ($(TARGET_PLATFORM), openshift)
docker push $(CATALOG_REPOSITORY):$(IMAGE_TAG)
docker push $(CATALOG_REPOSITORY):$(BRANCH)-latest
else
docker push $(CATALOG_REPOSITORY)-k8s:$(IMAGE_TAG)
docker push $(CATALOG_REPOSITORY)-k8s:$(BRANCH)-latest
endif
install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${OPERATOR_IMAGE}:${IMAGE_TAG}
$(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 -
all: build_all_images deploy_catalog deploy_operator
build_all_images: docker-build docker-push bundle_build bundle_push catalog_build catalog_push
build_bundle_catalog_images: bundle_build bundle_push catalog_build catalog_push
cluster_clean:
ifeq ($(TARGET_PLATFORM), openshift)
echo "Skipping cleanup"
else
kubectl delete --ignore-not-found=true ns operator
kubectl get ns olm ; if [ $$? -eq 0 ]; then operator-sdk olm uninstall ; fi
operator-sdk olm install --version v0.27.0 --timeout 10m0s
endif
deploy_catalog:
ifeq ($(TARGET_PLATFORM), openshift)
kubectl delete --ignore-not-found=true -n openshift-marketplace --ignore-not-found=true CatalogSource my-test-catalog
sleep 10
cat tests/catalog-source.yaml | sed "s|catalog:latest|$(CATALOG_REPOSITORY):$(IMAGE_TAG)|" | sed "s|olm|openshift-marketplace|"| kubectl apply -f -
sleep 20
else
kubectl delete --ignore-not-found=true -n olm --ignore-not-found=true CatalogSource my-test-catalog
sleep 10
cat tests/catalog-source.yaml | sed "s|catalog:latest|$(CATALOG_REPOSITORY)-k8s:$(IMAGE_TAG)|" | kubectl apply -f -
sleep 20
endif
deploy_operator:
ifeq ($(TARGET_PLATFORM), openshift)
echo "Skipping deployment, TDB"
else
kubectl create ns operator || true
kubectl apply -f tests/operator-group.yaml
sed -i "s|<http_proxy>|$(http_proxy)|" tests/operator-subscription.yaml
sed -i "s|<https_proxy>|$(https_proxy)|" tests/operator-subscription.yaml
sed -i "s|<no_proxy>|$(no_proxy)|" tests/operator-subscription.yaml
kubectl apply -f tests/operator-subscription.yaml
sleep 15
kubectl get clusterserviceversion --all-namespaces
endif
platform-build-software: PLATFORM_BUILD_DIR PLATFORM_BUILD_MODE $(PLATFORM_BUILD_MODE)
@echo ========== Target builds platform software ===============
@echo Args:
@echo PLATFORM_BUILD_DIR: installation files directory [$(PLATFORM_BUILD_DIR)]
@echo OPERATOR_IMAGE: [$(OPERATOR_IMAGE)]
@echo IMAGE_TAG: [$(IMAGE_TAG)]
@echo TARGET_PLATFORM: [$(TARGET_PLATFORM)]
@echo PLATFORM_PACKAGE_DIR: packages files directory
@echo PLATFORM_BUILD_MODE: build targets
@echo PLATFORM_OPTS: yaml file with all platform opts for installation
@echo $(OPERATOR_IMAGE):$(IMAGE_TAG)
@mkdir -p $(PLATFORM_PACKAGE_DIR)/dependencies/images
@docker save $(OPERATOR_IMAGE):$(IMAGE_TAG) | pigz > $(PLATFORM_PACKAGE_DIR)/dependencies/images/openvino_operator_$(PRODUCT_BUILD).tar.gz && test $${PIPESTATUS[0]} -eq 0
@cp $(PLATFORM_PACKAGE_DIR)/dependencies/images/openvino_operator_$(PRODUCT_BUILD).tar.gz $(PLATFORM_PACKAGE_DIR)/package.tar.gz
platform-install-software: PLATFORM_KUBECONFIG PLATFORM_INSTALLER_DIR PLATFORM_INSTALLATION_MODE $(PLATFORM_INSTALLATION_MODE)
@echo ========== Target installs platform software on the top of the kubernetes ===============
@echo Args:
@echo PLATFORM_KUBECONFIG: Kubernetes config with permissions to install platform
@echo PLATFORM_INSTALLER_DIR: installation files directory
@echo PLATFORM_INSTALLATION_MODE: installation mode
@echo PLATFORM_OPTS: yaml file with all platform opts for installation
@echo Returns: kubernetes installation with PLATFORM_KUBECONFIG configuration file
@echo =========================================================================================
PLATFORM_%:
@ if [ "${PLATFORM_${*}}" = "" ]; then \
echo "Environment variable PLATFORM_$ is not set, please set one before run"; \
exit 1; \
fi
style:
docker run --rm -v $$(pwd):/app -w /app -e https_proxy=$(https_proxy) golangci/golangci-lint:v1.56.1 golangci-lint run -E stylecheck --disable-all -v --timeout 4m0s
lint:
docker run --rm -v $$(pwd):/app -w /app -e https_proxy=$(https_proxy) golangci/golangci-lint:v1.56.1 golangci-lint run --skip-dirs ../go/pkg/mod -v --timeout 4m0s
VIRTUALENV_EXE := python3 -m venv
VIRTUALENV_DIR := .venv
ACTIVATE="$(VIRTUALENV_DIR)/bin/activate"
venv:$(ACTIVATE)
@echo -n "Using venv "
@. $(ACTIVATE); python3 --version
$(ACTIVATE):
@echo "Updating virtualenv dependencies in: $(VIRTUALENV_DIR)..."
@test -d $(VIRTUALENV_DIR) || $(VIRTUALENV_EXE) $(VIRTUALENV_DIR)
@. $(ACTIVATE); pip install --upgrade pip
@touch $(ACTIVATE)
sdl-check: venv
@echo "Checking license headers in files..."
@. $(ACTIVATE); bash -c "python3 lib_search.py . > missing_headers.txt"
@if ! grep -FRq "All files have headers" missing_headers.txt; then\
echo "Files with missing headers";\
cat missing_headers.txt;\
exit 1;\
fi
@rm missing_headers.txt
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
.PHONY: kustomize
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
ifeq (,$(wildcard $(KUSTOMIZE)))
ifeq (,$(shell which kustomize 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(KUSTOMIZE)) ;\
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | \
tar xzf - -C bin/ ;\
}
else
KUSTOMIZE = $(shell which kustomize)
endif
endif
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help screen.
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)