-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMakefile
More file actions
114 lines (93 loc) · 4.16 KB
/
Makefile
File metadata and controls
114 lines (93 loc) · 4.16 KB
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
GO111MODULE:=on
export DOCKER_BUILDKIT=1
GO_PACKAGES=$(shell go list ./... | grep -v /tests/)
GO_FILES=$(shell find . -type f -name '*.go' -not -path "./.git/*" -not -path "./api/v1/zz_generated*.go")
GOLANGCI_LINT_EXISTS:=$(shell golangci-lint --version 2>/dev/null)
GOSEC_EXISTS:=$(shell gosec --version 2>/dev/null)
GIT_COMMIT_SHA:=$(shell git rev-parse HEAD 2>/dev/null)
SHFILES=$(shell find . -type f -name '*fvt*.sh')
SHELLCHECK_EXISTS:=$(shell shellcheck --version 2>/dev/null)
YAMLLINT_EXISTS:=$(shell yamllint --version 2>/dev/null)
INSTALL_LOCATION?=$(GOPATH)/bin
MAKEFILE_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
include Makefile.env
include Makefile.sdk
deps:
make _deps-$(shell uname | tr '[:upper:]' '[:lower:]')
_deps-darwin:
$(error Operating system not supported)
_deps-linux:
@echo "Ensuring install directory exists: $(INSTALL_LOCATION)"
mkdir -p $(INSTALL_LOCATION)
@echo "Installing build dependencies..."
curl -sL https://github.com/operator-framework/operator-sdk/releases/download/v${OP_SDK_RELEASE_VERSION}/operator-sdk_linux_amd64 > ${INSTALL_LOCATION}/operator-sdk
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${INSTALL_LOCATION} v${GOLANGCI_LINT_VERSION}
curl -sL https://github.com/kubernetes-sigs/kind/releases/download/v${KIND_VERSION}/kind-linux-amd64 > ${INSTALL_LOCATION}/kind
curl -sL https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl > ${INSTALL_LOCATION}/kubectl
chmod +x ${INSTALL_LOCATION}/operator-sdk ${INSTALL_LOCATION}/kind ${INSTALL_LOCATION}/kubectl
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b ${INSTALL_LOCATION} v${GOSEC_VERSION}
_calculate-build-number:
$(eval export CONTAINER_VERSION?=$(GIT_COMMIT_SHA)-$(shell date "+%s"))
lint:
ifdef GOLANGCI_LINT_EXISTS
golangci-lint run --verbose --timeout 10m
else
@echo "golangci-lint is not installed"
endif
lint-sh:
ifdef SHELLCHECK_EXISTS
shellcheck ${SHFILES}
else
@echo "shellcheck is not installed"
endif
lint-yaml:
ifdef YAMLLINT_EXISTS
ifeq ($(TRAVIS),true)
yamllint .travis.yml ./config/
endif
else
@echo "yamllint is not installed"
endif
formatcheck:
([ -z "$(shell gofmt -d $(GO_FILES))" ]) || (echo "Source is unformatted, please execute make format"; exit 1)
format:
@gofmt -w ${GO_FILES}
coverage:
go tool cover -html=cover.out -o=cover.html
sec:
ifdef GOSEC_EXISTS
gosec -quiet ${GO_FILES}
else
@echo "gosec is not installed"
endif
fvt: _calculate-build-number validate-code build-operator
docker tag $(REGISTRY_REPO)-amd64 $(REGISTRY_REPO)-amd64:$(CONTAINER_VERSION)
$(eval export REGISTRY_REPO=$(REGISTRY_REPO)-amd64)
@scripts/run-fvt.sh
validate-code: lint lint-sh lint-yaml formatcheck vet sec test
update-operator-resource:
make manifests
build-operator:
make docker-build IMG=$(REGISTRY_REPO)
dev-publish-image: _calculate-build-number build-operator
docker tag $(REGISTRY_REPO)-amd64 $(REGISTRY_REPO)-amd64:$(CONTAINER_VERSION)-amd64
docker push $(REGISTRY_REPO)-amd64:$(CONTAINER_VERSION)-amd64
@echo "\n image: $(REGISTRY_REPO)-amd64:$(CONTAINER_VERSION)-amd64"
dev-run-operator-local: dev-apply-common-resources
# pick the first node to test run
$(eval export NODE_HOSTNAME=$(shell sh -c "kubectl get nodes -o jsonpath='{ $$.items[0].status.addresses[?(@.type==\"Hostname\")].address }'"))
make run
dev-run-operator-remote: dev-publish-image dev-apply-common-resources
cat config/manager/manager.yaml | sed 's|REPLACE_IMAGE|$(REGISTRY_REPO)-amd64:$(CONTAINER_VERSION)-amd64|g' > config/manager/manager.dev.yaml
kubectl create -f config/manager/manager.dev.yaml || :
dev-apply-common-resources:
kubectl create -f config/crd/bases/static-route.ibm.com_staticroutes.yaml || :
kubectl create -f config/rbac/service_account.yaml || :
kubectl create -f config/rbac/role.yaml || :
kubectl create -f config/rbac/role_binding.yaml || :
dev-cleanup-operator:
kubectl delete -f config/crd/bases/static-route.ibm.com_staticroutes.yaml || :
kubectl delete -f config/manager/manager.dev.yaml || :
kubectl delete -f config/rbac/role.yaml || :
kubectl delete -f config/rbac/role_binding.yaml || :
kubectl delete -f config/rbac/service_account.yaml || :