Skip to content

Commit

Permalink
update sample Makefile with proposed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantking committed Jan 13, 2022
1 parent ec010fd commit f5bee59
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion hack/generate/olm_bindata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function generate_bindata() {
delete_old_olmbindata

# get go-bindata tool
go get -u github.com/go-bindata/go-bindata/...
go install github.com/go-bindata/go-bindata@latest

mkdir olm-manifests
for v in $@; do
Expand Down
38 changes: 26 additions & 12 deletions testdata/go/v3/memcached-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,31 +136,45 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
##@ Build Dependencies

LOCAL_BIN = $(shell pwd)/bin
$(LOCAL_BIN):
mkdir -p $(LOCAL_BIN)

CONTROLLER_GEN = $(LOCAL_BIN)/bin/controller-gen
CONTROLLER_GEN_VERSION = v0.7.0
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)
controller-gen: $(CONTROLLER_GEN)
$(CONTROLLER_GEN): $(LOCAL_BIN) ## Download controller-gen locally if necessary.
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION))

KUSTOMIZE = $(shell pwd)/bin/kustomize
KUSTOMIZE = $(LOCAL_BIN)/kustomize
KUSTOMIZE_VERSION = v3.8.7
KUSTOMIZE_BUNDLE = kustomize_$(KUSTOMIZE_VERSION)_$(shell go env GOOS)_$(shell go env GOARCH).tar.gz
.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
kustomize: $(KUSTOMIZE)
$(KUSTOMIZE):$(LOCAL_BIN) ## Download kustomize locally if necessary.
curl -sLO https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F$(KUSTOMIZE_VERSION)/$(KUSTOMIZE_BUNDLE)
tar xf $(KUSTOMIZE_BUNDLE) --directory $(LOCAL_BIN)

ENVTEST = $(shell pwd)/bin/setup-envtest
ENVTEST = $(LOCAL_BIN)/setup-envtest
ENVTEST_VERSION = latest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
envtest: $(ENVTEST)
$(ENVTEST): $(LOCAL_BIN) ## Download envtest-setup locally if necessary.
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION))

# go-get-tool will 'go get' any package $2 and install it to $1.
# go-install-tool will 'go install' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
GOBIN=$(LOCAL_BIN) go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ With:
logf.SetLogger(logger)
```

**NOTE**: For this example, you will need to add the module `"github.com/sykesm/zap-logfmt"` to your project. Run `go get -u github.com/sykesm/zap-logfmt`.
**NOTE**: For this example, you will need to add the module `"github.com/sykesm/zap-logfmt"` to your project. Run `go install github.com/sykesm/zap-logfmt@latest`.

#### Output using custom zap logger

Expand Down

0 comments on commit f5bee59

Please sign in to comment.