forked from samba-in-kubernetes/samba-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
205 lines (171 loc) · 5.86 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
# Current Operator version
VERSION ?= 0.0.1
# Default bundle image tag
BUNDLE_IMG ?= samba-operator-bundle:$(VERSION)
# Options for 'bundle-build'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
COMMIT_ID = $(shell git describe --abbrev=40 --always --dirty=+ 2>/dev/null)
GIT_VERSION = $(shell git describe --match='v[0-9]*.[0-9].[0-9]' 2>/dev/null || echo "(unset)")
# Image URL to use all building/pushing image targets
TAG ?= latest
IMG ?= quay.io/samba.org/samba-operator:$(TAG)
# Produce CRDs that work on Kubernetes 1.16 or later
CRD_OPTIONS ?= "crd:trivialVersions=true,crdVersions=v1"
CHECK_GOFMT_FLAGS ?= -e -s -l
# 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
CONTAINER_BUILD_OPTS ?=
CONTAINER_CMD ?=
ifeq ($(CONTAINER_CMD),)
CONTAINER_CMD:=$(shell docker version >/dev/null 2>&1 && echo docker)
endif
ifeq ($(CONTAINER_CMD),)
CONTAINER_CMD:=$(shell podman version >/dev/null 2>&1 && echo podman)
endif
all: manager build-integration-tests
# Run tests
test: generate manifests vet
hack/test.sh
# Build manager binary
manager: generate build vet
build:
go build -o bin/manager -ldflags "-X main.Version=$(GIT_VERSION) -X main.CommitID=$(COMMIT_ID)" main.go
.PHONY: build
build-integration-tests:
go test -c -o bin/integration-tests -tags integration ./tests/integration
.PHONY: build-integration-tests
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate vet manifests
go run ./main.go
# Install CRDs into a cluster
install: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize set-image
$(KUSTOMIZE) build config/default | kubectl apply -f -
delete-deploy: manifests kustomize
$(KUSTOMIZE) build config/default | kubectl delete -f -
set-image: kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
.PHONY: set-image
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Run go fmt to reformat code
reformat:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the container image
docker-build: image-build
image-build:
$(CONTAINER_CMD) build \
--build-arg=GIT_VERSION="$(GIT_VERSION)" \
--build-arg=COMMIT_ID="$(COMMIT_ID)" \
$(CONTAINER_BUILD_OPTS) $(CONTAINER_BUILD_OPTS) . -t ${IMG}
.PHONY: image-build-buildah
image-build-buildah: build
cn=$$(buildah from registry.access.redhat.com/ubi8/ubi-minimal:latest) && \
buildah copy $$cn bin/manager /manager && \
buildah config --cmd='[]' $$cn && \
buildah config --entrypoint='["/manager"]' $$cn && \
buildah commit $$cn ${IMG}
# Push the container image
docker-push: container-push
container-push:
$(CONTAINER_CMD) push ${IMG}
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell command -v controller-gen ;))
@echo "controller-gen not found in PATH, checking in GOBIN ($(GOBIN))..."
ifeq (, $(shell command -v $(GOBIN)/controller-gen ;))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
endif
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell command -v controller-gen ;)
endif
kustomize:
ifeq (, $(shell command -v kustomize ;))
@echo "kustomize not found in PATH, checking in GOBIN ($(GOBIN))..."
ifeq (, $(shell command -v $(GOBIN)/kustomize ;))
@{ \
set -e ;\
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
endif
KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell command -v kustomize ;)
endif
# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle
# Build the bundle image.
.PHONY: bundle-build
bundle-build:
$(CONTAINER_CMD) build $(CONTAINER_BUILD_OPTS) -f bundle.Dockerfile -t $(BUNDLE_IMG) .
.PHONY: check check-revive check-format
check: check-revive check-format vet
check-format:
! gofmt $(CHECK_GOFMT_FLAGS) . | sed 's,^,formatting error: ,' | grep 'go$$'
check-revive: revive
# revive's checks are configured using .revive.toml
# See: https://github.com/mgechev/revive
$(REVIVE) -config .revive.toml $$(go list ./... | grep -v /vendor/)
.PHONY: revive
revive:
ifeq (, $(shell command -v revive ;))
@echo "revive not found in PATH, checking in GOBIN ($(GOBIN))..."
ifeq (, $(shell command -v $(GOBIN)/revive ;))
@{ \
set -e ;\
echo "revive not found in GOBIN, getting revive..." ;\
REVIVE_TMP_DIR=$$(mktemp -d) ;\
cd $$REVIVE_TMP_DIR ;\
go mod init tmp ;\
go get github.com/mgechev/revive ;\
rm -rf $$REVIVE_TMP_DIR ;\
}
@echo "revive installed in GOBIN"
else
@echo "revive found in GOBIN"
endif
REVIVE=$(shell command -v $(GOBIN)/revive ;)
else
@echo "revive found in PATH"
REVIVE=$(shell command -v revive ;)
endif