forked from rojkov/intel-device-plugins-for-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
144 lines (110 loc) · 4.61 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
CONTROLLER_GEN ?= controller-gen
GO := go
GOFMT := gofmt
KUBECTL ?= kubectl
KIND ?= kind
PODMAN ?= podman
BUILDTAGS ?= ""
BUILDER ?= "docker"
EXTRA_BUILD_ARGS ?= ""
WEBHOOK_IMAGE_FILE = intel-fpga-admissionwebhook-devel.tgz
pkgs = $(shell $(GO) list ./... | grep -v vendor | grep -v e2e | grep -v envtest)
cmds = $(shell ls cmd)
e2e_tmp_dir := $(shell mktemp -u -t e2e-tests.XXXXXXXXXX)
all: build
format:
@report=`$(GOFMT) -s -d -w $$(find cmd pkg test -name \*.go)` ; if [ -n "$$report" ]; then echo "$$report"; exit 1; fi
vendor:
@$(GO) mod vendor -v
go-mod-tidy:
$(GO) mod download
@report=`$(GO) mod tidy -v 2>&1` ; if [ -n "$$report" ]; then echo "$$report"; exit 1; fi
test:
ifndef WHAT
@$(GO) test -tags $(BUILDTAGS) -race -coverprofile=coverage.txt -covermode=atomic $(pkgs)
else
@cd $(WHAT) && \
$(GO) test -tags $(BUILDTAGS) -v -cover -coverprofile cover.out || rc=1; \
$(GO) tool cover -html=cover.out -o coverage.html; \
rm cover.out; \
echo "Coverage report: file://$$(realpath coverage.html)"; \
exit $$rc
endif
test-with-kind:
@build/docker/build-image.sh intel/intel-fpga-admissionwebhook buildah
@$(PODMAN) tag localhost/intel/intel-fpga-admissionwebhook:devel docker.io/intel/intel-fpga-admissionwebhook:devel
@mkdir -p $(e2e_tmp_dir)
@$(PODMAN) save "docker.io/intel/intel-fpga-admissionwebhook:devel" -o $(e2e_tmp_dir)/$(WEBHOOK_IMAGE_FILE)
@$(KIND) create cluster --name "intel-device-plugins" --kubeconfig $(e2e_tmp_dir)/kubeconfig --image "kindest/node:v1.17.0"
@$(KIND) load image-archive --name "intel-device-plugins" $(e2e_tmp_dir)/$(WEBHOOK_IMAGE_FILE)
@$(GO) test -v ./test/e2e -args -kubeconfig $(e2e_tmp_dir)/kubeconfig -kubectl-path $(KUBECTL) -ginkgo.focus "Webhook" || rc=1; \
$(KIND) delete cluster --name "intel-device-plugins"; \
rm -rf $(e2e_tmp_dir); \
exit $$rc
envtest:
@$(GO) test ./test/envtest
lint:
@golangci-lint run --timeout 15m
checks: lint go-mod-tidy
generate:
$(CONTROLLER_GEN) object:headerFile="build/boilerplate/boilerplate.go.txt" paths="./pkg/apis/..."
$(CONTROLLER_GEN) crd:trivialVersions=true \
paths="./pkg/apis/..." \
output:crd:artifacts:config=deployments/operator/crd/bases
$(CONTROLLER_GEN) crd:trivialVersions=true \
paths="./pkg/apis/fpga.intel.com/..." \
output:crd:artifacts:config=deployments/fpga_admissionwebhook/crd/bases
$(CONTROLLER_GEN) webhook \
paths="./pkg/..." \
output:webhook:artifacts:config=deployments/operator/webhook
$(CONTROLLER_GEN) webhook \
paths="./pkg/fpgacontroller/..." \
output:webhook:artifacts:config=deployments/fpga_admissionwebhook/webhook
$(CONTROLLER_GEN) rbac:roleName=manager-role paths="./pkg/..." output:dir=deployments/operator/rbac
$(CONTROLLER_GEN) rbac:roleName=manager-role paths="./pkg/fpgacontroller/..." output:dir=deployments/fpga_admissionwebhook/rbac
$(cmds):
cd cmd/$@; $(GO) build -tags $(BUILDTAGS)
build: $(cmds)
deploy-operator: operator generate
kubectl apply -k deployments/operator/default
undeploy-operator:
kubectl delete -k deployments/operator/default
run-operator: deploy-operator
./cmd/operator/operator
clean:
@for cmd in $(cmds) ; do pwd=$(shell pwd) ; cd cmd/$$cmd ; $(GO) clean ; cd $$pwd ; done
ORG?=intel
REG?=$(ORG)/
TAG?=devel
export TAG
pre-pull:
ifeq ($(TAG),devel)
@$(BUILDER) pull clearlinux/golang:latest
@$(BUILDER) pull clearlinux:latest
endif
images = $(shell ls build/docker/*.Dockerfile | sed 's/.*\/\(.\+\)\.Dockerfile/\1/')
$(images):
@build/docker/build-image.sh $(REG)$@ $(BUILDER) $(EXTRA_BUILD_ARGS)
images: $(images)
demos = $(shell cd demo/ && ls -d */ | sed 's/\(.\+\)\//\1/g')
$(demos):
@cd demo/ && ./build-image.sh $(REG)$@ $(BUILDER)
demos: $(demos)
image_tags = $(patsubst %,$(REG)%,$(images) $(demos))
$(image_tags):
@docker push $@
push: $(image_tags)
lock-images:
@scripts/update-clear-linux-base.sh clearlinux/golang:latest $(shell ls build/docker/*.Dockerfile)
@scripts/update-clear-linux-base.sh clearlinux:latest $(shell find demo -name Dockerfile)
set-version:
@scripts/set-version.sh $(TAG)
null :=
space := $(null) #
comma := ,
images_json := $(subst $(space),$(comma),[$(addprefix ",$(addsuffix ",$(images) $(demos))]))
check-github-actions:
@python3 -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout)' < .github/workflows/ci.yaml | \
jq -e '$(images_json) - .jobs.image.strategy.matrix.image == []' > /dev/null || \
(echo "Make sure all images are listed in .github/workflows/ci.yaml"; exit 1)
.PHONY: all format test lint build images $(cmds) $(images) lock-images vendor pre-pull set-version check-github-actions run-operator envtest deploy-operator undeploy-operator