forked from openshift/machine-config-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
148 lines (123 loc) · 5 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
MCO_COMPONENTS = daemon controller server operator
EXTRA_COMPONENTS = apiserver-watcher machine-os-builder
ALL_COMPONENTS = $(patsubst %,machine-config-%,$(MCO_COMPONENTS)) $(EXTRA_COMPONENTS)
PREFIX ?= /usr
GO111MODULE?=on
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
# Copied from coreos-assembler
GOARCH := $(shell uname -m)
ifeq ($(GOARCH),x86_64)
GOARCH = amd64
else ifeq ($(GOARCH),aarch64)
GOARCH = arm64
endif
# vim: noexpandtab ts=8
export GOPATH=$(shell echo $${GOPATH:-$$HOME/go})
export GO111MODULE
export GOPROXY=https://proxy.golang.org
# set golangci lint cache dir to an accessible location
# this is necessary for running golangci-lint in a container
export GOLANGCI_LINT_CACHE=$(shell echo $${GOLANGCI_LINT_CACHE:-$$GOPATH/cache})
GOTAGS = "containers_image_openpgp exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_ostree_stub"
all: binaries
.PHONY: clean test test-unit test-e2e verify update install-tools
# Remove build artifaces
# Example:
# make clean
#
clean:
@rm -rf _output
# Build machine configs. Intended to be called via another target.
# Example:
# make _build-machine-config-operator
_build-%:
WHAT=$* hack/build-go.sh
# Use podman to build the image.
image:
hack/build-image
# Run tests
test: test-unit test-e2e
# Unit tests only (no active cluster required)
test-unit: install-go-junit-report
./hack/test-unit.sh $(@) $(GOTAGS)
# Run the code generation tasks.
# Example:
# make update
update:
hack/update-templates.sh
go-deps:
go mod tidy
go mod vendor
go mod verify
# make scripts executable
chmod +x ./vendor/k8s.io/code-generator/generate-groups.sh
chmod +x ./vendor/k8s.io/code-generator/generate-internal-groups.sh
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.31.1
ENVTEST = go run ${PROJECT_DIR}/vendor/sigs.k8s.io/controller-runtime/tools/setup-envtest
SETUP_ENVTEST := $(shell command -v setup-envtest 2> /dev/null)
install-setup-envtest:
ifdef SETUP_ENVTEST
@echo "Found setup-envtest"
else
@echo "Installing setup-envtest"
go install sigs.k8s.io/controller-runtime/tools/setup-envtest
endif
GO_JUNIT_REPORT := $(shell command -v go-junit-report 2> /dev/null)
install-go-junit-report:
ifdef GO_JUNIT_REPORT
@echo "Found go-junit-report"
go-junit-report --version
else
@echo "Installing go-junit-report"
go install -mod= github.com/jstemmer/go-junit-report@latest
endif
GOLANGCI_LINT := $(shell command -v golangci-lint 2> /dev/null)
install-golangci-lint:
ifdef GOLANGCI_LINT
@echo "Found golangci-lint"
golangci-lint --version
else
@echo "Installing golangci-lint"
GO111MODULE=on go build -o $(GOPATH)/bin/golangci-lint ./vendor/github.com/golangci/golangci-lint/cmd/golangci-lint
endif
install-tools: install-golangci-lint install-go-junit-report install-setup-envtest
# Run verification steps
# Example:
# make verify
verify: install-tools
./hack/golangci-lint.sh $(GOTAGS)
hack/verify-templates.sh
# Template for defining build targets for binaries.
define target_template =
.PHONY: $(1)
$(1): _build-$(1)
endef
# Create a target for each component
$(foreach C, $(EXTRA_COMPONENTS), $(eval $(call target_template,$(C))))
$(foreach C, $(MCO_COMPONENTS), $(eval $(call target_template,$(patsubst %,machine-config-%,$(C)))))
.PHONY: binaries install
# Build all binaries:
# Example:
# make binaries
binaries: $(patsubst %,_build-%,$(ALL_COMPONENTS))
install: binaries
for component in $(ALL_COMPONENTS); do \
install -D -m 0755 _output/linux/$(GOARCH)/$${component} $(DESTDIR)$(PREFIX)/bin/$${component}; \
done
Dockerfile.rhel7: Dockerfile Makefile
(echo '# THIS FILE IS GENERATED FROM '$<' DO NOT EDIT' && \
sed -e s,org/openshift/release,org/ocp/builder, -e s,/openshift/origin-v4.0:base,/ocp/4.0:base, < $<) > $@.tmp && mv $@.tmp $@
# This was copied from https://github.com/openshift/cluster-image-registry-operator
test-e2e: install-go-junit-report
set -o pipefail; go test -tags=$(GOTAGS) -failfast -timeout 170m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e/ ./test/e2e-techpreview-shared/ | ./hack/test-with-junit.sh $(@)
test-e2e-techpreview: install-go-junit-report
set -o pipefail; go test -tags=$(GOTAGS) -failfast -timeout 170m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-techpreview ./test/e2e-techpreview-shared/ | ./hack/test-with-junit.sh $(@)
test-e2e-single-node: install-go-junit-report
set -o pipefail; go test -tags=$(GOTAGS) -failfast -timeout 120m -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-single-node/ | ./hack/test-with-junit.sh $(@)
bootstrap-e2e: install-go-junit-report install-setup-envtest
@echo "Setting up KUBEBUILDER_ASSETS"
@KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --index https://raw.githubusercontent.com/openshift/api/master/envtest-releases.yaml --bin-dir $(PROJECT_DIR)/bin -p path)" && \
echo "KUBEBUILDER_ASSETS=$$KUBEBUILDER_ASSETS" && \
set -o pipefail && \
KUBEBUILDER_ASSETS=$$KUBEBUILDER_ASSETS go test -tags=$(GOTAGS) -v$${WHAT:+ -run="$$WHAT"} ./test/e2e-bootstrap/ | ./hack/test-with-junit.sh $(@)