-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
297 lines (234 loc) · 12.3 KB
/
Makefile
File metadata and controls
297 lines (234 loc) · 12.3 KB
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
290
291
292
293
294
295
296
297
# Copyright (c) NVIDIA CORPORATION. All rights reserved.
#
# 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.
include deps.mk
## Version of the operator
VERSION ?= $(GIT_TAG_LAST)
# Image URL to use all building/pushing image targets
## TODO: update this to the correct image location
IMG ?= nvcr.io/nvidian/swgpu-baseos/skyhook-operator:latest
## default version of kind to use
KIND_VERSION?=1.30.8
PLATFORM := $(shell uname -s 2>/dev/null || echo unknown)
SKYHOOK_NAMESPACE ?= skyhook
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN := $(shell go env GOPATH)/bin
else
GOBIN := $(shell go env GOBIN)
endif
GIT_SHA := $(shell git rev-parse --short HEAD)
GIT_TAG := $(shell git describe --exact-match --tags)
GIT_TAG_LAST := $(shell git describe --tags --abbrev=0)
## GO Flags
GO_LDFLAGS := -ldflags "-X github.com/NVIDIA/skyhook/internal/version.GIT_SHA=$(GIT_SHA) \
-X github.com/NVIDIA/skyhook/internal/version.VERSION=$(VERSION)"
GOFLAGS := -mod=vendor
# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= podman
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: all
all: build
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\n\033[1;31mUsage:\033[0m\n make \033[3;1;36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1;31m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: clean
clean: ## Clears out the local build folder
chmod -R +w $(LOCALBIN)/* ## some binaries permissions are r+x
rm -rf $(LOCALBIN)/*
rm -rf $(REPORTING)/*
define util_confirm_code
$(eval confirm := $(shell read -p "⚠ Are you sure? [y/n] > " -r; echo $$REPLY))
$(if $(filter y Y,$(confirm)),1)
endef
#NOTE: We must call this one to remove \n or any other spaces
util_confirm_ask = $(strip $(util_confirm_code))
.PHONY: confirm
confirm:
$(if $(util_confirm_ask), echo "User said yes", echo "User said no"; exit 1)
##@ Development
.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object paths="./..."
$(MAKE) fmt ## fix up license headers
.PHONY: generate-mocks
generate-mocks: mockery ## Generate code for interface mocking
$(MOCKERY)
$(MAKE) fmt ## fix up license headers
license-report: go-licenses ## Run run license report
$(LOCALBIN)/go-licenses report ./... > $(REPORTING)/licenses.csv
@echo "report at $(REPORTING)/licenses.csv"
.PHONY: license-check
license-check: go-licenses ## Run go-licenses check against code.
$(LOCALBIN)/go-licenses check ./... --allowed_licenses=MIT,BSD-2-Clause,BSD-3-Clause,Apache-2.0,ISC,Zlib
.PHONY: license-fmt
license-fmt: go-license ## Run add license header to code.
$(LOCALBIN)/go-license --config license.yml $$(find "$$PWD" -name *.go | sed "s;$$PWD/;;g")
.PHONY: fmt
fmt: license-fmt ## Run go fmt against code.
go fmt $(GOFLAGS) ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet $(GOFLAGS) ./...
REPORTING ?= $(shell pwd)/reporting
reporting:
mkdir -p $(REPORTING)
.PHONY: test
test:: reporting manifests generate fmt vet lint helm-tests e2e-tests unit-tests ## Run all tests.
ifndef GITLAB_CI
## we double define test so we can do thing different if in ci vs local
test:: merge-coverage
echo "Total Code Coverage: $(shell go tool cover -func $(REPORTING)/cover.out | grep total | awk '{print $$NF}')"
go tool cover -html=$(REPORTING)/cover.out
else
test:: merge-coverage gocover-cobertura
echo "Total Code Coverage: $(shell go tool cover -func $(REPORTING)/cover.out | grep total | awk '{print $$NF}')"
$(GOCOVER_COBERTURA) < $(REPORTING)/cover.out > $(REPORTING)/coverage.xml
endif
.PHONY: watch-tests
watch-tests: ## watch unit tests and auto run on changes.
$(GINKGO) watch $(GOFLAGS) -p -vv ./...
.PHONY: unit-test
unit-tests: envtest ginkgo kill ## Run unit tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) $(GOFLAGS) --coverprofile=$(REPORTING)/unit.coverprofile -vv --trace --junit-report=$(REPORTING)/unit.xml --keep-going --timeout=90s ./...
## exec time is for things like scripts and commands, if we new more of these, might want to switch to a config file
## https://kyverno.github.io/chainsaw/latest/reference/commands/chainsaw_test/
## https://kyverno.github.io/chainsaw/latest/configuration/file/
CHAINSAW_ARGS:=--exec-timeout 30s
e2e-tests: chainsaw run ## Run end to end tests.
## requires a cluster to be running with access
## locally use kind to create clusters
## in ci, the plan current is to have a real cluster, and create a node pool for testing
$(CHAINSAW) test --test-dir e2e/chainsaw/skyhook $(CHAINSAW_ARGS)
$(MAKE) kill
go tool covdata textfmt -i=$(REPORTING)/int -o reporting/int.coverprofile
helm-tests: helm chainsaw
## Here we need to run the operator so that the old CRD can deleted along with
## any leftover SCRs. Without this the SCRs may have finalizers which rely on
## the operator and will cause the deletion and tests to hang.
$(MAKE) run
$(MAKE) uninstall ignore-not-found=true
$(MAKE) kill
$(CHAINSAW) test --test-dir e2e/chainsaw/helm $(CHAINSAW_ARGS)
create-kind-cluster: ## deletes and creates a new kind cluster. versions is set via KIND_VERSION
kind delete cluster && kind create cluster --image=kindest/node:v$(KIND_VERSION) --config config/local-dev/kind-config.yaml
$(KUBECTL) label node/kind-worker skyhook.nvidia.com/test-node=skyhooke2e
## sets you local podman creds into a secret in kind in the skyhook namespace
$(KUBECTL) create namespace $(SKYHOOK_NAMESPACE) --dry-run=client -o yaml | kubectl apply -f -
$(KUBECTL) create secret generic node-init-secret --type=kubernetes.io/dockerconfigjson -n $(SKYHOOK_NAMESPACE) \
--from-file=.dockerconfigjson=${HOME}/.config/containers/auth.json
podman-create-machine: ## creates a podman machine
podman machine stop podman-machine-default || true
podman machine rm podman-machine-default || true
podman machine init --cpus=6 -m=12288 --disk-size=300 podman-machine-default
podman machine start podman-machine-default
podman-restart:
podman machine stop && podman machine start
sedrp := sed -r -i
ifeq ($(PLATFORM),Darwin)
sedrp = sed -r -i ''
endif
.PHONY: merage-coverage
merge-coverage:
## merge coverage file into one so we can run totals and html reporting
cat $(REPORTING)/*.coverprofile > reporting/temp-cover.out
echo "mode: set" > $(REPORTING)/cover.out
## skip first line with +2
tail -n +2 $(REPORTING)/temp-cover.out | sed '/mode: set/d' >> $(REPORTING)/cover.out
$(sedrp) 's/^\/.*(\/skyhook-operator.*)/gitlab-master\.nvidia\.com\/dgx\/infra\1/g' $(REPORTING)/cover.out
.PHONY: lint
lint: golangci-lint license-check ## Run golangci-lint linter & yamllint
$(GOLANGCI_LINT) run
.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix
create-dashboard: ## create kubernetes dashboard for local testing
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace dashboard
$(KUBECTL) apply -f config/local-dev/dashboard.yaml
access-dashboard: ## portforwards and gets token for dashboard for local testing
token=$$($(KUBECTL) get secret admin-user -n dashboard -o jsonpath={".data.token"} | base64 -d); echo ""; echo "$$token"
$(KUBECTL) -n dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443
remove-dashboard:
$(KUBECTL) delete namespace/dashboard
##@ Build
.PHONY: build
build: manifests generate fmt vet lint ## Build manager binary.
go build $(GOFLAGS) $(GO_LDFLAGS) -o bin/manager cmd/main.go
.PHONY: run
ENABLE_WEBHOOKS?=false
BACKGROUND?=true
AGENT_IMAGE?=nvcr.io/nvidian/swgpu-baseos/agentless-test:6.2.0
LOG_LEVEL?=info
run: manifests generate fmt vet lint reporting install kill ## Run a controller from your host.
mkdir -p $(REPORTING)/int
rm -rf $(REPORTING)/int/*
go build $(GOFLAGS) -cover $(GO_LDFLAGS) -o $(LOCALBIN)/manager cmd/main.go
ifeq ($(BACKGROUND),true)
LOG_LEVEL=$(LOG_LEVEL) AGENT_IMAGE=$(AGENT_IMAGE) ENABLE_WEBHOOKS=$(ENABLE_WEBHOOKS) GOCOVERDIR=$(REPORTING)/int nohup $(LOCALBIN)/manager > $(REPORTING)/int/std.out & echo "$$!" > $(REPORTING)/int/run.PID
else
LOG_LEVEL=$(LOG_LEVEL) AGENT_IMAGE=$(AGENT_IMAGE) ENABLE_WEBHOOKS=$(ENABLE_WEBHOOKS) GOCOVERDIR=$(REPORTING)/int $(LOCALBIN)/manager > $(REPORTING)/int/std.out
endif
kill:
! test -s $(REPORTING)/int/run.PID || kill -15 $(shell cat $(REPORTING)/int/run.PID) || rm $(REPORTING)/int/run.PID
# some times it gets strange, so try to clean that up with a backup pgrep kill
-pgrep ^manager$$ ; [ "$$?" -ne "0" ] || (echo "kill failed, manager still running"; kill -15 $(shell pgrep ^manager$$))
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
$(CONTAINER_TOOL) build -f containers/operator.Dockerfile -t ${IMG} .
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
$(KUBECTL) create namespace $(SKYHOOK_NAMESPACE) --dry-run=client -o yaml | kubectl apply -f -
.PHONY: uninstall
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.
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
generate-helm: confirm manifests kustomize helm helmify ## Generates new helm chart using helmify. Be-careful, this can break things, it overwrites files, make sure to look at you git diff.
$(KUSTOMIZE) build config/default | $(HELMIFY) -original-name
.PHONY: undeploy
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.
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
##@ Build Dependencies
## Tool Binaries
KUBECTL ?= kubectl