-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
164 lines (134 loc) · 5.52 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
-include Makefile.prow
SHELL := /bin/bash
export BINDATA_TEMP_DIR := $(shell mktemp -d)
export GIT_COMMIT = $(shell git rev-parse --short HEAD)
export GIT_REMOTE_URL = $(shell git config --get remote.origin.url)
export ARCH ?= $(shell uname -m)
export ARCH_TYPE = $(if $(patsubst x86_64,,$(ARCH)),$(ARCH),amd64)
export BUILD_DATE = $(shell date +%m/%d@%H:%M:%S)
export VCS_REF = $(if $(shell git status --porcelain),$(GIT_COMMIT)-$(BUILD_DATE),$(GIT_COMMIT))
export CGO_ENABLED = 1
export GO111MODULE := on
export GOPACKAGES = $(shell go list ./... | grep -v /vendor | grep -v /internal | grep -v /build | grep -v /test | grep -v /controllers)
export PROJECT_DIR = $(shell 'pwd')
export BUILD_DIR = $(PROJECT_DIR)/build
export COMPONENT_SCRIPTS_PATH = $(BUILD_DIR)
export COMPONENT_NAME ?= $(shell cat ./COMPONENT_NAME 2> /dev/null)
export COMPONENT_VERSION ?= $(shell cat ./COMPONENT_VERSION 2> /dev/null)
## WARNING: OPERATOR-SDK - IMAGE_DESCRIPTION & DOCKER_BUILD_OPTS MUST NOT CONTAIN ANY SPACES
export IMAGE_DESCRIPTION ?= cluster-curator
export DOCKER_FILE = $(BUILD_DIR)/Dockerfile
export DOCKER_REGISTRY ?= quay.io
export DOCKER_NAMESPACE ?= stolostron
export DOCKER_IMAGE ?= $(COMPONENT_NAME)
export DOCKER_IMAGE_COVERAGE_POSTFIX ?= -coverage
export DOCKER_IMAGE_COVERAGE ?= $(DOCKER_IMAGE)$(DOCKER_IMAGE_COVERAGE_POSTFIX)
export DOCKER_BUILD_TAG ?= latest
export DOCKER_TAG ?= $(shell whoami)
#CRD_OPTIONS ?= "crd"
CRD_OPTIONS ?= "crd:trivialVersions=true"
TEST_TMP := /tmp
export KUBEBUILDER_ASSETS ?= $(TEST_TMP)/kubebuilder/bin
K8S_VERSION ?= 1.27.1
GOHOSTOS ?= $(shell go env GOHOSTOS)
GOHOSTARCH ?= $(shell go env GOHOSTARCH)
KB_TOOLS_ARCHIVE_NAME := kubebuilder-tools-$(K8S_VERSION)-$(GOHOSTOS)-$(GOHOSTARCH).tar.gz
KB_TOOLS_ARCHIVE_PATH := $(TEST_TMP)/$(KB_TOOLS_ARCHIVE_NAME)
BEFORE_SCRIPT := $(shell build/before-make.sh)
export DOCKER_BUILD_OPTS = --build-arg VCS_REF=$(VCS_REF) \
--build-arg VCS_URL=$(GIT_REMOTE_URL) \
--build-arg IMAGE_NAME=$(DOCKER_IMAGE) \
--build-arg IMAGE_DESCRIPTION=$(IMAGE_DESCRIPTION) \
--build-arg ARCH_TYPE=$(ARCH_TYPE) \
--build-arg REMOTE_SOURCE=. \
--build-arg REMOTE_SOURCE_DIR=/remote-source \
--build-arg BUILD_HARNESS_EXTENSIONS_PROJECT=${BUILD_HARNESS_EXTENSIONS_PROJECT} \
--build-arg GITHUB_TOKEN=$(GITHUB_TOKEN)
# Only use git commands if it exists
ifdef GIT
GIT_COMMIT = $(shell git rev-parse --short HEAD)
GIT_REMOTE_URL = $(shell git config --get remote.origin.url)
VCS_REF = $(if $(shell git status --porcelain),$(GIT_COMMIT)-$(BUILD_DATE),$(GIT_COMMIT))
endif
.PHONY: deps
## Download all project dependencies
deps: init component/init
.PHONY: check
## Runs a set of required checks
check: copyright-check
.PHONY: controller-gen
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which 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 ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
.PHONY: manifests
## Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths=./... rbac:roleName=manager-role output:crd:artifacts:config=deploy/crd
.PHONY: generate
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: copyright-check
copyright-check:
./build/copyright-check.sh $(TRAVIS_BRANCH)
.PHONY: clean
## Clean build-harness and remove Go generated build and test files
clean::
@rm -rf $(BUILD_DIR)/_output
.PHONY: lint
## Runs linter against go files
lint:
@echo "Running linting tool ..."
@GOGC=25 golangci-lint run --timeout 5m
.PHONY: unit-tests
## Runs go unit tests
unit-tests: ensure-kubebuilder-tools
@build/run-unit-tests.sh
#GOFLAGS="" go test -timeout 2000s -v ./pkg/...
#GOFLAGS="" go test -timeout 60s -v -short ./cmd/...
#GOFLAGS="" go test -timeout 60s -v -short ./controllers/...
.PHONY: push-curator
push-curator: build-curator
docker push ${REPO_URL}/cluster-curator-controller:${VERSION}
docker tag ${REPO_URL}/cluster-curator-controller:${VERSION} ${REPO_URL}/cluster-curator-controller:latest
docker push ${REPO_URL}/cluster-curator-controller:latest
#./deploy/controller/process.sh
.PHONY: compile-curator
compile-curator:
go mod tidy
go mod vendor
GOFLAGS="" go build -o build/_output/curator ./cmd/curator/curator.go
GOFLAGS="" go build -o build/_output/manager ./cmd/manager/main.go
.PHONY: build-curator
build-curator:
docker build -f Dockerfile.prow . -t ${REPO_URL}/cluster-curator-controller:${VERSION}
.PHONY: scale-up-test
scale-up-test:
go test -v -timeout 500s ./cmd/controller/controller_test.go -run TestCreateControllerScale
.PHONY: scale-down-test
scale-down-test:
go test -v -timeout 500s ./cmd/controller/controller_test.go -run TestDeleteManagedClusters
.PHONY: ensure-kubebuilder-tools
# download the kubebuilder-tools to get kube-apiserver binaries from it
ensure-kubebuilder-tools:
ifeq "" "$(wildcard $(KUBEBUILDER_ASSETS))"
$(info Downloading kube-apiserver into '$(KUBEBUILDER_ASSETS)')
mkdir -p '$(KUBEBUILDER_ASSETS)'
curl -s -f -L https://storage.googleapis.com/kubebuilder-tools/$(KB_TOOLS_ARCHIVE_NAME) -o '$(KB_TOOLS_ARCHIVE_PATH)'
tar -C '$(KUBEBUILDER_ASSETS)' --strip-components=2 -zvxf '$(KB_TOOLS_ARCHIVE_PATH)'
else
$(info Using existing kube-apiserver from "$(KUBEBUILDER_ASSETS)")
endif