Skip to content

Commit ccc7b1d

Browse files
makefile fixes (#162)
* makefile fixes Signed-off-by: raffaelespazzoli <raffaele.spazzoli@gmail.com> * fixed makefile Signed-off-by: raffaelespazzoli <raffaele.spazzoli@gmail.com> --------- Signed-off-by: raffaelespazzoli <raffaele.spazzoli@gmail.com>
1 parent b1b670b commit ccc7b1d

File tree

1 file changed

+55
-35
lines changed

1 file changed

+55
-35
lines changed

Makefile

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
4646
# example.com/memcached-operator-bundle:$VERSION and example.com/memcached-operator-catalog:$VERSION.
4747
IMAGE_TAG_BASE ?= quay.io/redhat-cop/$(OPERATOR_NAME)
4848

49+
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
50+
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
51+
52+
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
53+
# You can enable this value if you would like to use SHA Based Digests
54+
# To enable set flag to true
55+
USE_IMAGE_DIGESTS ?= false
56+
ifeq ($(USE_IMAGE_DIGESTS), true)
57+
BUNDLE_GEN_FLAGS += --use-image-digests
58+
endif
59+
4960
# BUNDLE_IMG defines the image:tag used for the bundle.
5061
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
5162
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
@@ -57,6 +68,11 @@ CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
5768
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5869
ENVTEST_K8S_VERSION = 1.21
5970

71+
## Tool Binaries
72+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
73+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
74+
ENVTEST ?= $(LOCALBIN)/setup-envtest
75+
6076
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6177
ifeq (,$(shell go env GOBIN))
6278
GOBIN=$(shell go env GOPATH)/bin
@@ -70,6 +86,7 @@ endif
7086
SHELL = /usr/bin/env bash -o pipefail
7187
.SHELLFLAGS = -ec
7288

89+
.PHONY: all
7390
all: build
7491

7592
##@ General
@@ -88,6 +105,7 @@ all: build
88105
.PHONY: help
89106
help: ## Display this help.
90107
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
108+
91109
##@ Development
92110

93111
.PHONY: manifests
@@ -119,44 +137,49 @@ kind-setup: kind kubectl helm
119137

120138
##@ Build
121139

122-
build: generate fmt vet ## Build manager binary.
140+
.PHONY: build
141+
build: manifests generate fmt vet ## Build manager binary.
123142
go build -o bin/manager main.go
124143

144+
.PHONY: run
125145
run: manifests generate fmt vet ## Run a controller from your host.
126146
go run ./main.go
127147

148+
.PHONY: docker-build
128149
docker-build: test ## Build docker image with the manager.
129150
docker build -t ${IMG} .
130151

152+
.PHONY: docker-push
131153
docker-push: ## Push docker image with the manager.
132154
docker push ${IMG}
133155

134156
##@ Deployment
135157

158+
ifndef ignore-not-found
159+
ignore-not-found = false
160+
endif
161+
162+
.PHONY: install
136163
install: manifests kustomize kubectl ## Install CRDs into the K8s cluster specified in ~/.kube/config.
137164
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
138165

166+
.PHONY: uninstall
139167
uninstall: manifests kustomize kubectl ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
140-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete -f -
168+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
141169

170+
.PHONY: deploy
142171
deploy: manifests kustomize kubectl ## Deploy controller to the K8s cluster specified in ~/.kube/config.
143172
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
144173
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
145174

175+
.PHONY: undeploy
146176
undeploy: kustomize kubectl ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
147-
$(KUSTOMIZE) build config/default | $(KUBECTL) delete -f -
177+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
148178

149179
LOCALBIN ?= $(shell pwd)/bin
150180
$(LOCALBIN):
151181
mkdir -p $(LOCALBIN)
152182

153-
## Tool Binaries
154-
KUSTOMIZE ?= $(LOCALBIN)/kustomize
155-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
156-
ENVTEST ?= $(LOCALBIN)/setup-envtest
157-
158-
159-
160183
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
161184
.PHONY: kustomize
162185
KUSTOMIZE ?= $(LOCALBIN)/kustomize
@@ -247,7 +270,8 @@ catalog-push: ## Push a catalog image.
247270
$(MAKE) docker-push IMG=$(CATALOG_IMG)
248271

249272
# Generate helm chart
250-
helmchart: kustomize helm
273+
.PHONY: helmchart
274+
helmchart: helmchart-clean kustomize helm
251275
mkdir -p ./charts/${OPERATOR_NAME}/templates
252276
mkdir -p ./charts/${OPERATOR_NAME}/crds
253277
repo=${OPERATOR_NAME} envsubst < ./config/local-development/tilt/env-replace-image.yaml > ./config/local-development/tilt/replace-image.yaml
@@ -262,11 +286,13 @@ helmchart: kustomize helm
262286
echo {{ end }} >> ./charts/${OPERATOR_NAME}/templates/monitoring.coreos.com_v1_servicemonitor_${OPERATOR_NAME}-controller-manager-metrics-monitor.yaml
263287
$(HELM) lint ./charts/${OPERATOR_NAME}
264288

289+
.PHONY: helmchart-repo
265290
helmchart-repo: helmchart
266291
mkdir -p ${HELM_REPO_DEST}/${OPERATOR_NAME}
267292
$(HELM) package -d ${HELM_REPO_DEST}/${OPERATOR_NAME} ./charts/${OPERATOR_NAME}
268293
$(HELM) repo index --url ${CHART_REPO_URL} ${HELM_REPO_DEST}
269294

295+
.PHONY: helmchart-repo-push
270296
helmchart-repo-push: helmchart-repo
271297
git -C ${HELM_REPO_DEST} add .
272298
git -C ${HELM_REPO_DEST} status
@@ -296,46 +322,40 @@ helmchart-test: kind-setup helmchart
296322
$(KUBECTL) wait --namespace default --for=condition=ready pod prometheus-kube-prometheus-stack-prometheus-0 --timeout=180s
297323
$(KUBECTL) exec prometheus-kube-prometheus-stack-prometheus-0 -n default -c test-metrics -- /bin/sh -c "echo 'Example metrics...' && cat /tmp/ready"
298324

325+
.PHONY: helmchart-clean
326+
helmchart-clean:
327+
rm -rf ./charts
328+
299329
.PHONY: kind
300-
KIND = ./bin/kind
301-
kind: ## Download kind locally if necessary.
302-
ifeq (,$(wildcard $(KIND)))
303-
ifeq (,$(shell which kind 2>/dev/null))
304-
$(call go-get-tool,$(KIND),sigs.k8s.io/kind@${KIND_VERSION})
305-
else
306-
KIND = $(shell which kind)
307-
endif
308-
endif
330+
KIND ?= $(LOCALBIN)/kind
331+
kind: $(KIND) ## Download kind locally if necessary.
332+
$(KIND): $(LOCALBIN)
333+
test -s $(LOCALBIN)/kind || echo "Downloading kind to ${KIND}..." && GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@${KIND_VERSION}
309334

310335
.PHONY: kubectl
311-
KUBECTL = ./bin/kubectl
336+
KUBECTL ?= $(LOCALBIN)/kubectl
312337
kubectl: ## Download kubectl locally if necessary.
313338
ifeq (,$(wildcard $(KUBECTL)))
314-
ifeq (,$(shell which kubectl 2>/dev/null))
315-
echo "Downloading ${KUBECTL} for managing k8s resources."
339+
@{ \
340+
set -e ;\
341+
echo "Downloading kubectl to ${KUBECTL}..." ;\
316342
OS=$(shell go env GOOS) ;\
317343
ARCH=$(shell go env GOARCH) ;\
318344
curl --create-dirs -sSLo ${KUBECTL} https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/$${OS}/$${ARCH}/kubectl ;\
319-
chmod +x ${KUBECTL}
320-
else
321-
KUBECTL = $(shell which kubectl)
322-
endif
345+
chmod +x ${KUBECTL} ;\
346+
}
323347
endif
324348

325349
.PHONY: helm
326-
HELM = ./bin/helm
350+
HELM ?= $(LOCALBIN)/helm
327351
helm: ## Download helm locally if necessary.
328352
ifeq (,$(wildcard $(HELM)))
329-
ifeq (,$(shell which helm 2>/dev/null))
330-
echo "Downloading ${HELM}."
353+
echo "Downloading helm to ${HELM}..."
331354
OS=$(shell go env GOOS) ;\
332355
ARCH=$(shell go env GOARCH) ;\
333356
curl --create-dirs -sSLo ${HELM}.tar.gz https://get.helm.sh/helm-${HELM_VERSION}-$${OS}-$${ARCH}.tar.gz ;\
334-
tar -xf ${HELM}.tar.gz -C ./bin/ ;\
357+
tar -xf ${HELM}.tar.gz -C $(LOCALBIN)/ ;\
335358
mv ./bin/$${OS}-$${ARCH}/helm ${HELM}
336-
else
337-
HELM = $(shell which helm)
338-
endif
339359
endif
340360

341361
.PHONY: operator-sdk
@@ -354,4 +374,4 @@ endif
354374

355375
.PHONY: clean
356376
clean:
357-
rm -rf $(LOCALBIN) ./bundle ./bundle-* ./charts
377+
rm -rf $(LOCALBIN) ./bundle ./bundle-* ./charts

0 commit comments

Comments
 (0)