-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathMakefile
142 lines (115 loc) · 4.8 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
# To generate a bundle for a specific REGISTRY, REPO, and VERSION, you can:
# make bundle REGISTRY=quay.io/username REPO=lso VERSION=latest
ifeq ($(REGISTRY),)
REGISTRY = quay.io/openshift
endif
ifeq ($(REPO),)
REPO = local-storage-operator
endif
ifeq ($(VERSION),)
VERSION = latest
endif
# Use podman or docker to build containers. Can bet set explicitly.
# make bundle REGISTRY=quay.io/username TOOL_BIN=`which docker`
ifeq ($(TOOL_BIN),)
TOOL_BIN=$(shell which podman 2>/dev/null || which docker 2>/dev/null)
endif
TARGET_GOOS=$(shell go env GOOS)
TARGET_GOARCH=$(shell go env GOARCH)
CURPATH=$(PWD)
TARGET_DIR=$(CURPATH)/_output/bin
OPERATOR_IMAGE= $(REGISTRY)/$(REPO):operator-$(VERSION)
DISKMAKER_IMAGE = $(REGISTRY)/$(REPO):diskmaker-$(VERSION)
MUSTGATHER_IMAGE = $(REGISTRY)/$(REPO):mustgather-$(VERSION)
BUNDLE_IMAGE = $(REGISTRY)/$(REPO):bundle-$(VERSION)
INDEX_IMAGE = $(REGISTRY)/$(REPO):index-$(VERSION)
REV=$(shell git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
# 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
update: rbac manifests generate fmt
.PHONY: update
verify: vet
./hack/verify-rbac.sh
./hack/verify-manifests.sh
./hack/verify-generate.sh
./hack/verify-gofmt.sh
.PHONY: verify
rbac: controller-gen ## Generate ClusterRole and Role objects.
$(CONTROLLER_GEN) rbac:roleName=local-storage-operator webhook paths="./pkg/controllers/..." output:artifacts:config=config/rbac
$(CONTROLLER_GEN) rbac:roleName=local-storage-admin paths="./pkg/diskmaker/controllers/..." output:artifacts:config=config/rbac/diskmaker
.PHONY: rbac
manifests: controller-gen ## Generate CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=local-storage-operator crd paths="./api/..." output:artifacts:config=config/manifests/stable
.PHONY: manifests
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..."
.PHONY: generate
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: fmt
vet: ## Run go vet against code.
go vet ./...
.PHONY: vet
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: ## Run unit tests.
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR)
go test ./pkg/... -coverprofile cover.out
.PHONY: test
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin GOFLAGS="" go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
all build: build-diskmaker build-operator
.PHONY: all build
build-diskmaker:
env GOOS=$(TARGET_GOOS) GOARCH=$(TARGET_GOARCH) go build -mod=vendor -ldflags '-X main.version=$(REV)' -o $(TARGET_DIR)/diskmaker $(CURPATH)/cmd/diskmaker-manager
.PHONY: build-diskmaker
build-operator:
env GOOS=$(TARGET_GOOS) GOARCH=$(TARGET_GOARCH) go build -mod=vendor -ldflags '-X main.version=$(REV)' -o $(TARGET_DIR)/local-storage-operator $(CURPATH)/cmd/local-storage-operator
.PHONY: build-operator
images: diskmaker-container operator-container
.PHONY: images
push: images
$(TOOL_BIN) push $(OPERATOR_IMAGE)
$(TOOL_BIN) push $(DISKMAKER_IMAGE)
.PHONY: push
must-gather:
$(TOOL_BIN) build -t $(MUSTGATHER_IMAGE) -f $(CURPATH)/Dockerfile.mustgather .
.PHONY: must-gather
# this is ugly, but allows us to build dev containers without tripping over yum install
diskmaker-dockerfile-hack:
sed -e 's~registry.ci.openshift.org/ocp/.*:base.*~almalinux:9~' Dockerfile.diskmaker.rhel7 > Dockerfile.diskmaker.hack
.PHONY: diskmaker-dockerfile-hack
diskmaker-container: diskmaker-dockerfile-hack
$(TOOL_BIN) build -t $(DISKMAKER_IMAGE) -f $(CURPATH)/Dockerfile.diskmaker.hack .
.PHONY: diskmaker-container
operator-container:
$(TOOL_BIN) build -t $(OPERATOR_IMAGE) -f $(CURPATH)/Dockerfile.rhel7 .
.PHONY: operator-container
bundle: push
./hack/create-bundle.sh $(OPERATOR_IMAGE) $(DISKMAKER_IMAGE) $(BUNDLE_IMAGE) $(INDEX_IMAGE)
.PHONY: bundle
clean:
rm -f $(TARGET_DIR)/diskmaker $(TARGET_DIR)/local-storage-operator
.PHONY: clean
test_e2e:
./hack/test-e2e.sh
.PHONY: test_e2e